Skip to content

replies #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/t/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,21 @@ def mentions(query)
end
print_tweets(tweets)
end
map %w(replies) => :mentions

desc 'replies STATUS_ID', 'Returns replies to the given tweet.'
method_option 'csv', aliases: '-c', type: :boolean, desc: 'Output in CSV format.'
method_option 'decode_uris', aliases: '-d', type: :boolean, desc: 'Decodes t.co URLs into their original form.'
method_option 'long', aliases: '-l', type: :boolean, desc: 'Output in long format.'
method_option 'relative_dates', aliases: '-a', type: :boolean, desc: 'Show relative dates.'
def replies(status_id)
opts = {count: MAX_NUM_RESULTS}
opts[:include_entities] = !!options['decode_uris']
tweets = client.mentions(opts)
tweets = tweets.select do |tweet|
tweet.in_reply_to_status_id.to_i == status_id.to_i
end
print_tweets(tweets)
end

desc 'retweets [USER] QUERY', "Returns Tweets you've retweeted that match the specified query."
method_option 'csv', aliases: '-c', type: :boolean, desc: 'Output in CSV format.'
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/statuses_with_mention.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"created_at":"Thu Nov 01 01:23:39 +0000 2012","id":263813522369159169,"id_str":"263813522369159169","text":"@sferik Excellent","source":"<a href=\"http://tapbots.com/tweetbot\" rel=\"nofollow\">Tweetbot for iOS</a>","truncated":false,"in_reply_to_status_id":263810294395072513,"in_reply_to_status_id_str":"263810294395072513","in_reply_to_user_id":7505382,"in_reply_to_user_id_str":"7505382","in_reply_to_screen_name":"sferik","user":{"id":19110970,"id_str":"19110970","name":"Josh French","screen_name":"joshfrench","location":"San Francisco","description":"B, B+ tops","url":"http://joshfrench.tumblr.com","entities":{"url":{"urls":[{"url":"http://joshfrench.tumblr.com","expanded_url":null,"indices":[0,28]}]},"description":{"urls":[]}},"protected":false,"followers_count":464,"friends_count":375,"listed_count":27,"created_at":"Sat Jan 17 14:14:16 +0000 2009","favourites_count":540,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":4678,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_image_url":"http://a0.twimg.com/profile_images/2163716426/medium_normal.jpg","profile_image_url_https":"https://si0.twimg.com/profile_images/2163716426/medium_normal.jpg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":true,"default_profile_image":false,"following":true,"follow_request_sent":false,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"sferik","name":"Erik Michaels-Ober","id":7505382,"id_str":"7505382","indices":[0,7]}]},"favorited":false,"retweeted":false}]
14 changes: 14 additions & 0 deletions spec/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,20 @@
end
end

describe '#replies' do
before do
stub_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '200', include_entities: 'false'}).to_return(body: fixture('statuses_with_mention.json'), headers: {content_type: 'application/json; charset=utf-8'})
end
it 'has the correct output' do
@search.replies(263_810_294_395_072_513)
expect($stdout.string).to eq <<-eos
@joshfrench
@sferik Excellent

eos
end
end

describe '#list' do
before do
stub_get('/1.1/lists/statuses.json').with(query: {count: '200', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'false'}).to_return(body: fixture('statuses.json'), headers: {content_type: 'application/json; charset=utf-8'})
Expand Down