Skip to content
Browse files

Added tests for API v1.1 to match current Twitter docs

  • Loading branch information...
1 parent 635d35e commit 3381a5ebfd13f615ccac22d6c4f40117173371fe @semifor semifor committed Jan 28, 2013
Showing with 149 additions and 28 deletions.
  1. +82 −27 lib/Net/Twitter/Role/API/RESTv1_1.pm
  2. +67 −1 t/01_basic_v1_1.t
View
109 lib/Net/Twitter/Role/API/RESTv1_1.pm
@@ -35,7 +35,7 @@ Returns the 20 most recent mentions (statuses containing @username) for the
authenticating user.
aliases => [qw/replies mentions_timeline/],
- path => 'statuses/mentions',
+ path => 'statuses/mentions_timeline',
method => 'GET',
params => [qw/since_id max_id count trim_user include_entities contributor_details/],
booleans => [qw/trim_user include_entities contributor_details/],
@@ -206,7 +206,7 @@ twitter_api_method update_with_media => (
params => [qw/
status media[] possibly_sensitive in_reply_to_status_id lat long place_id display_coordinates
/],
- required => [qw/status media/],
+ required => [qw/status media[]/],
booleans => [qw/possibly_sensitive display_coordinates/],
returns => 'Status',
description => <<'EOT',
@@ -295,6 +295,7 @@ Important: this method requires an access token with RWD (read, write, and
direct message) permisions.
EOT
+ aliases => [qw/direct_messages_sent/],
path => 'direct_messages/sent',
method => 'GET',
params => [qw/since_id max_id page count include_entities/],
@@ -475,6 +476,7 @@ Returns an HASH ref with an array of numeric IDs in the C<ids> element for
every user who has a pending request to follow the authenticating user.
EOT
+ aliases => [qw/incoming_friendships/],
path => 'friendships/incoming',
method => 'GET',
params => [qw/cursor stringify_ids/],
@@ -490,6 +492,7 @@ every protected user for whom the authenticating user has a pending follow
request.
EOT
+ aliases => [qw/outgoing_friendships/],
path => 'friendships/outgoing',
method => 'GET',
params => [qw/cursor stringify_ids/],
@@ -918,42 +921,44 @@ Returns an array of users who can contribute to the specified account.
);
-twitter_api_method user_suggestions_for => (
- description => <<'',
-Access the users in a given category of the Twitter suggested user list.
-Twitter recommends caching results for no more than one hour.
-
- path => 'users/suggestions/:category',
+twitter_api_method suggestion_categories => (
+ path => 'users/suggestions',
method => 'GET',
- params => [qw/category lang/],
- required => [qw/category/],
+ params => [],
+ required => [],
returns => 'ArrayRef',
-);
-
-twitter_api_method suggestion_categories => (
- description => <<'',
+ description => <<''
Returns the list of suggested user categories. The category slug can be used in
the C<user_suggestions> API method get the users in that category . Does not
require authentication.
- path => 'users/suggestions',
+);
+
+twitter_api_method user_suggestions_for => (
+ aliases => [qw/follow_suggestions/],
+ path => 'users/suggestions/:category',
method => 'GET',
- params => [qw/lang/],
- required => [],
+ params => [qw/category lang/],
+ required => [qw/category/],
returns => 'ArrayRef',
+ description => <<''
+Access the users in a given category of the Twitter suggested user list.
+
);
twitter_api_method user_suggestions => (
- description => <<'',
-Access the users in a given category of the Twitter suggested user list and
-return their most recent status if they are not a protected user.
-
aliases => [qw/follow_suggestions/],
path => 'users/suggestions/:category/members',
method => 'GET',
params => [qw/category lang/],
required => [qw/category/],
returns => 'ArrayRef',
+ description => <<''
+Access the users in a given category of the Twitter suggested user list and
+return their most recent status if they are not a protected user. Currently
+supported values for optional parameter C<lang> are C<en>, C<fr>, C<de>, C<es>,
+C<it>. Does not require authentication.
+
);
twitter_api_method favorites => (
@@ -1221,6 +1226,7 @@ twitter_api_method get_list => (
Returns the specified list. Private lists will only be shown if the
authenticated user owns the specified list.
+ aliases => [qw/show_list/],
path => 'lists/show',
method => 'GET',
params => [qw/list_id slug owner_screen_name owner_id/],
@@ -1303,6 +1309,7 @@ twitter_api_method destroy_saved_search => (
Destroys a saved search. The search, specified by C<id>, must be owned
by the authenticating user.
+ aliases => [qw/delete_saved_search/],
path => 'saved_searches/destroy/:id',
method => 'POST',
params => [qw/id/],
@@ -1522,7 +1529,7 @@ Use the WOEID returned in the location object to query trends for a specific
location.
EOT
- path => 'trends/available',
+ path => 'trends/closest',
method => 'GET',
params => [qw/lat long/],
required => [],
@@ -1535,7 +1542,7 @@ twitter_api_method report_spam => (
description => <<'',
The user specified in the id is blocked by the authenticated user and reported as a spammer.
- path => 'report_spam',
+ path => 'users/report_spam',
method => 'POST',
params => [qw/user_id screen_name/],
required => [qw/id/],
@@ -1676,24 +1683,22 @@ retweeted by others.
aliases => [qw/retweeted_of_me/],
path => 'statuses/retweets_of_me',
method => 'GET',
- params => [qw/since_id max_id count page trim_user include_entities/],
+ params => [qw/since_id max_id count trim_user include_entities include_user_entities/],
booleans => [qw/trim_user include_entities/],
required => [],
returns => 'ArrayRef[Status]',
- deprecated => sub { croak "$_[0] not available in Twitter API V1.1" },
);
twitter_api_method no_retweet_ids => (
description => <<'',
Returns an ARRAY ref of user IDs for which the authenticating user does not
want to receive retweets.
- path => 'friendships/no_retweet_ids',
+ path => 'friendships/no_retweets/ids',
method => 'GET',
params => [],
required => [],
returns => 'ArrayRef[UserIDs]',
- deprecated => sub { croak "$_[0] not available in Twitter API V1.1" },
);
twitter_api_method end_session => (
@@ -1914,6 +1919,56 @@ response. This method is only available to users who have access to
deprecated => sub { croak "$_[0] not available in Twitter API V1.1" },
);
+twitter_api_method remove_profile_banner => (
+ description => <<'',
+Removes the uploaded profile banner for the authenticating user.
+
+ path => 'account/remove_profile_banner',
+ method => 'POST',
+ params => [qw//],
+ required => [qw//],
+ returns => 'Nothing',
+);
+
+twitter_api_method update_profile_banner => (
+ description => <<'EOT',
+Uploads a profile banner on behalf of the authenticating user. The C<image>
+parameter is an arrayref with the following interpretation:
+
+ [ $file ]
+ [ $file, $filename ]
+ [ $file, $filename, Content_Type => $mime_type ]
+ [ undef, $filename, Content_Type => $mime_type, Content => $raw_image_data ]
+
+The first value of the array (C<$file>) is the name of a file to open. The
+second value (C<$filename>) is the name given to Twitter for the file. If
+C<$filename> is not provided, the basename portion of C<$file> is used. If
+C<$mime_type> is not provided, it will be provided automatically using
+L<LWP::MediaTypes::guess_media_type()>.
+
+C<$raw_image_data> can be provided, rather than opening a file, by passing
+C<undef> as the first array value.
+EOT
+
+ path => 'account/update_profile_banner',
+ method => 'POST',
+ params => [qw/banner width height offset_left offset_top/],
+ required => [qw/banner/],
+ returns => 'Nothing',
+);
+
+twitter_api_method profile_banner => (
+ description => <<'',
+Returns a hash reference mapping available size varations to URLs that can be
+used to retrieve each variation of the banner.
+
+ path => 'users/profile_banner',
+ method => 'GET',
+ params => [qw/user_id screen_name/],
+ required => [qw//],
+ returns => 'HashRef',
+);
+
# infer screen_name or user_id from positional args for backwards compat
# and covenience
around [qw/
View
68 t/01_basic_v1_1.t
@@ -12,10 +12,22 @@ my $message_id = 1234;
my $status = 'Hello, world!';
my @tests = (
+ [ account_settings => sub { [] }, {}, GET => '/account/settings.json', __LINE__ ],
+ [ add_list_member => sub { [ { list_id => 1234, user_id => 5678 } ] }, { list_id => 1234, user_id => 5678 }, POST => '/lists/members/create.json', __LINE__ ],
+ [ add_place => sub { [ 'hacker nest', 'baadf00d', '1234', 49, -122 ] }, { name => 'hacker nest', contained_within => 'baadf00d', token => 1234, lat => 49, long => -122 }, POST => '/geo/place.json', __LINE__ ],
+ [ blocking => sub { [] }, {}, GET => '/blocks/list.json', __LINE__ ],
+ [ blocking_ids => sub { [ { cursor => -1 } ] }, { cursor => -1 }, GET => '/blocks/ids.json', __LINE__ ],
+ [ contributees => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name }, GET => '/users/contributees.json', __LINE__ ],
+ [ contributors => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name }, GET => '/users/contributors.json', __LINE__ ],
[ create_block => sub { [ $screen_name ] }, { screen_name => $screen_name }, POST => "/blocks/create.json", __LINE__ ],
[ create_favorite => sub { [ $message_id ] }, { id => $message_id }, POST => "/favorites/create.json", __LINE__ ],
[ create_favorite => sub { [ { id => $message_id } ] }, { id => $message_id }, POST => "/favorites/create.json", __LINE__ ],
[ create_friend => sub { [ $screen_name ] }, { screen_name => $screen_name }, POST => "/friendships/create.json", __LINE__ ],
+ [ create_list => sub { [ { name => 'my-list' } ] }, { name => 'my-list' }, POST => '/lists/create.json', __LINE__ ],
+ [ create_saved_search => sub { [ 'perl hacker' ] }, { query => 'perl hacker' }, POST => '/saved_searches/create.json', __LINE__ ],
+ [ delete_list => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, POST => '/lists/destroy.json', __LINE__ ],
+ [ delete_list_member => sub { [ { list_id => 1234, user_id => 678 } ] }, { list_id => 1234, user_id => 678 }, POST => '/lists/members/destroy.json', __LINE__ ],
+ [ delete_saved_search => sub { [ 1234 ] }, {}, POST => '/saved_searches/destroy/1234.json', __LINE__ ],
[ destroy_block => sub { [ $screen_name ] }, { screen_name => $screen_name }, POST => "/blocks/destroy.json", __LINE__ ],
[ destroy_direct_message => sub { [ $message_id ] }, { id => $message_id }, POST => "/direct_messages/destroy.json", __LINE__ ],
[ destroy_favorite => sub { [ $message_id ] }, { id => $message_id }, POST => "/favorites/destroy.json", __LINE__ ],
@@ -24,32 +36,86 @@ my @tests = (
[ destroy_status => sub { [ $message_id ] }, {}, POST => "/statuses/destroy/$message_id.json", __LINE__ ],
[ destroy_status => sub { [ { id => $message_id } ] }, {}, POST => "/statuses/destroy/$message_id.json", __LINE__ ],
[ direct_messages => sub { [] }, {}, GET => "/direct_messages.json", __LINE__ ],
+ [ direct_messages_sent => sub { [] }, {}, GET => '/direct_messages/sent.json', __LINE__ ],
[ disable_notifications => sub { [ $screen_name ] }, { screen_name => $screen_name, device => 'false' }, POST => "/friendships/update.json", __LINE__ ],
[ disable_notifications => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name, device => 'false' }, POST => "/friendships/update.json", __LINE__ ],
[ enable_notifications => sub { [ $screen_name ] }, { screen_name => $screen_name, device => 'true' }, POST => "/friendships/update.json", __LINE__ ],
[ enable_notifications => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name, device => 'true' }, POST => "/friendships/update.json", __LINE__ ],
[ favorites => sub { [] }, {}, GET => "/favorites/list.json", __LINE__ ],
[ followers => sub { [] }, {}, GET => "/followers/list.json", __LINE__ ],
+ [ followers_ids => sub { [ { screen_name => $screen_name, cursor => -1 } ] }, { screen_name => $screen_name, cursor => -1 }, GET => '/followers/ids.json', __LINE__ ],
[ friends => sub { [] }, {}, GET => "/friends/list.json", __LINE__ ],
+ [ friends_ids => sub { [ { screen_name => $screen_name, cursor => -1 } ] }, { screen_name => $screen_name, cursor => -1 }, GET => '/friends/ids.json', __LINE__ ],
[ friendship_exists => sub { [ 'a', 'b' ] }, { source_screen_name => 'a', target_screen_name => 'b' }, GET => "/friendships/show.json", __LINE__, '{"relationship":{"target":{"followed_by":true}}}' ],
- [ mentions => sub { [] }, {}, GET => "/statuses/mentions.json", __LINE__ ],
+ [ friendships_incoming => sub { [] }, {}, GET => '/friendships/incoming.json', __LINE__ ],
+ [ friendships_outgoing => sub { [] }, {}, GET => '/friendships/outgoing.json', __LINE__ ],
+ [ geo_id => sub { [ 'df51dec6f4ee2b2c' ] }, {}, GET => '/geo/id/df51dec6f4ee2b2c.json', __LINE__ ],
+ [ geo_search => sub { [ { query => 'spokane' } ] }, { query => 'spokane' }, GET => '/geo/search.json', __LINE__ ],
+ [ get_configuration => sub { [] }, {}, GET => '/help/configuration.json', __LINE__ ],
+ [ get_languages => sub { [] }, {}, GET => '/help/languages.json', __LINE__ ],
+ [ get_lists => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name }, GET => '/lists/list.json', __LINE__ ],
+ [ get_lists => sub { [] }, {}, GET => '/lists/list.json', __LINE__ ],
+ [ get_privacy_policy => sub { [] }, {}, GET => '/help/privacy.json', __LINE__ ],
+ [ get_tos => sub { [] }, {}, GET => '/help/tos.json', __LINE__ ],
+ [ home_timeline => sub { [] }, {}, GET => '/statuses/home_timeline.json', __LINE__ ],
+ [ list_members => sub { [ { list_id => 12334 } ] }, { list_id => 12334 }, GET => '/lists/members.json', __LINE__ ],
+ [ list_memberships => sub { [ { user_id => 1234 } ] }, { user_id => 1234 }, GET => '/lists/memberships.json', __LINE__ ],
+ [ list_statuses => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, GET => '/lists/statuses.json', __LINE__ ],
+ [ list_subscribers => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, GET => '/lists/subscribers.json', __LINE__ ],
+ [ lookup_friendships => sub { [ { user_id => [ 1234, 5678 ] } ] }, { user_id => '1234,5678' }, GET => '/friendships/lookup.json', __LINE__ ],
+ [ lookup_users => sub { [ { screen_name => [qw/foo bar baz/] } ] }, { screen_name => 'foo,bar,baz' }, GET => '/users/lookup.json', __LINE__ ],
+ [ members_create_all => sub { [ { list_id => 1234, screen_name => [qw/a b c/] } ] }, { list_id => 1234, screen_name => 'a,b,c' }, POST => '/lists/members/create_all.json', __LINE__ ],
+ [ members_destroy_all => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, POST => '/lists/members/destroy_all.json', __LINE__ ],
+ [ mentions => sub { [] }, {}, GET => "/statuses/mentions_timeline.json", __LINE__ ],
[ new_direct_message => sub { [ $screen_name, $status ] }, { screen_name => $screen_name, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
[ new_direct_message => sub { [ $screen_name, { text => $status } ] }, { screen_name => $screen_name, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
[ new_direct_message => sub { [ 1234, $status ] }, { user_id => 1234, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
[ new_direct_message => sub { [ { screen_name => $screen_name, text => $status } ] }, { screen_name => $screen_name, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
[ new_direct_message => sub { [ { user => $screen_name, text => $status } ] }, { screen_name => $screen_name, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
[ new_direct_message => sub { [ { user_id => 1234, text => $status } ] }, { user_id => 1234, text => $status }, POST => "/direct_messages/new.json", __LINE__ ],
+ [ no_retweet_ids => sub { [] }, {}, GET => '/friendships/no_retweets/ids.json' ],
+ [ oembed => sub { [ { id => 99530515043983360 } ] }, { id => 99530515043983360 }, GET => '/statuses/oembed.json', __LINE__ ],
+ [ profile_banner => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name }, GET => '/users/profile_banner.json', __LINE__ ],
[ rate_limit_status => sub { [ { resources => [qw/help statuses/] } ] }, { resources => 'help,statuses' }, GET => "/application/rate_limit_status.json", __LINE__ ],
[ rate_limit_status => sub { [] }, {}, GET => "/application/rate_limit_status.json", __LINE__ ],
+ [ remove_profile_banner => sub { [] }, {}, POST => '/account/remove_profile_banner.json' ],
+ [ report_spam => sub { [ { screen_name => 'spammer' } ] }, { screen_name => 'spammer' }, POST => '/users/report_spam.json', __LINE__ ],
+ [ retweet => sub { [ 44556 ] }, {}, POST => '/statuses/retweet/44556.json', __LINE__ ],
+ [ retweets => sub { [ 44444 ] }, {}, GET => '/statuses/retweets/44444.json', __LINE__ ],
+ [ retweets_of_me => sub { [] }, {}, GET => '/statuses/retweets_of_me.json', __LINE__ ],
+ [ reverse_geocode => sub { [ 37, -122 ] }, { lat => 37, long => -122 }, GET => '/geo/reverse_geocode.json', __LINE__ ],
+ [ saved_searches => sub { [] }, {}, GET => '/saved_searches/list.json', __LINE__ ],
+ [ search => sub { [ 'perl hacker' ] }, { q => 'perl hacker' }, GET => '/search/tweets.json', __LINE__ ],
+ [ search_users => sub { [ 'perl hacker' ] }, { q => 'perl hacker' }, GET => '/users/search.json', __LINE__],
[ sent_direct_messages => sub { [] }, {}, GET => "/direct_messages/sent.json", __LINE__ ],
+ [ show_direct_message => sub { [ 1234 ] }, { id => 1234 }, GET => '/direct_messages/show.json', __LINE__ ],
+ [ show_list => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, GET => '/lists/show.json', __LINE__ ],
+ [ show_list_member => sub { [ { list_id => 1234, screen_name => $screen_name } ] }, { list_id => 1234, screen_name => $screen_name }, GET => '/lists/members/show.json', __LINE__ ],
+ [ show_list_subscriber => sub { [ { list_id => 1234, user_id => 666 } ] }, { list_id => 1234, user_id => 666 }, GET => '/lists/subscribers/show.json', __LINE__ ],
+ [ show_saved_search => sub { [ 1234 ] }, {}, GET => '/saved_searches/show/1234.json', __LINE__ ],
[ show_status => sub { [ 12345678 ] }, {}, GET => "/statuses/show/12345678.json", __LINE__ ],
[ show_user => sub { [ $screen_name ] }, { screen_name => $screen_name }, GET => "/users/show.json", __LINE__ ],
+ [ similar_places => sub { [ { name => 'spokane' } ] }, { name => 'spokane' }, GET => '/geo/similar_places.json', __LINE__ ],
+ [ subscribe_list => sub { [ { owner_screen_name => $screen_name, slug => 'some-list' }, ] }, { owner_screen_name => $screen_name, slug => 'some-list' }, POST => '/lists/subscribers/create.json', __LINE__ ],
+ [ subscriptions => sub { [ { screen_name => $screen_name } ] }, { screen_name => $screen_name }, GET => '/lists/subscriptions.json', __LINE__ ],
+ [ suggestion_categories => sub { [ { lang => 'en' } ] }, { lang => 'en' }, GET => '/users/suggestions.json', __LINE__ ],
+ [ trends_available => sub { [] }, {}, GET => '/trends/available.json', __LINE__ ],
+ [ trends_closest => sub { [ { lat => 37, long => -122 } ] }, { lat => 37, long => -122 }, GET => '/trends/closest.json', __LINE__ ],
+ [ trends_place => sub { [ 1234 ] }, { id => 1234 }, GET => '/trends/place.json', __LINE__ ],
+ [ unsubscribe_list => sub { [ { list_id => 1234 } ] }, { list_id => 1234 }, POST => '/lists/subscribers/destroy.json', __LINE__ ],
[ update => sub { [ $status ] }, { status => $status, source => 'twitterpm' }, POST => "/statuses/update.json", __LINE__ ],
+ [ update_account_settings => sub { [ { lang => 'en' } ] }, { lang => 'en' }, POST => '/account/settings.json', __LINE__ ],
[ update_delivery_device => sub { [ 'sms' ] }, { device => 'sms' }, POST => "/account/update_delivery_device.json", __LINE__ ],
+ [ update_friendship => sub { [ { screen_name => $screen_name, retweets => 0 } ] }, { screen_name => $screen_name, retweets => 'false' }, POST => '/friendships/update.json', __LINE__ ],
+ [ update_list => sub { [ { list_id => 1234, mode => 'private' } ] }, { list_id => 1234, mode => 'private' }, POST => '/lists/update.json', __LINE__ ],
[ update_profile => sub { [ { name => 'Barney' } ] }, { name => 'Barney' }, POST => "/account/update_profile.json", __LINE__ ],
[ update_profile_background_image => sub { [ { image => 'binary' } ] }, { image => 'binary' }, POST => "/account/update_profile_background_image.json", __LINE__ ],
+ [ update_profile_banner => sub { [ { banner => 'binary data here' } ] }, { banner => 'binary data here' }, POST => "/account/update_profile_banner.json", __LINE__ ],
[ update_profile_colors => sub { [ { profile_background_color => '#0000' } ] }, { profile_background_color => '#0000' }, POST => "/account/update_profile_colors.json", __LINE__ ],
[ update_profile_image => sub { [ { image => 'binary data here' } ] }, { image => 'binary data here' }, POST => "/account/update_profile_image.json", __LINE__ ],
+ [ update_with_media => sub { [ $status, [ undef ] ] }, {' name' => "\"media[]\"\cM\cJ\cM\cJ\cM\cJ--xYzZY--\cM\cJ", "--xYzZY\cM\cJContent-Disposition: form-data" => ''}, POST => '/statuses/update_with_media.json', __LINE__ ], # TODO: test body args for file upload
+ [ user_suggestions => sub { [ 'slug', { lang => 'en' } ] }, { lang => 'en' }, GET => '/users/suggestions/slug/members.json', __LINE__ ],
+ [ user_suggestions_for => sub { [ 'slug', { lang => 'en' } ] }, { lang => 'en' }, GET => '/users/suggestions/slug.json', __LINE__ ],
[ user_timeline => sub { [] }, {}, GET => "/statuses/user_timeline.json", __LINE__ ],
[ verify_credentials => sub { [] }, {}, GET => "/account/verify_credentials.json", __LINE__ ],
);

0 comments on commit 3381a5e

Please sign in to comment.
Something went wrong with that request. Please try again.