Skip to content

Commit

Permalink
Moved trends methods to API::REST
Browse files Browse the repository at this point in the history
  • Loading branch information
semifor committed Mar 26, 2011
1 parent 5d17caa commit 5489d13
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 110 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -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';
}
Expand Down
94 changes: 52 additions & 42 deletions README
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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"
Expand Down
54 changes: 54 additions & 0 deletions lib/Net/Twitter/Role/API/REST.pm
Expand Up @@ -893,6 +893,7 @@ twitter_api_method trends_available => (
method => 'GET',
params => [qw/lat long/],
required => [],
authenticate => 0,
returns => 'ArrayRef[Location]',
description => <<EOT,
Returns the locations with trending topic information. The response is an
Expand All @@ -914,6 +915,7 @@ twitter_api_method trends_location => (
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
Expand All @@ -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',
Expand Down
77 changes: 12 additions & 65 deletions 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 <<EOT;
The "trends" methods have been moved to the API::REST trait. This warning
will be removed in a future release. You can supress it by:
- including the API::REST trait
- or setting the environment variable NET_TWITTER_NO_TRENDS_WARNING=1
EOT
}
};

base_url 'search_trends_api_url';
authenticate 0;

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//],
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<Net::Twitter::Role::API::Search::Trends> 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<Search::API>. 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<trends> methods have been move to the C<API::REST> trait.
=head1 AUTHOR
Expand Down
2 changes: 1 addition & 1 deletion t/12_identica.t
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion t/13_search.t
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion t/51_since.t
Expand Up @@ -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"}');
Expand Down

0 comments on commit 5489d13

Please sign in to comment.