Skip to content

Commit 790f2f7

Browse files
committed
Rename $api to $client
I think this will make more sense to readers of the code and examples, and will make sense if/when the distribution is renamed.
1 parent 0a024a5 commit 790f2f7

13 files changed

+86
-86
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ version 0.0100
1111
### Common usage ###
1212

1313
use Twitter::API;
14-
my $api = Twitter::API->new_with_traits(
14+
my $client = Twitter::API->new_with_traits(
1515
traits => 'Enchilada',
1616
consumer_key => $YOUR_CONSUMER_KEY,
1717
consumer_secret => $YOUR_CONSUMER_SECRET,
1818
access_token => $YOUR_ACCESS_TOKEN
1919
access_token_secret => $YOUR_ACCESS_TOKEN_SECRET,
2020
);
2121

22-
my $me = $api->verify_credentials;
23-
my $user = $api->show_user('twitter');
22+
my $me = $client->verify_credentials;
23+
my $user = $client->show_user('twitter');
2424

2525
# In list context, both the Twitter API result and a Twitter::API::Context
2626
# object are returned.
27-
my ($r, $context) = $api->home_timeline({ count => 200, trim_user => 1 });
27+
my ($r, $context) = $client->home_timeline({ count => 200, trim_user => 1 });
2828
my $remaning = $context->rate_limit_remaining;
2929
my $until = $context->rate_limit_reset;
3030

3131

3232
### No frills ###
3333

34-
my $api = Twitter::API->new(
34+
my $client = Twitter::API->new(
3535
consumer_key => $YOUR_CONSUMER_KEY,
3636
consumer_secret => $YOUR_CONSUMER_SECRET,
3737
);
3838

39-
my $r = $api->get('account/verify_credentials', {
39+
my $r = $client->get('account/verify_credentials', {
4040
-token => $an_access_token,
4141
-token_secret => $an_access_token_secret,
4242
});
@@ -47,7 +47,7 @@ version 0.0100
4747
use Try::Tiny;
4848

4949
try {
50-
my $r = $api->verify_credentials;
50+
my $r = $client->verify_credentials;
5151
}
5252
catch {
5353
die $_ unless is_twitter_api_error($_);

examples/api.pl

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
use Twitter::API;
88

9-
my $api = Twitter::API->new_with_traits(
9+
my $client = Twitter::API->new_with_traits(
1010
traits => [ qw/ApiMethods/ ],
1111
consumer_key => $ENV{CONSUMER_KEY},
1212
consumer_secret => $ENV{CONSUMER_SECRET},
1313
access_token => $ENV{ACCESS_TOKEN},
1414
access_token_secret => $ENV{ACCESS_TOKEN_SECRET},
1515
);
1616

17-
my $r = $api->verify_credentials;
17+
my $r = $client->verify_credentials;
1818
say "$$r{screen_name} is authorized";
1919

20-
my $mentions = $api->mentions({ user_id => $$r{id} });
20+
my $mentions = $client->mentions({ user_id => $$r{id} });
2121
for my $status ( @$mentions ) {
2222
say $$status{text};
2323
}

examples/app-auth.pl

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
use Twitter::API;
88

9-
my $api = Twitter::API->new_with_traits(
9+
my $client = Twitter::API->new_with_traits(
1010
traits => [ qw/AppAuth ApiMethods/ ],
1111
consumer_key => $ENV{CONSUMER_KEY},
1212
consumer_secret => $ENV{CONSUMER_SECRET},
1313
);
1414

15-
my $token = $api->get_bearer_token;
16-
$api->access_token($$token{access_token});
17-
my $r = $api->user_timeline(twitterapi => { count => 10 });
15+
my $token = $client->get_bearer_token;
16+
$client->access_token($$token{access_token});
17+
my $r = $client->user_timeline(twitterapi => { count => 10 });
1818

1919
for my $status ( @$r ) {
2020
say "$status->{user}{screen_name}: $status->{text}";

examples/decode-html-entities.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
use Twitter::API;
99

10-
my $api = Twitter::API->new_with_traits(
10+
my $client = Twitter::API->new_with_traits(
1111
traits => [ qw/ApiMethods DecodeHtmlEntities/ ],
1212
consumer_key => $ENV{CONSUMER_KEY},
1313
consumer_secret => $ENV{CONSUMER_SECRET},
1414
access_token => $ENV{ACCESS_TOKEN},
1515
access_token_secret => $ENV{ACCESS_TOKEN_SECRET},
1616
);
1717

18-
my $r = $api->show_status(801814387723935744);
18+
my $r = $client->show_status(801814387723935744);
1919

2020
diag $$r{text};
2121
is $$r{text}, q{Test DecodeHtmlEntities trait. < & > ⚠️ 🏉 'single' "double"},

examples/oauth_desktop.pl

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99

1010
# You can replace the consumer key/secret with your own. These credentials are
1111
# for the Net::Twitter example app.
12-
my $api = Twitter::API->new_with_traits(
12+
my $client = Twitter::API->new_with_traits(
1313
traits => 'Enchilada',
1414
consumer_key => 'v8t3JILkStylbgnxGLOQ',
1515
consumer_secret => '5r31rSMc0NPtBpHcK8MvnCLg2oAyFLx5eGOMkXM',
1616
);
1717

1818
# 1. First, we get a request token and secret:
19-
my $request = $api->get_request_token;
19+
my $request = $client->get_request_token;
2020

2121
# 2. We use the request token to generate an authorization URL:
22-
my $auth_url = $api->get_authorization_url({
22+
my $auth_url = $client->get_authorization_url({
2323
oauth_token => $request->{oauth_token},
2424
});
2525

@@ -34,7 +34,7 @@
3434
say '';
3535

3636
# 5. Exchange the request token for an access token
37-
my $access = $api->get_access_token({
37+
my $access = $client->get_access_token({
3838
token => $request->{oauth_token},
3939
token_secret => $request->{oauth_token_secret},
4040
verifier => $pin,
@@ -46,7 +46,7 @@
4646
say 'access_token.......: ', $token;
4747
say 'access_token_secret: ', $secret;
4848

49-
my $status = $api->user_timeline({
49+
my $status = $client->user_timeline({
5050
count => 1,
5151
-token => $token,
5252
-token_secret => $secret,

examples/retry-on-error.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Twitter::API;
88

9-
my $api = Twitter::API->new_with_traits(
9+
my $client = Twitter::API->new_with_traits(
1010
traits => [ qw/ApiMethods RetryOnError/ ],
1111
consumer_key => $ENV{CONSUMER_KEY},
1212
consumer_secret => $ENV{CONSUMER_SECRET},
1313
access_token => $ENV{ACCESS_TOKEN},
1414
access_token_secret => $ENV{ACCESS_TOKEN_SECRET},
1515
);
1616

17-
my $r = $api->verify_credentials;
17+
my $r = $client->verify_credentials;
1818
say "$$r{screen_name} is authorized";
1919

examples/upload.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
use Twitter::API;
66

7-
my $api = Twitter::API->new_with_traits(
7+
my $client = Twitter::API->new_with_traits(
88
traits => [ qw/ApiMethods/ ],
99
consumer_key => $ENV{CONSUMER_KEY},
1010
consumer_secret => $ENV{CONSUMER_SECRET},
1111
access_token => $ENV{ACCESS_TOKEN},
1212
access_token_secret => $ENV{ACCESS_TOKEN_SECRET},
1313
);
1414

15-
my $r = $api->upload_media([ "$ENV{HOME}/Downloads/hello-world.png" ]);
15+
my $r = $client->upload_media([ "$ENV{HOME}/Downloads/hello-world.png" ]);
1616

1717
say "media_id: $$r{media_id}";

lib/Twitter/API.pm

+7-7
Original file line numberDiff line numberDiff line change
@@ -413,32 +413,32 @@ __END__
413413
### Common usage ###
414414
415415
use Twitter::API;
416-
my $api = Twitter::API->new_with_traits(
416+
my $client = Twitter::API->new_with_traits(
417417
traits => 'Enchilada',
418418
consumer_key => $YOUR_CONSUMER_KEY,
419419
consumer_secret => $YOUR_CONSUMER_SECRET,
420420
access_token => $YOUR_ACCESS_TOKEN
421421
access_token_secret => $YOUR_ACCESS_TOKEN_SECRET,
422422
);
423423
424-
my $me = $api->verify_credentials;
425-
my $user = $api->show_user('twitter');
424+
my $me = $client->verify_credentials;
425+
my $user = $client->show_user('twitter');
426426
427427
# In list context, both the Twitter API result and a Twitter::API::Context
428428
# object are returned.
429-
my ($r, $context) = $api->home_timeline({ count => 200, trim_user => 1 });
429+
my ($r, $context) = $client->home_timeline({ count => 200, trim_user => 1 });
430430
my $remaning = $context->rate_limit_remaining;
431431
my $until = $context->rate_limit_reset;
432432
433433
434434
### No frills ###
435435
436-
my $api = Twitter::API->new(
436+
my $client = Twitter::API->new(
437437
consumer_key => $YOUR_CONSUMER_KEY,
438438
consumer_secret => $YOUR_CONSUMER_SECRET,
439439
);
440440
441-
my $r = $api->get('account/verify_credentials', {
441+
my $r = $client->get('account/verify_credentials', {
442442
-token => $an_access_token,
443443
-token_secret => $an_access_token_secret,
444444
});
@@ -449,7 +449,7 @@ __END__
449449
use Try::Tiny;
450450
451451
try {
452-
my $r = $api->verify_credentials;
452+
my $r = $client->verify_credentials;
453453
}
454454
catch {
455455
die $_ unless is_twitter_api_error($_);

lib/Twitter/API/Trait/AppAuth.pm

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ __END__
7373
=head1 SYNOPSIS
7474
7575
use Twitter::API;
76-
my $api = Twitter::API->new_with_traits(
76+
my $client = Twitter::API->new_with_traits(
7777
traits => [ qw/ApiMethods AppAuth/ ]);
7878
79-
my $r = $api->get_bearer_token;
79+
my $r = $client->get_bearer_token;
8080
# return value is hash ref:
8181
# { token_type => 'bearer', access_token => 'AA...' }
8282
my $token = $r->{access_token};
8383
8484
# you can use the token explicitly with the -token argument:
85-
my $user = $api->show_user('twitter_api', { -token => $token });
85+
my $user = $client->show_user('twitter_api', { -token => $token });
8686
8787
# or you can set the access_token attribute to use it implicitly
88-
$api->access_token($token);
89-
my $user = $api->show_user('twitterapi');
88+
$client->access_token($token);
89+
my $user = $client->show_user('twitterapi');
9090
9191
# to revoke a token
92-
$api->invalidate_token($token);
92+
$client->invalidate_token($token);
9393
9494
# if you revoke the token stored in the access_token attribute, clear it:
95-
$api->clear_access_token;
95+
$client->clear_access_token;
9696
9797
=cut

lib/Twitter/API/Trait/Enchilada.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ __END__
2424
2525
use Twitter::API;
2626
27-
my $api = Twitter::API->new_with_traits(
27+
my $client = Twitter::API->new_with_traits(
2828
traits => 'Enchilada',
2929
%other_new_options
3030
);
3131
3232
# which is just shorthand for:
33-
my $api = Twitter::API->new_with_traits(
33+
my $client = Twitter::API->new_with_traits(
3434
traits => [ qw/
3535
ApiMethods
3636
NormalizeBooleans

0 commit comments

Comments
 (0)