Skip to content

Commit

Permalink
Handle new API v1.1 list response format
Browse files Browse the repository at this point in the history
Closes #70.
  • Loading branch information
sferik committed Oct 8, 2012
1 parent 9d60b66 commit 2c187ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 140 deletions.
8 changes: 4 additions & 4 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,16 @@ def leaders(user=nil)
method_option "sort", :aliases => "-s", :type => :string, :enum => %w(members mode posted slug subscribers), :default => "slug", :desc => "Specify the order of the results.", :banner => "ORDER"
method_option "unsorted", :aliases => "-u", :type => :boolean, :default => false, :desc => "Output is not sorted."
def lists(user=nil)
if user
lists = if user
require 't/core_ext/string'
user = if options['id']
user.to_i
else
user.strip_ats
end
end
lists = collect_with_cursor do |cursor|
client.lists(user, :cursor => cursor)
client.lists(user)
else
client.lists
end
print_lists(lists)
end
Expand Down
36 changes: 18 additions & 18 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1942,18 +1942,16 @@
describe "#lists" do
before do
stub_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@cli.lists
a_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1"}).
should have_been_made
end
it "should have the correct output" do
@cli.lists
$stdout.string.chomp.should == "@sferik/code-for-america @sferik/presidents"
$stdout.string.chomp.should == "@pengwynn/rubyists @twitter/team @sferik/test"
end
context "--csv" do
before do
Expand All @@ -1963,8 +1961,9 @@
@cli.lists
$stdout.string.should == <<-eos
ID,Created at,Screen name,Slug,Members,Subscribers,Mode,Description
21718825,2010-09-14 21:46:56 +0000,sferik,code-for-america,26,5,public,Code for America
8863586,2010-03-15 12:10:13 +0000,sferik,presidents,2,1,public,Presidents of the United States of America
1129440,2009-10-30 14:39:25 +0000,pengwynn,rubyists,499,39,public,""
574,2009-09-23 01:18:01 +0000,twitter,team,1199,78078,public,""
73546689,2012-07-08 22:19:05 +0000,sferik,test,2,0,private,""
eos
end
end
Expand All @@ -1975,9 +1974,10 @@
it "should output in long format" do
@cli.lists
$stdout.string.should == <<-eos
ID Created at Screen name Slug Members Subscribers ...
21718825 Sep 14 2010 @sferik code-for-america 26 5 ...
8863586 Mar 15 2010 @sferik presidents 2 1 ...
ID Created at Screen name Slug Members Subscribers Mode ...
1129440 Oct 30 2009 @pengwynn rubyists 499 39 public
574 Sep 22 2009 @twitter team 1199 78078 public
73546689 Jul 8 14:19 @sferik test 2 0 private
eos
end
end
Expand All @@ -1987,7 +1987,7 @@
end
it "should reverse the order of the sort" do
@cli.lists
$stdout.string.chomp.should == "@sferik/presidents @sferik/code-for-america"
$stdout.string.chomp.should == "@sferik/test @twitter/team @pengwynn/rubyists"
end
end
context "--sort=members" do
Expand All @@ -1996,7 +1996,7 @@
end
it "should sort by the time when Twitter acount was created" do
@cli.lists
$stdout.string.chomp.should == "@sferik/presidents @sferik/code-for-america"
$stdout.string.chomp.should == "@sferik/test @pengwynn/rubyists @twitter/team"
end
end
context "--sort=mode" do
Expand All @@ -2005,7 +2005,7 @@
end
it "should sort by the time when Twitter acount was created" do
@cli.lists
$stdout.string.chomp.should == "@sferik/code-for-america @sferik/presidents"
$stdout.string.chomp.should == "@sferik/test @twitter/team @pengwynn/rubyists"
end
end
context "--sort=posted" do
Expand All @@ -2014,7 +2014,7 @@
end
it "should sort by the time when Twitter acount was created" do
@cli.lists
$stdout.string.chomp.should == "@sferik/presidents @sferik/code-for-america"
$stdout.string.chomp.should == "@twitter/team @pengwynn/rubyists @sferik/test"
end
end
context "--sort=subscribers" do
Expand All @@ -2023,7 +2023,7 @@
end
it "should sort by the time when Twitter acount was created" do
@cli.lists
$stdout.string.chomp.should == "@sferik/presidents @sferik/code-for-america"
$stdout.string.chomp.should == "@sferik/test @pengwynn/rubyists @twitter/team"
end
end
context "--unsorted" do
Expand All @@ -2032,32 +2032,32 @@
end
it "should not be sorted" do
@cli.lists
$stdout.string.chomp.should == "@sferik/code-for-america @sferik/presidents"
$stdout.string.chomp.should == "@pengwynn/rubyists @twitter/team @sferik/test"
end
end
context "with a user passed" do
before do
stub_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@cli.lists("sferik")
a_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1", :screen_name => "sferik"}).
with(:query => {:screen_name => "sferik"}).
should have_been_made
end
context "--id" do
before do
@cli.options = @cli.options.merge("id" => true)
stub_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1", :user_id => "7505382"}).
with(:query => {:user_id => "7505382"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@cli.lists("7505382")
a_get("/1.1/lists/list.json").
with(:query => {:cursor => "-1", :user_id => "7505382"}).
with(:query => {:user_id => "7505382"}).
should have_been_made
end
end
Expand Down
117 changes: 1 addition & 116 deletions spec/fixtures/lists.json
Original file line number Diff line number Diff line change
@@ -1,116 +1 @@
{
"lists": [
{
"slug": "code-for-america",
"name": "code for america",
"full_name": "@sferik/code-for-america",
"description": "Code for America",
"mode": "public",
"uri": "/sferik/code-for-america",
"user": {
"id": 7505382,
"profile_image_url": "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png",
"url": "https://github.com/sferik",
"created_at": "Mon Jul 16 12:59:01 +0000 2007",
"followers_count": 2126,
"default_profile": false,
"profile_background_color": "000000",
"lang": "en",
"utc_offset": -28800,
"name": "Erik Michaels-Ober",
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/162641967/we_concept_bg2.png",
"location": "San Francisco",
"profile_link_color": "0084B4",
"listed_count": 115,
"verified": false,
"protected": false,
"profile_use_background_image": true,
"is_translator": false,
"following": false,
"description": "My heart is in the work.",
"profile_text_color": "333333",
"statuses_count": 6953,
"screen_name": "sferik",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1759857427/image1326743606_normal.png",
"time_zone": "Pacific Time (US & Canada)",
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/162641967/we_concept_bg2.png",
"friends_count": 204,
"default_profile_image": false,
"contributors_enabled": false,
"profile_sidebar_border_color": "C0DEED",
"id_str": "7505382",
"geo_enabled": true,
"favourites_count": 3128,
"profile_background_tile": false,
"notifications": false,
"show_all_inline_media": true,
"profile_sidebar_fill_color": "DDEEF6",
"follow_request_sent": false
},
"member_count": 26,
"id_str": "21718825",
"created_at": "Tue Sep 14 21:46:56 +0000 2010",
"subscriber_count": 5,
"following": false,
"id": 21718825
},
{
"slug": "presidents",
"name": "presidents",
"full_name": "@sferik/presidents",
"description": "Presidents of the United States of America",
"mode": "public",
"uri": "/sferik/presidents",
"user": {
"id": 7505382,
"profile_image_url": "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png",
"url": "https://github.com/sferik",
"created_at": "Mon Jul 16 12:59:01 +0000 2007",
"followers_count": 2126,
"default_profile": false,
"profile_background_color": "000000",
"lang": "en",
"utc_offset": -28800,
"name": "Erik Michaels-Ober",
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/162641967/we_concept_bg2.png",
"location": "San Francisco",
"profile_link_color": "0084B4",
"listed_count": 115,
"verified": false,
"protected": false,
"profile_use_background_image": true,
"is_translator": false,
"following": false,
"description": "My heart is in the work.",
"profile_text_color": "333333",
"statuses_count": 6953,
"screen_name": "sferik",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1759857427/image1326743606_normal.png",
"time_zone": "Pacific Time (US & Canada)",
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/162641967/we_concept_bg2.png",
"friends_count": 204,
"default_profile_image": false,
"contributors_enabled": false,
"profile_sidebar_border_color": "C0DEED",
"id_str": "7505382",
"geo_enabled": true,
"favourites_count": 3128,
"profile_background_tile": false,
"notifications": false,
"show_all_inline_media": true,
"profile_sidebar_fill_color": "DDEEF6",
"follow_request_sent": false
},
"member_count": 2,
"id_str": "8863586",
"created_at": "Mon Mar 15 12:10:13 +0000 2010",
"subscriber_count": 1,
"following": false,
"id": 8863586
}
],
"next_cursor": 0,
"previous_cursor": 0,
"next_cursor_str": "0",
"previous_cursor_str": "0"
}
[{"uri":"\/pengwynn\/rubyists","name":"Rubyists","full_name":"@pengwynn\/rubyists","description":"","mode":"public","user":{"id":14100886,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","time_zone":"Central Time (US & Canada)","location":"Denton, TX","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","id_str":"14100886","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2221455972\/wynn-mic-bw_normal.jpg","utc_offset":-21600,"profile_use_background_image":false,"statuses_count":7384,"name":"Wynn Netherland","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"pengwynn","listed_count":397,"protected":false,"is_translator":false,"followers_count":6182,"profile_sidebar_border_color":"FFFFFF","description":"Christian, husband, father, GitHubber, Co-host of @thechangelog, Co-author of Sass, Compass, #CSS book http:\/\/wynn.fm\/sass-meap","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2221455972\/wynn-mic-bw_normal.jpg","profile_background_tile":false,"following":true,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"http:\/\/wynnnetherland.com","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/14100886\/1347987369","favourites_count":338,"created_at":"Sat Mar 08 16:34:22 +0000 2008","friends_count":3528,"verified":false,"notifications":false,"profile_background_color":"292929","contributors_enabled":false},"following":true,"created_at":"Fri Oct 30 14:39:25 +0000 2009","member_count":499,"id_str":"1129440","subscriber_count":39,"slug":"rubyists","id":1129440},{"uri":"\/twitter\/team","name":"Team","full_name":"@twitter\/team","description":"","mode":"public","user":{"id":783214,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/657090062\/l1uqey5sy82r9ijhke1i.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco, CA","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/657090062\/l1uqey5sy82r9ijhke1i.png","id_str":"783214","profile_link_color":"038543","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2284174758\/v65oai7fxn47qv9nectx_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":1433,"name":"Twitter","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"twitter","listed_count":73287,"protected":false,"followers_count":13711595,"profile_sidebar_border_color":"EEEEEE","is_translator":false,"description":"Always wondering what's happening. ","profile_background_tile":true,"following":true,"profile_sidebar_fill_color":"F6F6F6","default_profile_image":false,"url":"http:\/\/blog.twitter.com\/","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/783214\/1347405327","favourites_count":18,"created_at":"Tue Feb 20 14:35:54 +0000 2007","friends_count":1249,"verified":true,"notifications":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2284174758\/v65oai7fxn47qv9nectx_normal.png","profile_background_color":"ACDED6","contributors_enabled":true},"following":true,"created_at":"Wed Sep 23 01:18:01 +0000 2009","member_count":1199,"id_str":"574","subscriber_count":78078,"slug":"team","id":574},{"uri":"\/sferik\/test","name":"test","full_name":"@sferik\/test","description":"","mode":"private","user":{"id":7505382,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","id_str":"7505382","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":8576,"name":"Erik Michaels-Ober","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"sferik","listed_count":129,"protected":false,"followers_count":2449,"profile_sidebar_border_color":"000000","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","description":"An ingredient in your recipe.","is_translator":false,"profile_background_tile":false,"following":false,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"https:\/\/github.com\/sferik","favourites_count":4321,"created_at":"Mon Jul 16 12:59:01 +0000 2007","friends_count":203,"verified":false,"notifications":false,"profile_background_color":"000000","contributors_enabled":false},"following":false,"created_at":"Sun Jul 08 22:19:05 +0000 2012","member_count":2,"id_str":"73546689","subscriber_count":0,"slug":"test","id":73546689}]
4 changes: 2 additions & 2 deletions t.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |gem|
gem.add_dependency 'oauth', '~> 0.4'
gem.add_dependency 'retryable', '~> 1.2'
gem.add_dependency 'thor', ['>= 0.16', '< 2']
gem.add_dependency 'tweetstream', '~> 2.2'
gem.add_dependency 'twitter', '~> 4.0'
gem.add_dependency 'tweetstream', '~> 2.3'
gem.add_dependency 'twitter', '~> 4.1'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
Expand Down

0 comments on commit 2c187ea

Please sign in to comment.