From 5489d1375b6efe773b4931d5db7fb256fdb50f7f Mon Sep 17 00:00:00 2001 From: Marc Mims Date: Sat, 26 Mar 2011 12:44:30 -0700 Subject: [PATCH] Moved trends methods to API::REST --- Changes | 1 + Makefile.PL | 1 + README | 94 +++++++++++++---------- lib/Net/Twitter/Role/API/REST.pm | 54 +++++++++++++ lib/Net/Twitter/Role/API/Search/Trends.pm | 77 +++---------------- t/12_identica.t | 2 +- t/13_search.t | 2 +- t/51_since.t | 2 +- 8 files changed, 123 insertions(+), 110 deletions(-) diff --git a/Changes b/Changes index 04495d8..454c972 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Moved trends methods to API::REST; added warning to API::Search::Trends - Added no_retweet_ids method - modify searchapiurl for identica option - added deprecation notice to Net::Identica with Net::Twitter examples diff --git a/Makefile.PL b/Makefile.PL index dac8a3f..d725df9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,6 +4,7 @@ version_from 'lib/Net/Twitter/Core.pm'; perl_version_from 'lib/Net/Twitter/Core.pm'; if ( $Module::Install::AUTHOR ) { + $ENV{NET_TWITTER_NO_TRENDS_WARNING} = 1; system $^X, "src/build.pl", version, 'src/net-twitter-pod.tt2', 'lib/Net/Twitter.pod'; system 'pod2text lib/Net/Twitter.pod > README'; } diff --git a/README b/README index f988c86..e326c74 100644 --- a/README +++ b/README @@ -969,6 +969,16 @@ REST API Methods Returns: DirectMessage + no_retweet_ids + + Parameters: *none* + Required: *none* + + Returns an ARRAY ref of user IDs for which the authenticating user + does not want to receive retweets. + + Returns: ArrayRef[UserIDs] + public_timeline Parameters: skip_user, trim_user, include_entities @@ -1279,6 +1289,18 @@ REST API Methods Returns: Str + trends + + Parameters: *none* + Required: *none* + + Returns the top ten queries that are currently trending on Twitter. + The response includes the time of the request, the name of each + trending topic, and the url to the Twitter Search results page for + that topic. + + Returns: ArrayRef[Query] + trends_available Parameters: lat, long @@ -1300,6 +1322,27 @@ REST API Methods Returns: ArrayRef[Location] + trends_current + trends_current(exclude) + + Parameters: exclude + Required: *none* + + Returns the current top ten trending topics on Twitter. The response + includes the time of the request, the name of each trending topic, + and query used on Twitter Search results page for that topic. + + Returns: HashRef + + trends_daily + + Parameters: date, exclude + Required: *none* + + Returns the top 20 trending topics for each hour in a given day. + + Returns: HashRef + trends_location trends_location(woeid) @@ -1317,6 +1360,15 @@ REST API Methods Returns: ArrayRef[Trend] + trends_weekly + + Parameters: date, exclude + Required: *none* + + Returns the top 30 trending topics for each day in a given week. + + Returns: HashRef + update update(status) @@ -1537,48 +1589,6 @@ Search API Methods Returns: HashRef - trends - - Parameters: *none* - Required: *none* - - Returns the top ten queries that are currently trending on Twitter. - The response includes the time of the request, the name of each - trending topic, and the url to the Twitter Search results page for - that topic. - - Returns: ArrayRef[Query] - - trends_current - trends_current(exclude) - - Parameters: exclude - Required: *none* - - Returns the current top ten trending topics on Twitter. The response - includes the time of the request, the name of each trending topic, - and query used on Twitter Search results page for that topic. - - Returns: HashRef - - trends_daily - - Parameters: date, exclude - Required: *none* - - Returns the top 20 trending topics for each hour in a given day. - - Returns: HashRef - - trends_weekly - - Parameters: date, exclude - Required: *none* - - Returns the top 30 trending topics for each day in a given week. - - Returns: HashRef - Lists API Methods These methods are provided when trait "API::Lists" is included in the "traits" option to "new". All Lists API methods require a "user" diff --git a/lib/Net/Twitter/Role/API/REST.pm b/lib/Net/Twitter/Role/API/REST.pm index 5b098e8..2c551a5 100644 --- a/lib/Net/Twitter/Role/API/REST.pm +++ b/lib/Net/Twitter/Role/API/REST.pm @@ -893,6 +893,7 @@ twitter_api_method trends_available => ( method => 'GET', params => [qw/lat long/], required => [], + authenticate => 0, returns => 'ArrayRef[Location]', description => < ( params => [qw/woeid/], required => [qw/woeid/], returns => 'ArrayRef[Trend]', + authenticate => 0, description => <<'', Returns the top 10 trending topics for a specific location. The response is an array of "trend" objects that encode the name of the trending topic, the query @@ -925,6 +927,58 @@ available from this API by using a WOEID of 1. ); +twitter_api_method trends => ( + description => <<'', +Returns the top ten queries that are currently trending on Twitter. The +response includes the time of the request, the name of each trending topic, and +the url to the Twitter Search results page for that topic. + + path => 'trends', + method => 'GET', + params => [qw//], + required => [qw//], + authenticate => 0, + returns => 'ArrayRef[Query]', +); + +twitter_api_method trends_current => ( + description => <<'', +Returns the current top ten trending topics on Twitter. The response includes +the time of the request, the name of each trending topic, and query used on +Twitter Search results page for that topic. + + path => 'trends/current', + method => 'GET', + params => [qw/exclude/], + required => [qw//], + authenticate => 0, + returns => 'HashRef', +); + +twitter_api_method trends_daily => ( + description => <<'', +Returns the top 20 trending topics for each hour in a given day. + + path => 'trends/daily', + method => 'GET', + params => [qw/date exclude/], + required => [qw//], + authenticate => 0, + returns => 'HashRef', +); + +twitter_api_method trends_weekly => ( + description => <<'', +Returns the top 30 trending topics for each day in a given week. + + path => 'trends/weekly', + method => 'GET', + params => [qw/date exclude/], + required => [qw//], + authenticate => 0, + returns => 'HashRef', +); + twitter_api_method reverse_geocode => ( path => 'geo/reverse_geocode', method => 'GET', diff --git a/lib/Net/Twitter/Role/API/Search/Trends.pm b/lib/Net/Twitter/Role/API/Search/Trends.pm index 2fec494..4a182dc 100644 --- a/lib/Net/Twitter/Role/API/Search/Trends.pm +++ b/lib/Net/Twitter/Role/API/Search/Trends.pm @@ -1,88 +1,35 @@ package Net::Twitter::Role::API::Search::Trends; - use Moose::Role; -use Net::Twitter::API; - -has search_trends_api_url => ( isa => 'Str', is => 'rw', default => 'http://api.twitter.com/1' ); after BUILD => sub { my $self = shift; - $self->{search_trends_api_url} =~ s/^http:/https:/ if $self->ssl; + unless ( $self->can('trends') || $ENV{NET_TWITTER_NO_TRENDS_WARNING} ) { + warn < ( - description => <<'', -Returns the top ten queries that are currently trending on Twitter. The -response includes the time of the request, the name of each trending topic, and -the url to the Twitter Search results page for that topic. - - path => 'trends', - method => 'GET', - params => [qw//], - required => [qw//], - returns => 'ArrayRef[Query]', -); - -twitter_api_method trends_current => ( - description => <<'', -Returns the current top ten trending topics on Twitter. The response includes -the time of the request, the name of each trending topic, and query used on -Twitter Search results page for that topic. - - path => 'trends/current', - method => 'GET', - params => [qw/exclude/], - required => [qw//], - returns => 'HashRef', -); - -twitter_api_method trends_daily => ( - description => <<'', -Returns the top 20 trending topics for each hour in a given day. - - path => 'trends/daily', - method => 'GET', - params => [qw/date exclude/], - required => [qw//], - returns => 'HashRef', -); - -twitter_api_method trends_weekly => ( - description => <<'', -Returns the top 30 trending topics for each day in a given week. - - path => 'trends/weekly', - method => 'GET', - params => [qw/date exclude/], - required => [qw//], - returns => 'HashRef', -); - 1; __END__ =head1 NAME -Net::Twitter::Role::API::Search::Trends - A definition of the Twitter Search Trends API as a Moose role +Net::Twitter::Role::API::Search::Trends - DEPRECATED: use API::REST =head1 SYNOPSIS - package My::Twitter; - use Moose; - with 'Net::Twitter::API::Search'; + my $nt = Net::Twitter->new(taits => [qw/API::Search API::REST/], ...); =head1 DESCRIPTION -B provides definitions for all the -Twitter Search Trends API methods. You probably don't want to use it directly. -It is included when you use C. The trends methods were factored -out into their own class when Twitter changed the base URL for trends so that -it differs from search. +The C methods have been move to the C trait. =head1 AUTHOR diff --git a/t/12_identica.t b/t/12_identica.t index 1ae7323..49da8ef 100644 --- a/t/12_identica.t +++ b/t/12_identica.t @@ -32,6 +32,6 @@ use_ok 'Net::Twitter'; } { - my $nt = Net::Twitter->new(traits => ['API::Search'], identica => 1); + my $nt = Net::Twitter->new(traits => [qw/API::REST API::Search/], identica => 1); like $nt->searchapiurl, qr/identi\.ca/, 'use identica url for search'; } diff --git a/t/13_search.t b/t/13_search.t index c5459f5..f47a620 100644 --- a/t/13_search.t +++ b/t/13_search.t @@ -11,7 +11,7 @@ plan tests => 5; use Net::Twitter; -my $nt = Net::Twitter->new(traits => [qw/API::Search/]); +my $nt = Net::Twitter->new(traits => [qw/API::Search API::REST/]); my $request; my %args; diff --git a/t/51_since.t b/t/51_since.t index 1a04f4f..648ec0b 100644 --- a/t/51_since.t +++ b/t/51_since.t @@ -58,7 +58,7 @@ try { } catch { pass $test }; -$nt = Net::Twitter->new(traits => [qw/API::Search/]); +$nt = Net::Twitter->new(traits => [qw/API::Search API::REST/]); $nt->ua->add_handler(request_send => sub { my $res = HTTP::Response->new(200); $res->content('{"test":"done"}');