Skip to content

Commit

Permalink
Allow multiple arguments (and return an array) for the following methods
Browse files Browse the repository at this point in the history
* Twitter::Client#accept
* Twitter::Client#block
* Twitter::Client#deny
* Twitter::Client#direct_message
* Twitter::Client#direct_message_destroy
* Twitter::Client#disable_notifications
* Twitter::Client#enable_notifications
* Twitter::Client#favorite
* Twitter::Client#follow
* Twitter::Client#oembed
* Twitter::Client#report_spam
* Twitter::Client#retweet
* Twitter::Client#saved_search
* Twitter::Client#saved_search_destroy
* Twitter::Client#status
* Twitter::Client#status_activity
* Twitter::Client#status_destroy
* Twitter::Client#status_with_activity
* Twitter::Client#unblock
* Twitter::Client#unfavorite
* Twitter::Client#unfollow
  • Loading branch information
sferik committed Jun 5, 2012
1 parent 9c29181 commit 78adf38
Show file tree
Hide file tree
Showing 12 changed files with 605 additions and 478 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,34 @@ wiki][apps]!

The Active Support dependency has been removed!

The `Twitter::Client#follow` and `Twitter::Client#unfollow` methods now accept
multiple users as arguments and return an array instead of a `Twitter::User`.
The following methods now accept multiple users or ids as arguments and return
arrays:

* `Twitter::Client#accept`
* `Twitter::Client#block`
* `Twitter::Client#deny`
* `Twitter::Client#direct_message`
* `Twitter::Client#direct_message_destroy`
* `Twitter::Client#disable_notifications`
* `Twitter::Client#enable_notifications`
* `Twitter::Client#favorite`
* `Twitter::Client#follow`
* `Twitter::Client#oembed`
* `Twitter::Client#report_spam`
* `Twitter::Client#retweet`
* `Twitter::Client#saved_search`
* `Twitter::Client#saved_search_destroy`
* `Twitter::Client#status`
* `Twitter::Client#status_activity`
* `Twitter::Client#status_destroy`
* `Twitter::Client#status_with_activity`
* `Twitter::Client#unblock`
* `Twitter::Client#unfavorite`
* `Twitter::Client#unfollow`

Additionally, the `Twitter::Client#follow` method now checks to make sure the
user isn't already being followed. If you don't wish to perform that check
(which requires an extra HTTP request), you can use the new
(which does require an extra HTTP request), you can use the new
`Twitter::Client#follow!` method instead. **Note**: This may re-send an email
notification to the user, even if they are already being followed.

Expand Down
910 changes: 497 additions & 413 deletions lib/twitter/client.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/twitter/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def metadata
# @return [Twitter::OEmbed]
def oembed(options={})
@client ||= Twitter::Client.new
@client.oembed(@attrs['id'], options) unless @attrs['id'].nil?
@client.oembed(@attrs['id'], options).first unless @attrs['id'].nil?
end

# @return [Twitter::Place]
Expand Down
14 changes: 8 additions & 6 deletions spec/twitter/client/block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@
should have_been_made
end
it "should return the blocked user" do
user = @client.block("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.block("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand All @@ -97,9 +98,10 @@
should have_been_made
end
it "should return the un-blocked user" do
user = @client.unblock("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.unblock("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand Down
12 changes: 7 additions & 5 deletions spec/twitter/client/direct_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
should have_been_made
end
it "should return the deleted message" do
direct_message = @client.direct_message_destroy(1825785544)
direct_message.should be_a Twitter::DirectMessage
direct_message.text.should == "Creating a fixture for the Twitter gem"
direct_messages = @client.direct_message_destroy(1825785544)
direct_messages.should be_an Array
direct_messages.first.should be_a Twitter::DirectMessage
direct_messages.first.sender.name.should == "Erik Michaels-Ober"
end
end

Expand Down Expand Up @@ -90,8 +91,9 @@
end
it "should return the 20 most recent direct messages sent to the authenticating user" do
direct_messages = @client.direct_message(1825786345)
direct_messages.should be_a Twitter::DirectMessage
direct_messages.sender.name.should == "Erik Michaels-Ober"
direct_messages.should be_an Array
direct_messages.first.should be_a Twitter::DirectMessage
direct_messages.first.sender.name.should == "Erik Michaels-Ober"
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec/twitter/client/favorites_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
should have_been_made
end
it "should return the favorite status when successful" do
status = @client.favorite(25938088801)
status.should be_a Twitter::Status
status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
statuses = @client.favorite(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
end
end

Expand All @@ -71,9 +72,10 @@
should have_been_made
end
it "should return the un-favorite status when successful" do
status = @client.unfavorite(25938088801)
status.should be_a Twitter::Status
status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
statuses = @client.unfavorite(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec/twitter/client/friends_and_followers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,10 @@
should have_been_made
end
it "should return the accepted user" do
user = @client.accept("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.accept("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand All @@ -648,9 +649,10 @@
should have_been_made
end
it "should return the denied user" do
user = @client.deny("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.deny("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec/twitter/client/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
should have_been_made
end
it "should return the specified user when successful" do
user = @client.enable_notifications("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.enable_notifications("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand All @@ -38,9 +39,10 @@
should have_been_made
end
it "should return the specified user when successful" do
user = @client.disable_notifications("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.disable_notifications("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand Down
14 changes: 8 additions & 6 deletions spec/twitter/client/saved_searches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
should have_been_made
end
it "should return the data for a saved search owned by the authenticating user specified by the given id" do
saved_search = @client.saved_search(16129012)
saved_search.should be_a Twitter::SavedSearch
saved_search.name.should == "twitter"
saved_searches = @client.saved_search(16129012)
saved_searches.should be_an Array
saved_searches.first.should be_a Twitter::SavedSearch
saved_searches.first.name.should == "twitter"
end
end

Expand Down Expand Up @@ -71,9 +72,10 @@
should have_been_made
end
it "should return the deleted saved search" do
saved_search = @client.saved_search_destroy(16129012)
saved_search.should be_a Twitter::SavedSearch
saved_search.name.should == "twitter"
saved_searches = @client.saved_search_destroy(16129012)
saved_searches.should be_an Array
saved_searches.first.should be_a Twitter::SavedSearch
saved_searches.first.name.should == "twitter"
end
end

Expand Down
7 changes: 4 additions & 3 deletions spec/twitter/client/spam_reporting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
should have_been_made
end
it "should return the specified user" do
user = @client.report_spam("sferik")
user.should be_a Twitter::User
user.name.should == "Erik Michaels-Ober"
users = @client.report_spam("sferik")
users.should be_an Array
users.first.should be_a Twitter::User
users.first.name.should == "Erik Michaels-Ober"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/twitter/client/suggested_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
end
it "should return users in a given category of the Twitter suggested user list and return their most recent status if they are not a protected user" do
suggest_users = @client.suggest_users("art-design")
suggest_users.should be_a Array
suggest_users.should be_an Array
suggest_users.first.should be_a Twitter::User
suggest_users.first.name.should == "OMGFacts"
end
Expand Down
51 changes: 29 additions & 22 deletions spec/twitter/client/tweets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@
should have_been_made
end
it "should return a single status" do
status = @client.status(25938088801)
status.should be_a Twitter::Status
status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
statuses = @client.status(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
end
end

Expand All @@ -88,9 +89,10 @@
should have_been_made
end
it "should return a single status" do
status = @client.status_activity(25938088801)
status.should be_a Twitter::Status
status.retweeters_count.should == "1"
statuses = @client.status_activity(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.retweeters_count.should == "1"
end
end

Expand All @@ -109,10 +111,11 @@
should have_been_made
end
it "should return a single status" do
status = @client.status_with_activity(25938088801)
status.should be_a Twitter::Status
status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
status.retweeters_count.should == "1"
statuses = @client.status_with_activity(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
statuses.first.retweeters_count.should == "1"
end
end

Expand All @@ -127,9 +130,10 @@
should have_been_made
end
it "should return a single status" do
status = @client.status_destroy(25938088801)
status.should be_a Twitter::Status
status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
statuses = @client.status_destroy(25938088801)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
end
end

Expand All @@ -144,11 +148,12 @@
should have_been_made
end
it "should return the original Tweet with retweet details embedded" do
status = @client.retweet(28561922516)
status.should be_a Twitter::Status
status.text.should == "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
status.retweeted_status.text.should == "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
status.retweeted_status.id.should_not == status.id
statuses = @client.retweet(28561922516)
statuses.should be_an Array
statuses.first.should be_a Twitter::Status
statuses.first.text.should == "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
statuses.first.retweeted_status.text.should == "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
statuses.first.retweeted_status.id.should_not == statuses.first.id
end
end

Expand Down Expand Up @@ -203,8 +208,9 @@
should have_been_made
end
it "should return an OEmbed instance" do
oembed = @client.oembed(25938088801)
oembed.should be_a Twitter::OEmbed
oembeds = @client.oembed(25938088801)
oembeds.should be_an Array
oembeds.first.should be_a Twitter::OEmbed
end
end
context "with url passed" do
Expand All @@ -218,8 +224,9 @@
should have_been_made
end
it "should return an OEmbed instance" do
oembed = @client.oembed('https://twitter.com/#!/twitter/status/25938088801')
oembed.should be_a Twitter::OEmbed
oembeds = @client.oembed('https://twitter.com/#!/twitter/status/25938088801')
oembeds.should be_an Array
oembeds.first.should be_a Twitter::OEmbed
end
end

Expand Down

0 comments on commit 78adf38

Please sign in to comment.