Skip to content

Commit

Permalink
Allow use of Twitter::Tweet instead of in_reply_to_status_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 28, 2013
1 parent dd994e2 commit 6b7d6c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/twitter/rest/api/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def destroy_status(*args)
# @return [Twitter::Tweet] The created Tweet.
# @param status [String] The text of your status update, up to 140 characters.
# @param options [Hash] A customizable set of options.
# @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to.
# @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
Expand All @@ -119,6 +120,7 @@ def destroy_status(*args)
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
def update(status, options={})
hash = options.dup
hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
hash[:place_id] = hash.delete(:place).id unless hash[:place].nil?
object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", hash.merge(:status => status))
rescue Twitter::Error::Forbidden => error
Expand Down Expand Up @@ -188,6 +190,7 @@ def retweet!(*args)
# @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :possibly_sensitive Set to true for content which may not be suitable for every audience.
# @option options [Twitter::Tweet] :in_reply_to_status An existing status that the update is in reply to.
# @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
# @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
# @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
Expand All @@ -197,6 +200,7 @@ def retweet!(*args)
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
def update_with_media(status, media, options={})
hash = options.dup
hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
hash[:place_id] = hash.delete(:place).id unless hash[:place].nil?
object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", hash.merge('media[]' => media, 'status' => status))
rescue Twitter::Error::Forbidden => error
Expand Down
19 changes: 19 additions & 0 deletions spec/twitter/rest/api/tweets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@
expect{@client.update("The problem with your code is that it's doing exactly what you told it to do.")}.to raise_error Twitter::Error::AlreadyPosted
end
end
context "with an in-reply-to status" do
before do
@tweet = Twitter::Tweet.new(:id => 1)
stub_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status_id => "1"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.update("The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status => @tweet)
expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status_id => "1"})).to have_been_made
end
end
context "with an in-reply-to status ID" do
before do
stub_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status_id => "1"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.update("The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status_id => 1)
expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do.", :in_reply_to_status_id => "1"})).to have_been_made
end
end
end

describe "#retweet" do
Expand Down

0 comments on commit 6b7d6c2

Please sign in to comment.