From 6b7d6c2b637a074c348a56a51fb1e02252482fb2 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Thu, 28 Nov 2013 13:47:31 +0100 Subject: [PATCH] Allow use of Twitter::Tweet instead of in_reply_to_status_id --- lib/twitter/rest/api/tweets.rb | 4 ++++ spec/twitter/rest/api/tweets_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/twitter/rest/api/tweets.rb b/lib/twitter/rest/api/tweets.rb index bda6bff02..7745d42e6 100644 --- a/lib/twitter/rest/api/tweets.rb +++ b/lib/twitter/rest/api/tweets.rb @@ -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. @@ -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 @@ -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. @@ -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 diff --git a/spec/twitter/rest/api/tweets_spec.rb b/spec/twitter/rest/api/tweets_spec.rb index 210478175..ba7fdfda2 100644 --- a/spec/twitter/rest/api/tweets_spec.rb +++ b/spec/twitter/rest/api/tweets_spec.rb @@ -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