[svn-upgrade] new version libnet-twitter-perl (3.17001)
Alessandro Ghedini
13 years ago
0 | 3.17001 2011-03-31 | |
1 | - fixed intermittent bug in AutoCursor (result of Class::MOP anon class caching) | |
2 | ||
3 | 3.17000 2011-03-29 | |
4 | - production release with new AutoCursor trait | |
5 | ||
6 | 3.16000_1 2011-03-27 | |
7 | - Added AutoCursor trait | |
8 | ||
9 | 3.16000 2011-03-26 | |
10 | - Moved trends methods to API::REST; added warning to API::Search::Trends | |
11 | - Added no_retweet_ids method | |
12 | - modify searchapiurl for identica option | |
13 | - added deprecation notice to Net::Identica with Net::Twitter examples | |
14 | - replaced Test::Exception with Test::Fatal in tests | |
15 | ||
0 | 16 | 3.15000 2011-02-25 |
1 | 17 | - added Lists API method members_create_all (alias add_list_members) |
2 | 18 | - added tests dependency: Test::Exception (closes RT #65786) |
25 | 25 | lib/Net/Twitter/Role/API/Search.pm |
26 | 26 | lib/Net/Twitter/Role/API/Search/Trends.pm |
27 | 27 | lib/Net/Twitter/Role/API/TwitterVision.pm |
28 | lib/Net/Twitter/Role/AutoCursor.pm | |
28 | 29 | lib/Net/Twitter/Role/InflateObjects.pm |
29 | 30 | lib/Net/Twitter/Role/Legacy.pm |
30 | 31 | lib/Net/Twitter/Role/OAuth.pm |
61 | 62 | t/99-pod_coverage.t |
62 | 63 | t/99-pod_spelling.t |
63 | 64 | t/99-pod_syntax.t |
65 | t/auto-cursor.t | |
64 | 66 | t/geo.t |
65 | 67 | t/leak.t |
66 | 68 | t/lib/TestUA.pm |
3 | 3 | - 'Marc Mims <marc@questright.com> (@semifor on Twitter)' |
4 | 4 | build_requires: |
5 | 5 | ExtUtils::MakeMaker: 6.42 |
6 | Test::Exception: 0 | |
6 | Test::Fatal: 0 | |
7 | 7 | Test::More: 0.88 |
8 | 8 | configure_requires: |
9 | 9 | ExtUtils::MakeMaker: 6.42 |
29 | 29 | Devel::StackTrace: 1.21 |
30 | 30 | Digest::HMAC_SHA1: 0 |
31 | 31 | Digest::SHA: 0 |
32 | Digest::SHA1: 0 | |
32 | 33 | Encode: 0 |
33 | 34 | File::Spec: 0 |
34 | 35 | HTML::Entities: 0 |
41 | 42 | Moose::Exporter: 0 |
42 | 43 | Moose::Role: 0 |
43 | 44 | MooseX::MultiInitArg: 0 |
45 | MooseX::Role::Parameterized: 0 | |
44 | 46 | Net::Netrc: 0 |
45 | 47 | Net::OAuth: 0.25 |
46 | 48 | Scalar::Util: 0 |
55 | 57 | homepage: http://github.com/semifor/Net-Twitter |
56 | 58 | license: http://dev.perl.org/licenses/ |
57 | 59 | repository: git://github.com/semifor/Net-Twitter.git |
58 | version: 3.15000 | |
60 | version: 3.17001 |
3 | 3 | perl_version_from 'lib/Net/Twitter/Core.pm'; |
4 | 4 | |
5 | 5 | if ( $Module::Install::AUTHOR ) { |
6 | $ENV{NET_TWITTER_NO_TRENDS_WARNING} = 1; | |
6 | 7 | system $^X, "src/build.pl", version, 'src/net-twitter-pod.tt2', 'lib/Net/Twitter.pod'; |
7 | 8 | system 'pod2text lib/Net/Twitter.pod > README'; |
8 | 9 | } |
26 | 27 | requires 'DateTime::Format::Strptime'=> 1.09; |
27 | 28 | requires 'Devel::StackTrace' => 1.21; |
28 | 29 | requires 'Digest::HMAC_SHA1'; |
30 | requires 'Digest::SHA1'; | |
29 | 31 | requires 'Encode'; |
30 | 32 | requires 'HTML::Entities'; |
31 | 33 | requires 'HTTP::Request::Common'; |
35 | 37 | requires 'Moose::Exporter'; |
36 | 38 | requires 'Moose::Role'; |
37 | 39 | requires 'MooseX::MultiInitArg'; |
40 | requires 'MooseX::Role::Parameterized'; | |
38 | 41 | requires 'namespace::autoclean' => 0.09; |
39 | 42 | requires 'Net::OAuth' => 0.25; |
40 | 43 | requires 'Scalar::Util'; |
43 | 46 | requires 'URI::Escape'; |
44 | 47 | requires 'Try::Tiny' => 0.03; |
45 | 48 | |
46 | test_requires 'Test::Exception'; | |
49 | test_requires 'Test::Fatal'; | |
47 | 50 | test_requires 'Test::More' => 0.88; # for done_testing |
48 | 51 | |
49 | 52 | # Don't rely on the JSON::Any requirement to pull in a suitable JSON backend. |
1 | 1 | Net::Twitter - A perl interface to the Twitter API |
2 | 2 | |
3 | 3 | VERSION |
4 | This document describes Net::Twitter version 3.15000 | |
4 | This document describes Net::Twitter version 3.17001 | |
5 | 5 | |
6 | 6 | SYNOPSIS |
7 | 7 | use Net::Twitter; |
104 | 104 | Provides support for the TwitterVision API. See |
105 | 105 | <http://twittervision.com/api.html>. |
106 | 106 | |
107 | WrapError | |
108 | "Net::Twitter" normally throws exceptions on error. When | |
109 | this trait is included, "Net::Twitter" returns undef when a | |
110 | method fails and makes the error available through method | |
111 | "get_error". This is the way all errors were handled in | |
112 | Net::Twitter versions prior to version 3.00. | |
113 | ||
114 | OAuth | |
115 | The "OAuth" trait provides OAuth authentication rather than | |
116 | the default Basic Authentication for Twitter API method | |
117 | calls. See the "Authentication" section and | |
118 | Net::Twitter::Role::OAuth for full documentation. | |
107 | AutoCursor | |
108 | "AutoCursor" is a parameterized trait that provides an | |
109 | automatic loop for cursored calls, returning an ARRAY | |
110 | reference to the combined results. By default, it handles | |
111 | "friends_ids" and "followers_ids". See | |
112 | Net::Twitter::Role::AutoCursor for details. | |
119 | 113 | |
120 | 114 | InflateObjects |
121 | 115 | When this optional trait is included, Net::Twitter inflates |
144 | 138 | # etc. |
145 | 139 | print $r->relative_created_at; |
146 | 140 | |
147 | RateLimit | |
148 | The "RateLimit" trait adds utility methods that return | |
149 | information about the current rate limit status. See | |
150 | Net::Twitter::Role::RateLimit for details. | |
151 | ||
152 | 141 | Legacy |
153 | 142 | This trait provides backwards compatibility to |
154 | 143 | "Net::Twitter" versions prior to 3.00. It implies the traits |
162 | 151 | backwards compatibility for existing applications using |
163 | 152 | "Net::Twitter" versions prior to 3.00. See section "LEGACY |
164 | 153 | COMPATIBILITY" for more details. |
154 | ||
155 | OAuth | |
156 | The "OAuth" trait provides OAuth authentication rather than | |
157 | the default Basic Authentication for Twitter API method | |
158 | calls. See the "Authentication" section and | |
159 | Net::Twitter::Role::OAuth for full documentation. | |
160 | ||
161 | RateLimit | |
162 | The "RateLimit" trait adds utility methods that return | |
163 | information about the current rate limit status. See | |
164 | Net::Twitter::Role::RateLimit for details. | |
165 | ||
166 | RetryOnError | |
167 | The "RetryOnError" trait automatically retries Twitter API | |
168 | calls with temporary failures. See | |
169 | Net::Twitter::Role::RetryOnError for details. | |
170 | ||
171 | WrapError | |
172 | "Net::Twitter" normally throws exceptions on error. When | |
173 | this trait is included, "Net::Twitter" returns undef when a | |
174 | method fails and makes the error available through method | |
175 | "get_error". This is the way all errors were handled in | |
176 | Net::Twitter versions prior to version 3.00. | |
165 | 177 | |
166 | 178 | Some examples of using the "traits" parameter in "new": |
167 | 179 | |
968 | 980 | |
969 | 981 | Returns: DirectMessage |
970 | 982 | |
983 | no_retweet_ids | |
984 | ||
985 | Parameters: *none* | |
986 | Required: *none* | |
987 | ||
988 | Returns an ARRAY ref of user IDs for which the authenticating user | |
989 | does not want to receive retweets. | |
990 | ||
991 | Returns: ArrayRef[UserIDs] | |
992 | ||
971 | 993 | public_timeline |
972 | 994 | |
973 | 995 | Parameters: skip_user, trim_user, include_entities |
1278 | 1300 | |
1279 | 1301 | Returns: Str |
1280 | 1302 | |
1303 | trends | |
1304 | ||
1305 | Parameters: *none* | |
1306 | Required: *none* | |
1307 | ||
1308 | Returns the top ten queries that are currently trending on Twitter. | |
1309 | The response includes the time of the request, the name of each | |
1310 | trending topic, and the url to the Twitter Search results page for | |
1311 | that topic. | |
1312 | ||
1313 | Returns: ArrayRef[Query] | |
1314 | ||
1281 | 1315 | trends_available |
1282 | 1316 | |
1283 | 1317 | Parameters: lat, long |
1298 | 1332 | specific location. |
1299 | 1333 | |
1300 | 1334 | Returns: ArrayRef[Location] |
1335 | ||
1336 | trends_current | |
1337 | trends_current(exclude) | |
1338 | ||
1339 | Parameters: exclude | |
1340 | Required: *none* | |
1341 | ||
1342 | Returns the current top ten trending topics on Twitter. The response | |
1343 | includes the time of the request, the name of each trending topic, | |
1344 | and query used on Twitter Search results page for that topic. | |
1345 | ||
1346 | Returns: HashRef | |
1347 | ||
1348 | trends_daily | |
1349 | ||
1350 | Parameters: date, exclude | |
1351 | Required: *none* | |
1352 | ||
1353 | Returns the top 20 trending topics for each hour in a given day. | |
1354 | ||
1355 | Returns: HashRef | |
1301 | 1356 | |
1302 | 1357 | trends_location |
1303 | 1358 | trends_location(woeid) |
1316 | 1371 | |
1317 | 1372 | Returns: ArrayRef[Trend] |
1318 | 1373 | |
1374 | trends_weekly | |
1375 | ||
1376 | Parameters: date, exclude | |
1377 | Required: *none* | |
1378 | ||
1379 | Returns the top 30 trending topics for each day in a given week. | |
1380 | ||
1381 | Returns: HashRef | |
1382 | ||
1319 | 1383 | update |
1320 | 1384 | update(status) |
1321 | 1385 | |
1520 | 1584 | search |
1521 | 1585 | search(q) |
1522 | 1586 | |
1523 | Parameters: q, callback, lang, rpp, page, since_id, geocode, | |
1524 | show_user | |
1587 | Parameters: q, callback, lang, locale, rpp, page, since_id, until, | |
1588 | geocode, show_user, result_type | |
1525 | 1589 | Required: q |
1526 | 1590 | |
1527 | 1591 | Returns a HASH reference with some meta-data about the query |
1533 | 1597 | for my $status ( @{$r->{results}} ) { |
1534 | 1598 | print "$status->{text}\n"; |
1535 | 1599 | } |
1536 | ||
1537 | Returns: HashRef | |
1538 | ||
1539 | trends | |
1540 | ||
1541 | Parameters: *none* | |
1542 | Required: *none* | |
1543 | ||
1544 | Returns the top ten queries that are currently trending on Twitter. | |
1545 | The response includes the time of the request, the name of each | |
1546 | trending topic, and the url to the Twitter Search results page for | |
1547 | that topic. | |
1548 | ||
1549 | Returns: ArrayRef[Query] | |
1550 | ||
1551 | trends_current | |
1552 | trends_current(exclude) | |
1553 | ||
1554 | Parameters: exclude | |
1555 | Required: *none* | |
1556 | ||
1557 | Returns the current top ten trending topics on Twitter. The response | |
1558 | includes the time of the request, the name of each trending topic, | |
1559 | and query used on Twitter Search results page for that topic. | |
1560 | ||
1561 | Returns: HashRef | |
1562 | ||
1563 | trends_daily | |
1564 | ||
1565 | Parameters: date, exclude | |
1566 | Required: *none* | |
1567 | ||
1568 | Returns the top 20 trending topics for each hour in a given day. | |
1569 | ||
1570 | Returns: HashRef | |
1571 | ||
1572 | trends_weekly | |
1573 | ||
1574 | Parameters: date, exclude | |
1575 | Required: *none* | |
1576 | ||
1577 | Returns the top 30 trending topics for each day in a given week. | |
1578 | 1600 | |
1579 | 1601 | Returns: HashRef |
1580 | 1602 |
1 | 1 | use Moose; |
2 | 2 | |
3 | 3 | # use *all* digits for fBSD ports |
4 | our $VERSION = '3.15000'; | |
4 | our $VERSION = '3.17001'; | |
5 | 5 | $VERSION = eval $VERSION; # numify for warning-free dev releases |
6 | 6 | |
7 | 7 | extends 'Net::Twitter::Core'; |
29 | 29 | $nt = Net::Identica->new(username => $user, password => $passwd); |
30 | 30 | |
31 | 31 | $nt->update('Hello, Identica friends!'); |
32 | ||
33 | =head1 DEPRECATED | |
34 | ||
35 | This module is a backwards compatibility wrapper for applications that used | |
36 | L<Net::Identica> packaged with C<Net::Twitter> versions 2.12 and earlier. | |
37 | Instead, use L<Net::Twitter> with the C<identica> option to gain all of the new | |
38 | features and functionality (OAuth, Search, exceptions on error, etc.). | |
39 | ||
40 | use Net::Twitter; | |
41 | ||
42 | # A simple, backwards compatible replacement for Net::Identica | |
43 | my $identica = Net::Twitter->new( | |
44 | legacy => 1, | |
45 | identica => 1, | |
46 | username => $username, | |
47 | password => $password, | |
48 | ); | |
49 | ||
50 | # A more complex object with OAuth and some optional traits | |
51 | my $identica = Net::Twitter->new( | |
52 | traits => [qw/API::REST API::Search OAuth InflateObjects/], | |
53 | identica => 1, | |
54 | consumer_key => $consumer_key, | |
55 | consumer_secret => $consumer_secret, | |
56 | access_token => $token, | |
57 | access_token_secret => $token_secret, | |
58 | ); | |
32 | 59 | |
33 | 60 | =head1 DESCRIPTION |
34 | 61 |
17 | 17 | use namespace::autoclean; |
18 | 18 | |
19 | 19 | # use *all* digits for fBSD ports |
20 | our $VERSION = '3.15000'; | |
20 | our $VERSION = '3.17001'; | |
21 | 21 | |
22 | 22 | $VERSION = eval $VERSION; # numify for warning-free dev releases |
23 | 23 | |
59 | 59 | return $synthetic_args; |
60 | 60 | } |
61 | 61 | |
62 | around BUILDARGS => sub { | |
63 | my $next = shift; | |
64 | my $class = shift; | |
65 | ||
66 | my %options = @_ == 1 ? %{$_[0]} : @_; | |
67 | ||
68 | if ( delete $options{identica} ) { | |
69 | %options = ( | |
70 | apiurl => 'http://identi.ca/api', | |
71 | searchapiurl => 'http://identi.ca/api', | |
72 | apirealm => 'Laconica API', | |
73 | oauth_urls => { | |
74 | request_token_url => "https://identi.ca/api/oauth/request_token", | |
75 | authentication_url => "https://identi.ca/api/oauth/authenticate", | |
76 | authorization_url => "https://identi.ca/api/oauth/authorize", | |
77 | access_token_url => "https://identi.ca/api/oauth/access_token", | |
78 | xauth_url => "https://identi.ca/api/oauth/access_token", | |
79 | }, | |
80 | %options, | |
81 | ); | |
82 | } | |
83 | ||
84 | return $next->($class, \%options); | |
85 | }; | |
86 | ||
62 | 87 | sub BUILD { |
63 | 88 | my $self = shift; |
64 | 89 |
1 | 1 | use Moose; |
2 | 2 | |
3 | 3 | # use *all* digits for fBSD ports |
4 | our $VERSION = '3.15000'; | |
4 | our $VERSION = '3.17001'; | |
5 | 5 | $VERSION = eval $VERSION; # numify for warning-free dev releases |
6 | 6 | |
7 | 7 | extends 'Net::Twitter::Core'; |
18 | 18 | my $self = shift; |
19 | 19 | |
20 | 20 | $self->{apiurl} =~ s/^http:/https:/ if $self->ssl; |
21 | }; | |
22 | ||
23 | around BUILDARGS => sub { | |
24 | my $next = shift; | |
25 | my $class = shift; | |
26 | ||
27 | my %options = @_ == 1 ? %{$_[0]} : @_; | |
28 | ||
29 | if ( delete $options{identica} ) { | |
30 | %options = ( | |
31 | apiurl => 'http://identi.ca/api', | |
32 | apirealm => 'Laconica API', | |
33 | oauth_urls => { | |
34 | request_token_url => "https://identi.ca/api/oauth/request_token", | |
35 | authentication_url => "https://identi.ca/api/oauth/authenticate", | |
36 | authorization_url => "https://identi.ca/api/oauth/authorize", | |
37 | access_token_url => "https://identi.ca/api/oauth/access_token", | |
38 | xauth_url => "https://identi.ca/api/oauth/access_token", | |
39 | }, | |
40 | %options, | |
41 | ); | |
42 | } | |
43 | ||
44 | return $next->($class, \%options); | |
45 | 21 | }; |
46 | 22 | |
47 | 23 | base_url 'apiurl'; |
464 | 440 | returns => 'Bool', |
465 | 441 | ); |
466 | 442 | |
443 | twitter_api_method no_retweet_ids => ( | |
444 | description => <<'', | |
445 | Returns an ARRAY ref of user IDs for which the authenticating user does not | |
446 | want to receive retweets. | |
447 | ||
448 | path => 'friendships/no_retweet_ids', | |
449 | method => 'GET', | |
450 | params => [], | |
451 | required => [], | |
452 | returns => 'ArrayRef[UserIDs]', | |
453 | ); | |
454 | ||
467 | 455 | twitter_api_method friends_ids => ( |
468 | 456 | description => <<'EOT', |
469 | 457 | Returns a reference to an array of numeric IDs for every user followed the |
904 | 892 | method => 'GET', |
905 | 893 | params => [qw/lat long/], |
906 | 894 | required => [], |
895 | authenticate => 0, | |
907 | 896 | returns => 'ArrayRef[Location]', |
908 | 897 | description => <<EOT, |
909 | 898 | Returns the locations with trending topic information. The response is an |
925 | 914 | params => [qw/woeid/], |
926 | 915 | required => [qw/woeid/], |
927 | 916 | returns => 'ArrayRef[Trend]', |
917 | authenticate => 0, | |
928 | 918 | description => <<'', |
929 | 919 | Returns the top 10 trending topics for a specific location. The response is an |
930 | 920 | array of "trend" objects that encode the name of the trending topic, the query |
936 | 926 | |
937 | 927 | ); |
938 | 928 | |
929 | twitter_api_method trends => ( | |
930 | description => <<'', | |
931 | Returns the top ten queries that are currently trending on Twitter. The | |
932 | response includes the time of the request, the name of each trending topic, and | |
933 | the url to the Twitter Search results page for that topic. | |
934 | ||
935 | path => 'trends', | |
936 | method => 'GET', | |
937 | params => [qw//], | |
938 | required => [qw//], | |
939 | authenticate => 0, | |
940 | returns => 'ArrayRef[Query]', | |
941 | ); | |
942 | ||
943 | twitter_api_method trends_current => ( | |
944 | description => <<'', | |
945 | Returns the current top ten trending topics on Twitter. The response includes | |
946 | the time of the request, the name of each trending topic, and query used on | |
947 | Twitter Search results page for that topic. | |
948 | ||
949 | path => 'trends/current', | |
950 | method => 'GET', | |
951 | params => [qw/exclude/], | |
952 | required => [qw//], | |
953 | authenticate => 0, | |
954 | returns => 'HashRef', | |
955 | ); | |
956 | ||
957 | twitter_api_method trends_daily => ( | |
958 | description => <<'', | |
959 | Returns the top 20 trending topics for each hour in a given day. | |
960 | ||
961 | path => 'trends/daily', | |
962 | method => 'GET', | |
963 | params => [qw/date exclude/], | |
964 | required => [qw//], | |
965 | authenticate => 0, | |
966 | returns => 'HashRef', | |
967 | ); | |
968 | ||
969 | twitter_api_method trends_weekly => ( | |
970 | description => <<'', | |
971 | Returns the top 30 trending topics for each day in a given week. | |
972 | ||
973 | path => 'trends/weekly', | |
974 | method => 'GET', | |
975 | params => [qw/date exclude/], | |
976 | required => [qw//], | |
977 | authenticate => 0, | |
978 | returns => 'HashRef', | |
979 | ); | |
980 | ||
939 | 981 | twitter_api_method reverse_geocode => ( |
940 | 982 | path => 'geo/reverse_geocode', |
941 | 983 | method => 'GET', |
1085 | 1127 | |
1086 | 1128 | ); |
1087 | 1129 | |
1088 | # new in 3.15000 2010-10-19 | |
1130 | # new in 3.17001 2010-10-19 | |
1089 | 1131 | |
1090 | 1132 | twitter_api_method account_totals => ( |
1091 | 1133 | path => 'account/totals', |
0 | 0 | package Net::Twitter::Role::API::Search::Trends; |
1 | ||
2 | 1 | use Moose::Role; |
3 | use Net::Twitter::API; | |
4 | ||
5 | has search_trends_api_url => ( isa => 'Str', is => 'rw', default => 'http://api.twitter.com/1' ); | |
6 | 2 | |
7 | 3 | after BUILD => sub { |
8 | 4 | my $self = shift; |
9 | 5 | |
10 | $self->{search_trends_api_url} =~ s/^http:/https:/ if $self->ssl; | |
6 | unless ( $self->can('trends') || $ENV{NET_TWITTER_NO_TRENDS_WARNING} ) { | |
7 | warn <<EOT; | |
8 | The "trends" methods have been moved to the API::REST trait. This warning | |
9 | will be removed in a future release. You can supress it by: | |
10 | ||
11 | - including the API::REST trait | |
12 | - or setting the environment variable NET_TWITTER_NO_TRENDS_WARNING=1 | |
13 | EOT | |
14 | } | |
11 | 15 | }; |
12 | ||
13 | base_url 'search_trends_api_url'; | |
14 | authenticate 0; | |
15 | ||
16 | twitter_api_method trends => ( | |
17 | description => <<'', | |
18 | Returns the top ten queries that are currently trending on Twitter. The | |
19 | response includes the time of the request, the name of each trending topic, and | |
20 | the url to the Twitter Search results page for that topic. | |
21 | ||
22 | path => 'trends', | |
23 | method => 'GET', | |
24 | params => [qw//], | |
25 | required => [qw//], | |
26 | returns => 'ArrayRef[Query]', | |
27 | ); | |
28 | ||
29 | twitter_api_method trends_current => ( | |
30 | description => <<'', | |
31 | Returns the current top ten trending topics on Twitter. The response includes | |
32 | the time of the request, the name of each trending topic, and query used on | |
33 | Twitter Search results page for that topic. | |
34 | ||
35 | path => 'trends/current', | |
36 | method => 'GET', | |
37 | params => [qw/exclude/], | |
38 | required => [qw//], | |
39 | returns => 'HashRef', | |
40 | ); | |
41 | ||
42 | twitter_api_method trends_daily => ( | |
43 | description => <<'', | |
44 | Returns the top 20 trending topics for each hour in a given day. | |
45 | ||
46 | path => 'trends/daily', | |
47 | method => 'GET', | |
48 | params => [qw/date exclude/], | |
49 | required => [qw//], | |
50 | returns => 'HashRef', | |
51 | ); | |
52 | ||
53 | twitter_api_method trends_weekly => ( | |
54 | description => <<'', | |
55 | Returns the top 30 trending topics for each day in a given week. | |
56 | ||
57 | path => 'trends/weekly', | |
58 | method => 'GET', | |
59 | params => [qw/date exclude/], | |
60 | required => [qw//], | |
61 | returns => 'HashRef', | |
62 | ); | |
63 | 16 | |
64 | 17 | 1; |
65 | 18 | |
67 | 20 | |
68 | 21 | =head1 NAME |
69 | 22 | |
70 | Net::Twitter::Role::API::Search::Trends - A definition of the Twitter Search Trends API as a Moose role | |
23 | Net::Twitter::Role::API::Search::Trends - DEPRECATED: use API::REST | |
71 | 24 | |
72 | 25 | =head1 SYNOPSIS |
73 | 26 | |
74 | package My::Twitter; | |
75 | use Moose; | |
76 | with 'Net::Twitter::API::Search'; | |
27 | my $nt = Net::Twitter->new(taits => [qw/API::Search API::REST/], ...); | |
77 | 28 | |
78 | 29 | =head1 DESCRIPTION |
79 | 30 | |
80 | B<Net::Twitter::Role::API::Search::Trends> provides definitions for all the | |
81 | Twitter Search Trends API methods. You probably don't want to use it directly. | |
82 | It is included when you use C<Search::API>. The trends methods were factored | |
83 | out into their own class when Twitter changed the base URL for trends so that | |
84 | it differs from search. | |
31 | The C<trends> methods have been move to the C<API::REST> trait. | |
85 | 32 | |
86 | 33 | =head1 AUTHOR |
87 | 34 |
33 | 33 | |
34 | 34 | path => 'search', |
35 | 35 | method => 'GET', |
36 | params => [qw/q callback lang rpp page since_id geocode show_user/], | |
36 | params => [qw/q callback lang locale rpp page since_id until geocode show_user result_type/], | |
37 | 37 | required => [qw/q/], |
38 | 38 | returns => 'HashRef', |
39 | 39 | ); |
0 | package Net::Twitter::Role::AutoCursor; | |
1 | use MooseX::Role::Parameterized; | |
2 | ||
3 | parameter max_calls => isa => 'Int', default => 16; | |
4 | parameter array_accessor => isa => 'Str', default => 'ids'; | |
5 | parameter force_cursor => isa => 'Bool', default => 0; | |
6 | parameter methods => isa => 'ArrayRef[Str]', default => sub { [qw/friends_ids followers_ids/] }; | |
7 | ||
8 | role { | |
9 | my $p = shift; | |
10 | ||
11 | requires @{$p->methods}; | |
12 | ||
13 | my $around = sub { | |
14 | my $orig = shift; | |
15 | my $self = shift; | |
16 | ||
17 | my $args = ref $_[-1] eq 'HASH' ? pop : {}; | |
18 | $args->{id} = shift if @_; | |
19 | ||
20 | $args->{cursor} = -1 if !exists $args->{cursor} && $p->force_cursor; | |
21 | ||
22 | my $max_calls = delete $args->{max_calls} || $p->max_calls; | |
23 | ||
24 | my $calls = 0; | |
25 | my $results; | |
26 | if ( !exists $args->{cursor} ) { | |
27 | my $r = $orig->($self, $args); | |
28 | ++$calls; | |
29 | if ( ref $r eq 'HASH' ) { | |
30 | # If Twitter forces a cursored call, we'll get a HASH instead of an ARRAY | |
31 | $results = $r->{$p->array_accessor}; | |
32 | $args->{cursor} = $r->{next_cursor}; | |
33 | } | |
34 | else { | |
35 | $results = $r; | |
36 | } | |
37 | } | |
38 | ||
39 | while ( $args->{cursor} && $calls++ < $max_calls ) { | |
40 | my $r = $orig->($self, $args); | |
41 | push @$results, @{$r->{$p->array_accessor}}; | |
42 | $args->{cursor} = $r->{next_cursor}; | |
43 | } | |
44 | ||
45 | return $results; | |
46 | }; | |
47 | ||
48 | around $_, $around for @{$p->methods}; | |
49 | }; | |
50 | ||
51 | 1; | |
52 | ||
53 | __END__ | |
54 | ||
55 | =head1 NAME | |
56 | ||
57 | Net::Twitter::Role::AutoCursor | |
58 | ||
59 | =head1 SYNOPSIS | |
60 | ||
61 | use Net::Twitter; | |
62 | my $nt = Net::Twitter->new( | |
63 | traits => [qw/AutoCursor API::REST RetryOnError OAuth/], | |
64 | # additional ags... | |
65 | ); | |
66 | ||
67 | # Get friends_ids or followers_ids without worrying about cursors | |
68 | my $ids = $nt->followers_ids; | |
69 | ||
70 | my $nt = Net::Twitter->new( | |
71 | traits => [ | |
72 | qw/API::REST RetryOnError OAuth/ | |
73 | AutoCursor => { max_calls => 32 }, | |
74 | AutoCursor => { | |
75 | max_calls => 4, | |
76 | force_cursor => 1, | |
77 | array_accessor => 'users', | |
78 | methods => [qw/friends followers/], | |
79 | }, | |
80 | ], | |
81 | # additional args | |
82 | ); | |
83 | ||
84 | # works with any Twitter call that takes a cursor parameter | |
85 | my $friends = $nt->friends; | |
86 | ||
87 | =head1 DESCRIPTION | |
88 | ||
89 | On 25-Mar-2011, Twitter announced a change to C<friends_ids> and | |
90 | C<followers_ids> API methods: | |
91 | ||
92 | [Soon] followers/ids and friends/ids is being updated to set the cursor to -1 | |
93 | if it isn't supplied during the request. This changes the default response | |
94 | format | |
95 | ||
96 | This will break a lot of existing code. The C<AutoCursor> trait was created to | |
97 | help users transition to cursor based access for these methods. | |
98 | ||
99 | With default parameters, the C<AutoCursor> trait attempts a non-cursored call | |
100 | for C<friends_ids> and C<followers_ids>. If it detects a cursored | |
101 | response from Twitter, it continues to call the underlying Twitter API method, | |
102 | with the next cursor, until it has received all results or 16 calls have been | |
103 | made (yielding 80,000 results). It returns an ARRAY reference to the combined | |
104 | results. | |
105 | ||
106 | If the C<cursor> parameter is passed to C<friends_ids> or C<followers_ids>, | |
107 | C<Net::Twitter> uses cursored access from the start, i.e., it does not | |
108 | attempt an initial non-cursored call. | |
109 | ||
110 | The C<AutoCursor> trait is parameterized, allowing it to work with any Twitter | |
111 | API method that expects cursors, returning combined results for up to the | |
112 | maximum number of calls specified. | |
113 | ||
114 | C<AutoCursor> can be applied multiple times to handle different sets of API | |
115 | methods. | |
116 | ||
117 | =head1 PARAMETERS | |
118 | ||
119 | =over 4 | |
120 | ||
121 | =item max_calls | |
122 | ||
123 | An integer specifying the maximum number of API calls to make. Default is 16. | |
124 | ||
125 | C<max_calls> can be overridden on a per-call basis by passing a C<max_calls> | |
126 | argument to the API method. | |
127 | ||
128 | =item force_cursor | |
129 | ||
130 | If true, when the caller does not provide a C<cursor> parameter, C<AutoCursor> | |
131 | will add one with value -1. Default is 0. | |
132 | ||
133 | =item array_accessor | |
134 | ||
135 | The name of the HASH key used to access the ARRAY ref of results in the data | |
136 | structure returned by Twitter. Default is C<ids>. | |
137 | ||
138 | =item methods | |
139 | ||
140 | A reference to an ARRAY containing the names of Twitter API methods to which | |
141 | C<AutoCursor> will be applied. | |
142 | ||
143 | =back | |
144 | ||
145 | =head1 AUTHOR | |
146 | ||
147 | Marc Mims <marc@questright.com> | |
148 | ||
149 | =head1 COPYRIGHT | |
150 | ||
151 | Copyright (c) 2011 Marc Mims | |
152 | ||
153 | =head1 LICENSE | |
154 | ||
155 | This library is free software and may be distributed under the same terms as perl itself. | |
156 | ||
157 | =cut | |
158 |
1 | 1 | use Moose; |
2 | 2 | |
3 | 3 | # use *all* digits for fBSD ports |
4 | our $VERSION = '3.15000'; | |
4 | our $VERSION = '3.17001'; | |
5 | 5 | $VERSION = eval $VERSION; # numify for warning-free dev releases |
6 | 6 | |
7 | 7 | extends 'Net::Twitter::Core'; |
1 | 1 | use Moose; |
2 | 2 | use Carp; |
3 | 3 | use Net::Twitter::Core; |
4 | use Digest::SHA1 qw/sha1_hex/; | |
4 | 5 | |
5 | 6 | use namespace::autoclean; |
6 | 7 | |
10 | 11 | ); |
11 | 12 | |
12 | 13 | # use *all* digits for fBSD ports |
13 | our $VERSION = '3.15000'; | |
14 | our $VERSION = '3.17001'; | |
14 | 15 | |
15 | 16 | $VERSION = eval $VERSION; # numify for warning-free dev releases |
16 | 17 | |
38 | 39 | |
39 | 40 | sub _resolve_traits { |
40 | 41 | my ($class, @traits) = @_; |
42 | ||
41 | 43 | return map { |
42 | my $transformed = $class->_transform_trait($_); | |
43 | Class::MOP::load_class($transformed); | |
44 | $transformed; | |
44 | unless ( ref ) { | |
45 | $_ = $class->_transform_trait($_); | |
46 | Class::MOP::load_class($_); | |
47 | } | |
48 | $_; | |
45 | 49 | } @traits; |
46 | 50 | } |
47 | 51 | |
55 | 59 | sub _create_anon_class { |
56 | 60 | my ($superclasses, $traits, $immutable, $package) = @_; |
57 | 61 | |
62 | # Do we already have a meta class? | |
63 | return $package->meta if $package->can('meta'); | |
64 | ||
58 | 65 | my $meta; |
59 | 66 | $meta = Net::Twitter::Core->meta->create_anon_class( |
60 | 67 | superclasses => $superclasses, |
61 | 68 | roles => $traits, |
62 | 69 | methods => { meta => sub { $meta }, isa => \&_isa }, |
63 | cache => 1, | |
70 | cache => 0, | |
64 | 71 | package => $package, |
65 | 72 | ); |
66 | 73 | $meta->make_immutable(inline_constructor => $immutable); |
67 | 74 | |
68 | 75 | return $meta; |
76 | } | |
77 | ||
78 | { | |
79 | my $serial_number = 0; | |
80 | my %serial_for_params; | |
81 | ||
82 | sub _name_for_anon_class { | |
83 | my @t = @{$_[0]}; | |
84 | ||
85 | my @comps; | |
86 | while ( @t ) { | |
87 | my $t = shift @t; | |
88 | if ( ref $t[0] eq 'HASH' ) { | |
89 | my $params = shift @t; | |
90 | my $sig = sha1_hex(JSON::Any->to_json($params)); | |
91 | my $sn = $serial_for_params{$sig} ||= ++$serial_number; | |
92 | $t .= "_$sn"; | |
93 | } | |
94 | $t =~ s/(?:::|\W)/_/g; | |
95 | push @comps, $t; | |
96 | } | |
97 | ||
98 | return __PACKAGE__ . '::' . join '__', 'with', sort @comps; | |
99 | } | |
69 | 100 | } |
70 | 101 | |
71 | 102 | sub new { |
89 | 120 | # ensure we have the OAuth trait if we have a consumer key |
90 | 121 | $traits = [ (grep $_ ne 'OAuth', @$traits), 'OAuth' ] if $args{consumer_key}; |
91 | 122 | |
92 | my $package_suffix = 'with__' . join '__', | |
93 | map { (my $part = $_) =~ s/::/_/g; $part =~ s/\W//; $part } sort @$traits; | |
123 | # create a unique name for the created class based on trait names and parameters | |
124 | my $anon_class_name = _name_for_anon_class($traits); | |
94 | 125 | |
95 | 126 | $traits = [ $class->_resolve_traits(@$traits) ]; |
96 | 127 | |
97 | 128 | my $superclasses = [ 'Net::Twitter::Core' ]; |
98 | my $meta = _create_anon_class($superclasses, $traits, 1, __PACKAGE__ . '::' . $package_suffix); | |
129 | my $meta = _create_anon_class($superclasses, $traits, 1, $anon_class_name); | |
99 | 130 | |
100 | 131 | # create a Net::Twitter::Core object with roles applied |
101 | 132 | my $new = $meta->name->new(%args); |
104 | 135 | if ( $class ne __PACKAGE__ ) { |
105 | 136 | unshift @$superclasses, $class; |
106 | 137 | my $final_meta = _create_anon_class( |
107 | $superclasses, $traits, 0, join '::', $class, __PACKAGE__, $package_suffix | |
138 | $superclasses, $traits, 0, join '::', $class, $anon_class_name | |
108 | 139 | ); |
109 | 140 | bless $new, $final_meta->name; |
110 | 141 | } |
3 | 3 | |
4 | 4 | =head1 VERSION |
5 | 5 | |
6 | This document describes Net::Twitter version 3.15000 | |
6 | This document describes Net::Twitter version 3.17001 | |
7 | 7 | |
8 | 8 | =head1 SYNOPSIS |
9 | 9 | |
123 | 123 | Provides support for the TwitterVision API. See |
124 | 124 | L<http://twittervision.com/api.html>. |
125 | 125 | |
126 | =item WrapError | |
127 | ||
128 | C<Net::Twitter> normally throws exceptions on error. When this trait is | |
129 | included, C<Net::Twitter> returns undef when a method fails and makes the | |
130 | error available through method C<get_error>. This is the way all errors were | |
131 | handled in Net::Twitter versions prior to version 3.00. | |
132 | ||
133 | =item OAuth | |
134 | ||
135 | The C<OAuth> trait provides OAuth authentication rather than the default Basic | |
136 | Authentication for Twitter API method calls. See the L</Authentication> | |
137 | section and L<Net::Twitter::Role::OAuth> for full documentation. | |
126 | =item AutoCursor | |
127 | ||
128 | C<AutoCursor> is a parameterized trait that provides an automatic loop for | |
129 | cursored calls, returning an ARRAY reference to the combined results. By | |
130 | default, it handles C<friends_ids> and C<followers_ids>. See | |
131 | L<Net::Twitter::Role::AutoCursor> for details. | |
138 | 132 | |
139 | 133 | =item InflateObjects |
140 | 134 | |
161 | 155 | # etc. |
162 | 156 | print $r->relative_created_at; |
163 | 157 | |
164 | =item RateLimit | |
165 | ||
166 | The C<RateLimit> trait adds utility methods that return information about the | |
167 | current rate limit status. See L<Net::Twitter::Role::RateLimit> for details. | |
168 | ||
169 | 158 | =item Legacy |
170 | 159 | |
171 | 160 | This trait provides backwards compatibility to C<Net::Twitter> versions prior |
178 | 167 | option is not specified. This ensures backwards compatibility for existing |
179 | 168 | applications using C<Net::Twitter> versions prior to 3.00. See section |
180 | 169 | L</LEGACY COMPATIBILITY> for more details. |
170 | ||
171 | =item OAuth | |
172 | ||
173 | The C<OAuth> trait provides OAuth authentication rather than the default Basic | |
174 | Authentication for Twitter API method calls. See the L</Authentication> | |
175 | section and L<Net::Twitter::Role::OAuth> for full documentation. | |
176 | ||
177 | =item RateLimit | |
178 | ||
179 | The C<RateLimit> trait adds utility methods that return information about the | |
180 | current rate limit status. See L<Net::Twitter::Role::RateLimit> for details. | |
181 | ||
182 | =item RetryOnError | |
183 | ||
184 | The C<RetryOnError> trait automatically retries Twitter API calls with | |
185 | temporary failures. See L<Net::Twitter::Role::RetryOnError> for details. | |
186 | ||
187 | =item WrapError | |
188 | ||
189 | C<Net::Twitter> normally throws exceptions on error. When this trait is | |
190 | included, C<Net::Twitter> returns undef when a method fails and makes the | |
191 | error available through method C<get_error>. This is the way all errors were | |
192 | handled in Net::Twitter versions prior to version 3.00. | |
181 | 193 | |
182 | 194 | =back |
183 | 195 | |
1306 | 1318 | |
1307 | 1319 | Returns: DirectMessage |
1308 | 1320 | |
1321 | =item B<no_retweet_ids> | |
1322 | ||
1323 | ||
1324 | ||
1325 | =over 4 | |
1326 | ||
1327 | =item Parameters: I<none> | |
1328 | ||
1329 | =item Required: I<none> | |
1330 | ||
1331 | =back | |
1332 | ||
1333 | Returns an ARRAY ref of user IDs for which the authenticating user does not | |
1334 | want to receive retweets. | |
1335 | ||
1336 | ||
1337 | Returns: ArrayRef[UserIDs] | |
1338 | ||
1309 | 1339 | =item B<public_timeline> |
1310 | 1340 | |
1311 | 1341 | |
1811 | 1841 | |
1812 | 1842 | Returns: Str |
1813 | 1843 | |
1844 | =item B<trends> | |
1845 | ||
1846 | ||
1847 | ||
1848 | =over 4 | |
1849 | ||
1850 | =item Parameters: I<none> | |
1851 | ||
1852 | =item Required: I<none> | |
1853 | ||
1854 | =back | |
1855 | ||
1856 | Returns the top ten queries that are currently trending on Twitter. The | |
1857 | response includes the time of the request, the name of each trending topic, and | |
1858 | the url to the Twitter Search results page for that topic. | |
1859 | ||
1860 | ||
1861 | Returns: ArrayRef[Query] | |
1862 | ||
1814 | 1863 | =item B<trends_available> |
1815 | 1864 | |
1816 | 1865 | |
1836 | 1885 | |
1837 | 1886 | |
1838 | 1887 | Returns: ArrayRef[Location] |
1888 | ||
1889 | =item B<trends_current> | |
1890 | ||
1891 | =item B<trends_current(exclude)> | |
1892 | ||
1893 | ||
1894 | ||
1895 | =over 4 | |
1896 | ||
1897 | =item Parameters: exclude | |
1898 | ||
1899 | =item Required: I<none> | |
1900 | ||
1901 | =back | |
1902 | ||
1903 | Returns the current top ten trending topics on Twitter. The response includes | |
1904 | the time of the request, the name of each trending topic, and query used on | |
1905 | Twitter Search results page for that topic. | |
1906 | ||
1907 | ||
1908 | Returns: HashRef | |
1909 | ||
1910 | =item B<trends_daily> | |
1911 | ||
1912 | ||
1913 | ||
1914 | =over 4 | |
1915 | ||
1916 | =item Parameters: date, exclude | |
1917 | ||
1918 | =item Required: I<none> | |
1919 | ||
1920 | =back | |
1921 | ||
1922 | Returns the top 20 trending topics for each hour in a given day. | |
1923 | ||
1924 | ||
1925 | Returns: HashRef | |
1839 | 1926 | |
1840 | 1927 | =item B<trends_location> |
1841 | 1928 | |
1862 | 1949 | |
1863 | 1950 | Returns: ArrayRef[Trend] |
1864 | 1951 | |
1952 | =item B<trends_weekly> | |
1953 | ||
1954 | ||
1955 | ||
1956 | =over 4 | |
1957 | ||
1958 | =item Parameters: date, exclude | |
1959 | ||
1960 | =item Required: I<none> | |
1961 | ||
1962 | =back | |
1963 | ||
1964 | Returns the top 30 trending topics for each day in a given week. | |
1965 | ||
1966 | ||
1967 | Returns: HashRef | |
1968 | ||
1865 | 1969 | =item B<update> |
1866 | 1970 | |
1867 | 1971 | =item B<update(status)> |
2181 | 2285 | |
2182 | 2286 | =over 4 |
2183 | 2287 | |
2184 | =item Parameters: q, callback, lang, rpp, page, since_id, geocode, show_user | |
2288 | =item Parameters: q, callback, lang, locale, rpp, page, since_id, until, geocode, show_user, result_type | |
2185 | 2289 | |
2186 | 2290 | =item Required: q |
2187 | 2291 | |
2195 | 2299 | for my $status ( @{$r->{results}} ) { |
2196 | 2300 | print "$status->{text}\n"; |
2197 | 2301 | } |
2198 | ||
2199 | ||
2200 | Returns: HashRef | |
2201 | ||
2202 | =item B<trends> | |
2203 | ||
2204 | ||
2205 | ||
2206 | =over 4 | |
2207 | ||
2208 | =item Parameters: I<none> | |
2209 | ||
2210 | =item Required: I<none> | |
2211 | ||
2212 | =back | |
2213 | ||
2214 | Returns the top ten queries that are currently trending on Twitter. The | |
2215 | response includes the time of the request, the name of each trending topic, and | |
2216 | the url to the Twitter Search results page for that topic. | |
2217 | ||
2218 | ||
2219 | Returns: ArrayRef[Query] | |
2220 | ||
2221 | =item B<trends_current> | |
2222 | ||
2223 | =item B<trends_current(exclude)> | |
2224 | ||
2225 | ||
2226 | ||
2227 | =over 4 | |
2228 | ||
2229 | =item Parameters: exclude | |
2230 | ||
2231 | =item Required: I<none> | |
2232 | ||
2233 | =back | |
2234 | ||
2235 | Returns the current top ten trending topics on Twitter. The response includes | |
2236 | the time of the request, the name of each trending topic, and query used on | |
2237 | Twitter Search results page for that topic. | |
2238 | ||
2239 | ||
2240 | Returns: HashRef | |
2241 | ||
2242 | =item B<trends_daily> | |
2243 | ||
2244 | ||
2245 | ||
2246 | =over 4 | |
2247 | ||
2248 | =item Parameters: date, exclude | |
2249 | ||
2250 | =item Required: I<none> | |
2251 | ||
2252 | =back | |
2253 | ||
2254 | Returns the top 20 trending topics for each hour in a given day. | |
2255 | ||
2256 | ||
2257 | Returns: HashRef | |
2258 | ||
2259 | =item B<trends_weekly> | |
2260 | ||
2261 | ||
2262 | ||
2263 | =over 4 | |
2264 | ||
2265 | =item Parameters: date, exclude | |
2266 | ||
2267 | =item Required: I<none> | |
2268 | ||
2269 | =back | |
2270 | ||
2271 | Returns the top 30 trending topics for each day in a given week. | |
2272 | 2302 | |
2273 | 2303 | |
2274 | 2304 | Returns: HashRef |
123 | 123 | Provides support for the TwitterVision API. See |
124 | 124 | L<http://twittervision.com/api.html>. |
125 | 125 | |
126 | =item WrapError | |
127 | ||
128 | C<Net::Twitter> normally throws exceptions on error. When this trait is | |
129 | included, C<Net::Twitter> returns undef when a method fails and makes the | |
130 | error available through method C<get_error>. This is the way all errors were | |
131 | handled in Net::Twitter versions prior to version 3.00. | |
132 | ||
133 | =item OAuth | |
134 | ||
135 | The C<OAuth> trait provides OAuth authentication rather than the default Basic | |
136 | Authentication for Twitter API method calls. See the L</Authentication> | |
137 | section and L<Net::Twitter::Role::OAuth> for full documentation. | |
126 | =item AutoCursor | |
127 | ||
128 | C<AutoCursor> is a parameterized trait that provides an automatic loop for | |
129 | cursored calls, returning an ARRAY reference to the combined results. By | |
130 | default, it handles C<friends_ids> and C<followers_ids>. See | |
131 | L<Net::Twitter::Role::AutoCursor> for details. | |
138 | 132 | |
139 | 133 | =item InflateObjects |
140 | 134 | |
161 | 155 | # etc. |
162 | 156 | print $r->relative_created_at; |
163 | 157 | |
164 | =item RateLimit | |
165 | ||
166 | The C<RateLimit> trait adds utility methods that return information about the | |
167 | current rate limit status. See L<Net::Twitter::Role::RateLimit> for details. | |
168 | ||
169 | 158 | =item Legacy |
170 | 159 | |
171 | 160 | This trait provides backwards compatibility to C<Net::Twitter> versions prior |
178 | 167 | option is not specified. This ensures backwards compatibility for existing |
179 | 168 | applications using C<Net::Twitter> versions prior to 3.00. See section |
180 | 169 | L</LEGACY COMPATIBILITY> for more details. |
170 | ||
171 | =item OAuth | |
172 | ||
173 | The C<OAuth> trait provides OAuth authentication rather than the default Basic | |
174 | Authentication for Twitter API method calls. See the L</Authentication> | |
175 | section and L<Net::Twitter::Role::OAuth> for full documentation. | |
176 | ||
177 | =item RateLimit | |
178 | ||
179 | The C<RateLimit> trait adds utility methods that return information about the | |
180 | current rate limit status. See L<Net::Twitter::Role::RateLimit> for details. | |
181 | ||
182 | =item RetryOnError | |
183 | ||
184 | The C<RetryOnError> trait automatically retries Twitter API calls with | |
185 | temporary failures. See L<Net::Twitter::Role::RetryOnError> for details. | |
186 | ||
187 | =item WrapError | |
188 | ||
189 | C<Net::Twitter> normally throws exceptions on error. When this trait is | |
190 | included, C<Net::Twitter> returns undef when a method fails and makes the | |
191 | error available through method C<get_error>. This is the way all errors were | |
192 | handled in Net::Twitter versions prior to version 3.00. | |
181 | 193 | |
182 | 194 | =back |
183 | 195 |
1 | 1 | use warnings; |
2 | 2 | use strict; |
3 | 3 | use Test::More; |
4 | use Test::Exception; | |
4 | use Test::Fatal; | |
5 | 5 | use lib qw(t/lib); |
6 | 6 | use Net::Twitter; |
7 | 7 | |
19 | 19 | my $t = TestUA->new($nt->ua); |
20 | 20 | |
21 | 21 | # things that should fail |
22 | throws_ok { $nt->relationship_exists(qw/one two three/) } qr/expected 2 args/, 'too many args'; | |
23 | throws_ok { | |
24 | Net::Twitter->new(useragent_class => 'NoSuchModule::Test7701')->verify_credentials | |
25 | } qr/Can't locate NoSuchModule/, 'bad useragent_class'; | |
22 | like exception { $nt->relationship_exists(qw/one two three/) }, qr/expected 2 args/, 'too many args'; | |
23 | like exception { Net::Twitter->new(useragent_class => 'NoSuchModule::Test7701')->verify_credentials }, | |
24 | qr/Can't locate NoSuchModule/, 'bad useragent_class'; | |
26 | 25 | |
27 | 26 | exit 0; |
1 | 1 | use Carp; |
2 | 2 | use strict; |
3 | 3 | use Test::More; |
4 | use Test::Exception; | |
4 | use Test::Fatal; | |
5 | 5 | use lib qw(t/lib); |
6 | 6 | |
7 | 7 | { |
38 | 38 | my $r; |
39 | 39 | |
40 | 40 | # back compat: 1.23 accepts scalar args |
41 | lives_ok { $r = $nt->relationship_exists('homer', 'marge') } 'relationship_exists scalar args'; | |
41 | is exception { $r = $nt->relationship_exists('homer', 'marge') }, undef, 'relationship_exists scalar args'; | |
42 | 42 | |
43 | 43 | ok $r = $nt->relationship_exists({ user_a => 'homer', user_b => 'marge' }), |
44 | 44 | 'relationship_exists hashref'; |
92 | 92 | is $t->request->uri->scheme, 'https', 'ssl used for Lists'; |
93 | 93 | |
94 | 94 | ### v3.10001 ### netrc used $self->apiurl, which is only available via the API::REST trait |
95 | lives_ok { Net::Twitter->new(netrc => 1, traits => [qw/API::Lists/]) } | |
96 | 'netrc with API::Lists lives'; | |
95 | is exception { Net::Twitter->new(netrc => 1, traits => [qw/API::Lists/]) }, undef, 'netrc with API::Lists lives'; | |
97 | 96 | ### v3.11004 ### single array ref arg to update_profile_image not proprerly handled |
98 | 97 | $r = $nt->update_profile_image([ undef, 'my_mug.jpg', Content_Type => 'image/jpeg', Content => '' ]); |
99 | 98 | is $t->request->content_type, 'multipart/form-data', 'multipart/form-data'; |
3 | 3 | use strict; |
4 | 4 | |
5 | 5 | use Test::More tests => 3; |
6 | use Test::Exception; | |
6 | use Test::Fatal; | |
7 | 7 | |
8 | 8 | use_ok 'Net::Twitter'; |
9 | 9 | |
10 | 10 | my $nt; |
11 | lives_ok { $nt = Net::Twitter->new(useragent_args => { timeout => 20 }) } | |
11 | is exception { $nt = Net::Twitter->new(useragent_args => { timeout => 20 }) }, undef, | |
12 | 12 | 'object creation with useragent_args'; |
13 | 13 | |
14 | 14 | is $nt->ua->timeout, 20, 'useragent_args applied'; |
8 | 8 | eval 'use TestUA'; |
9 | 9 | plan skip_all => 'LWP::UserAgent 5.819 required for tests' if $@; |
10 | 10 | |
11 | plan tests => 4; | |
11 | plan tests => 5; | |
12 | 12 | |
13 | 13 | use_ok 'Net::Twitter'; |
14 | 14 | |
15 | my $nt = Net::Twitter->new(legacy => 0, identica => 1, username => 'me', password => 'secret'); | |
16 | my $t = TestUA->new($nt->ua); | |
15 | { | |
16 | my $nt = Net::Twitter->new(legacy => 0, identica => 1, username => 'me', password => 'secret'); | |
17 | my $t = TestUA->new($nt->ua); | |
17 | 18 | |
18 | $t->response->content('"true"'); | |
19 | my $r = $nt->follows('night', 'day'); | |
20 | ok $r, 'string "true" is true'; | |
19 | $t->response->content('"true"'); | |
20 | my $r = $nt->follows('night', 'day'); | |
21 | ok $r, 'string "true" is true'; | |
21 | 22 | |
22 | $t->response->content('"false"'); | |
23 | $r = $nt->follows('night', 'day'); | |
24 | ok !$r, 'string "false" is false'; | |
23 | $t->response->content('"false"'); | |
24 | $r = $nt->follows('night', 'day'); | |
25 | ok !$r, 'string "false" is false'; | |
25 | 26 | |
26 | 27 | # and when they finally get it right: |
27 | $t->response->content('"true"'); | |
28 | $r = $nt->follows('night', 'day'); | |
29 | ok $r, 'bool true is true'; | |
28 | $t->response->content('"true"'); | |
29 | $r = $nt->follows('night', 'day'); | |
30 | ok $r, 'bool true is true'; | |
31 | } | |
32 | ||
33 | { | |
34 | my $nt = Net::Twitter->new(traits => [qw/API::REST API::Search/], identica => 1); | |
35 | like $nt->searchapiurl, qr/identi\.ca/, 'use identica url for search'; | |
36 | } |
10 | 10 | |
11 | 11 | use Net::Twitter; |
12 | 12 | |
13 | my $nt = Net::Twitter->new(traits => [qw/API::Search/]); | |
13 | my $nt = Net::Twitter->new(traits => [qw/API::Search API::REST/]); | |
14 | 14 | |
15 | 15 | my $request; |
16 | 16 | my %args; |
1 | 1 | use warnings; |
2 | 2 | use strict; |
3 | 3 | use Test::More; |
4 | use Test::Exception; | |
4 | use Test::Fatal; | |
5 | 5 | use lib qw(t/lib); |
6 | 6 | use Net::Twitter; |
7 | 7 | |
16 | 16 | $nt = Net::Twitter->new(legacy => 0); |
17 | 17 | my $t = TestUA->new($nt->ua); |
18 | 18 | |
19 | lives_ok { $nt->user_timeline } "lives without credentials"; | |
19 | is exception { $nt->user_timeline }, undef, "lives without credentials"; | |
20 | 20 | ok !$t->request->header('Authorization'), "no auth header without credentials"; |
21 | 21 | |
22 | 22 | $nt->credentials(homer => 'doh!'); |
23 | lives_ok { $nt->user_timeline } "lives with credentials"; | |
23 | is exception { $nt->user_timeline }, undef, "lives with credentials"; | |
24 | 24 | like $t->request->header('Authorization'), qr/Basic/, "has Basic Auth header"; |
25 | 25 | |
26 | 26 | $nt->public_timeline; |
45 | 45 | ); |
46 | 46 | $t = TestUA->new($nt->ua); |
47 | 47 | |
48 | lives_ok { $nt->user_timeline } "lives without oauth tokens"; | |
48 | is exception { $nt->user_timeline }, undef, "lives without oauth tokens"; | |
49 | 49 | ok !$t->request->header('Authorization'), "no auth header without access tokens"; |
50 | 50 | |
51 | 51 | $nt->access_token('1234'); |
52 | 52 | $nt->access_token_secret('5678'); |
53 | lives_ok { $nt->user_timeline } "lives with access tokens"; | |
53 | is exception { $nt->user_timeline }, undef, "lives with access tokens"; |
1 | 1 | use warnings; |
2 | 2 | use strict; |
3 | 3 | use Test::More; |
4 | use Test::Exception; | |
4 | use Test::Fatal; | |
5 | 5 | use lib qw(t/lib); |
6 | 6 | use Net::Twitter; |
7 | 7 | |
8 | 8 | eval 'use TestUA'; |
9 | 9 | plan skip_all => 'LWP::UserAgent 5.819 required for tests' if $@; |
10 | ||
11 | plan tests => 11; | |
12 | 10 | |
13 | 11 | my $nt = Net::Twitter->new( |
14 | 12 | traits => [qw/API::REST/], |
34 | 32 | fail $message; |
35 | 33 | } |
36 | 34 | |
37 | dies_ok { $nt->destroy_direct_message(456) } 'TwitterException'; | |
38 | my $e = $@; | |
39 | isa_ok $e, 'Net::Twitter::Error'; | |
40 | like $e, qr/No direct message/, 'error stringifies'; | |
41 | is $e->http_response->code, 404, "respose code"; | |
42 | is $e->code, 404, 'http_response handles code'; | |
43 | like $e->twitter_error->{request}, qr/456.json/, 'twitter_error request'; | |
44 | is $e, $e->error, 'stringifies to $@->error'; | |
45 | ||
46 | ||
35 | { | |
36 | my $e = exception { $nt->destroy_direct_message(456) }; | |
37 | isa_ok $e, 'Net::Twitter::Error'; | |
38 | like $e, qr/No direct message/, 'error stringifies'; | |
39 | is $e->http_response->code, 404, "respose code"; | |
40 | is $e->code, 404, 'http_response handles code'; | |
41 | like $e->twitter_error->{request}, qr/456.json/, 'twitter_error request'; | |
42 | is $e, $e->error, 'stringifies to $@->error'; | |
43 | } | |
47 | 44 | |
48 | 45 | # simulate a 500 response returned by LWP::UserAgent when it can't make a connection |
49 | 46 | $response = HTTP::Response->new(500, "Can't connect to api.twitter.com:80"); |
50 | 47 | $response->content("<html>foo</html>"); |
51 | 48 | $t->response($response); |
52 | 49 | |
53 | dies_ok { $nt->friends_timeline({ since_id => 500_000_000 }) } 'HttpException'; | |
54 | $e = $@; | |
55 | isa_ok $e, 'Net::Twitter::Error'; | |
56 | like $e->http_response->content, qr/html/, 'html content'; | |
50 | { | |
51 | my $e = exception { $nt->friends_timeline({ since_id => 500_000_000 }) }; | |
52 | isa_ok $e, 'Net::Twitter::Error'; | |
53 | like $e->http_response->content, qr/html/, 'html content'; | |
54 | } | |
57 | 55 | |
58 | exit 0; | |
56 | done_testing; |
0 | 0 | #!perl |
1 | 1 | use warnings; |
2 | 2 | use strict; |
3 | use Test::Exception; | |
3 | use Test::Fatal; | |
4 | 4 | use Test::More; |
5 | 5 | use lib qw(t/lib); |
6 | 6 | |
22 | 22 | |
23 | 23 | $t->response(HTTP::Response->new(500, $msg)); |
24 | 24 | |
25 | lives_ok { $r = $nt->public_timeline } 'exception trapped'; | |
25 | is exception { $r = $nt->public_timeline }, undef, 'exception trapped'; | |
26 | 26 | is $nt->http_message, $msg, 'http_message'; |
27 | 27 | isa_ok $nt->get_error, 'HASH', 'get_error returns a HASH ref'; |
28 | 28 | ok !defined $r, 'result is undef'; |
0 | 0 | #!perl |
1 | 1 | use warnings; |
2 | 2 | use strict; |
3 | use Test::Exception; | |
3 | use Test::Fatal; | |
4 | 4 | use Test::More; |
5 | 5 | use lib qw(t/lib); |
6 | 6 | |
25 | 25 | |
26 | 26 | $t->response(HTTP::Response->new(500, $msg)); |
27 | 27 | |
28 | lives_ok { $nt->public_timeline } 'exception trapped'; | |
28 | is exception { $nt->public_timeline }, undef, 'exception trapped'; | |
29 | 29 | is $nt->http_message, $msg, 'http_message'; |
30 | 30 | |
31 | 31 | exit 0; |
57 | 57 | } |
58 | 58 | catch { pass $test }; |
59 | 59 | |
60 | $nt = Net::Twitter->new(traits => [qw/API::Search/]); | |
60 | $nt = Net::Twitter->new(traits => [qw/API::Search API::REST/]); | |
61 | 61 | $nt->ua->add_handler(request_send => sub { |
62 | 62 | my $res = HTTP::Response->new(200); |
63 | 63 | $res->content('{"test":"done"}'); |
19 | 19 | API |
20 | 20 | APIs |
21 | 21 | Akira |
22 | AutoCursor | |
22 | 23 | BasicUser |
23 | 24 | CPAN |
24 | 25 | DateTime |
44 | 45 | Prather |
45 | 46 | RateLimit |
46 | 47 | RateLimitStatus |
48 | RetryOnError | |
47 | 49 | Retweets |
48 | 50 | SMS |
49 | 51 | SSL |
78 | 80 | oauth |
79 | 81 | ok |
80 | 82 | online |
83 | parameterized | |
81 | 84 | params |
82 | 85 | perigrin |
83 | 86 | Pecorella |
0 | #!perl | |
1 | use warnings; | |
2 | use strict; | |
3 | use Test::More; | |
4 | use Net::Twitter; | |
5 | use JSON::Any; | |
6 | use HTTP::Response; | |
7 | ||
8 | my $json_result = JSON::Any->to_json({ ids => ['test'], next_cursor => 1 }); | |
9 | sub mock_ua { | |
10 | my $nt = shift; | |
11 | ||
12 | ||
13 | $nt->ua->add_handler(request_send => sub { | |
14 | my $resp = HTTP::Response->new(200); | |
15 | $resp->content($json_result); | |
16 | return $resp; | |
17 | }); | |
18 | } | |
19 | ||
20 | { | |
21 | my $nt_with_max_calls_2 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 2 }]); | |
22 | my $class_for_max_calls_2 = ref $nt_with_max_calls_2; | |
23 | ||
24 | my $nt_with_max_calls_4 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]); | |
25 | my $class_for_max_calls_4 = ref $nt_with_max_calls_4; | |
26 | ||
27 | my $json_result = JSON::Any->to_json({ ids => ['test'], next_cursor => 1 }); | |
28 | ||
29 | mock_ua($_) for $nt_with_max_calls_2, $nt_with_max_calls_4; | |
30 | ||
31 | my $r = $nt_with_max_calls_2->friends_ids({ cursor => -1 }); | |
32 | is scalar @$r, 2, 'max_calls => 2'; | |
33 | ||
34 | $r = $nt_with_max_calls_4->friends_ids({ cursor => -1 }); | |
35 | is scalar @$r, 4, 'max_calls => 4'; | |
36 | ||
37 | $r = $nt_with_max_calls_4->followers_ids({ cursor => -1, max_calls => 10 }); | |
38 | is scalar @$r, 10, 'max_calls per call override'; | |
39 | ||
40 | my $nt = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 2 }]); | |
41 | mock_ua($nt); | |
42 | is ref $nt, $class_for_max_calls_2, 'clone max_calls => 2, class name'; | |
43 | $r = $nt->friends_ids({ cursor => -1 }); | |
44 | is scalar @$r, 2, 'cloned max_calls => 2'; | |
45 | ||
46 | $nt = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]); | |
47 | mock_ua($nt); | |
48 | is ref $nt, $class_for_max_calls_4, 'clone max_calls => 4, class name'; | |
49 | $r = $nt->friends_ids({ cursor => -1 }); | |
50 | is scalar @$r, 4, 'cloned max_calls => 4'; | |
51 | } | |
52 | ||
53 | done_testing; |