From 715277290c6dfd108c1652f117563ad52b479b81 Mon Sep 17 00:00:00 2001 From: Susan Potter Date: Thu, 2 Jun 2011 00:02:29 -0500 Subject: [PATCH] Add ability to post lat/long/place_id with tweet --- lib/twitter/client/status.rb | 17 ++++++++++++++++- spec/twitter/client/status_spec.rb | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/twitter/client/status.rb b/lib/twitter/client/status.rb index 0a6f3d5..7413b24 100644 --- a/lib/twitter/client/status.rb +++ b/lib/twitter/client/status.rb @@ -23,12 +23,20 @@ class Twitter::Client # twitter.status(:get, 107786772) # twitter.status(:post, "New Ruby open source project Twitter4R version 0.2.0 released.") # twitter.status(:delete, 107790712) + # twitter.status(:reply, :in_reply_to_status_id => 1390482942342, :status => "@t4ruby This new v0.7.0 release is da bomb! #ruby #twitterapi #twitter4r") + # twitter.status(:post, "My brand new status in all its glory here tweeted from Greenwich (the real one). #withawesomehashtag #booyah", :lat => 0, :long => 0) # # An ArgumentError will be raised if an invalid action # is given. Valid actions are: # * +:get+ # * +:post+ # * +:delete+ + # + # The third argument +options+ sends on a Hash to the Twitter API with the following keys allowed: + # * +:lat+ - latitude (for posting geolocation) + # * +:long+ - longitude (for posting geolocation) + # * +:place_id+ - using a place ID give by geo/reverse_geocode + # * +:display_coordinates+ - whether or not to put a pin in the exact coordinates def status(action, value = nil) return self.timeline_for(action, value || {}) if :replies == action raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action) @@ -39,7 +47,14 @@ class Twitter::Client when :get response = rest_oauth_connect(:get, uri, {:id => value.to_i}) when :post - response = rest_oauth_connect(:post, uri, :status => value, :source => self.class.config.source) + if value.is_a?(Hash) + params = value.delete_if { |k, v| + ![:status, :lat, :long, :place_id, :display_coordinates].member?(k) + } + else + params = {:status => value} + end + response = rest_oauth_connect(:post, uri, params.merge(:source => self.class.config.source)) when :delete response = rest_oauth_connect(:delete, uri, {:id => value.to_i}) when :reply diff --git a/spec/twitter/client/status_spec.rb b/spec/twitter/client/status_spec.rb index 0cfda22..813b0df 100644 --- a/spec/twitter/client/status_spec.rb +++ b/spec/twitter/client/status_spec.rb @@ -45,6 +45,16 @@ describe Twitter::Client, "#status" do @twitter.status(:post, @message) end + it "should create expected HTTP POST request for :post case when passing Hash with lat/long instead of String" do + @twitter.should_receive(:rest_oauth_connect).with(:post, @uris[:post], :lat => 0, :long => 0, :status => @message, :source => @source).and_return(@response) + @twitter.status(:post, :status => @message, :lat => 0, :long => 0) + end + + it "should create expected HTTP POST request for :post case when passing Hash with place_idinstead of String" do + @twitter.should_receive(:rest_oauth_connect).with(:post, @uris[:post], :place_id => 1234, :status => @message, :source => @source).and_return(@response) + @twitter.status(:post, :status => @message, :place_id => 1234) + end + it "should return nil if nil is passed as value argument for :post case" do status = @twitter.status(:post, nil) status.should be_nil -- 2.11.4.GIT