Skip to content
Browse files

support for updata_with_media with minimum gem logic changes

  • Loading branch information...
1 parent ee81f06 commit cdf717b366a9ac73133a6f576391c4c3f46f9bb3 @jnak jnak committed Aug 25, 2011
Showing with 38 additions and 9 deletions.
  1. +24 −0 lib/twitter/client/tweets.rb
  2. +6 −1 lib/twitter/configuration.rb
  3. +4 −3 lib/twitter/connection.rb
  4. +4 −5 lib/twitter/request.rb
View
24 lib/twitter/client/tweets.rb
@@ -45,6 +45,30 @@ def update(status, options={})
response = post('statuses/update', options.merge(:status => status))
format.to_s.downcase == 'xml' ? response['status'] : response
end
+
+ # Updates with media the authenticating user's status
+ #
+ # @see http://dev.twitter.com/docs/api/1/post/statuses/update_with_media
+ # @format :json, :xml
+ # @authenticated true
+ # @rate_limited false
+ # @param status [String] The text of your status update, up to 140 characters.
+ # @param media [File] A File object with your picture (PNG, JPEG or GIF)
+ # @param options [Hash] A customizable set of options.
+ # @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.
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::Client::Geo#reverse_geocode}.
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
+ # @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.
+ # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
+ # @return [Hashie::Mash] The created status.
+ # @example Update the authenticating user's status
+ # Twitter.update("I just posted a status update with a pic via the Twitter Ruby Gem!", File.new('my_awesome_pic.jpeg))
+ def update_with_media(status, image, options={})
+ response = post('statuses/update_with_media', options.merge('media[]' => image, 'status' => status), format, true)
+ format.to_s.downcase == 'xml' ? response['user'] : response
+ end
# Destroys the specified status
#
View
7 lib/twitter/configuration.rb
@@ -15,7 +15,8 @@ module Configuration
:oauth_token_secret,
:proxy,
:search_endpoint,
- :user_agent].freeze
+ :user_agent,
+ :media_endpoint].freeze
# The adapter that will be used to connect if none is set
DEFAULT_ADAPTER = :net_http
@@ -59,6 +60,9 @@ module Configuration
DEFAULT_USER_AGENT = "Twitter Ruby Gem #{Twitter::VERSION}".freeze
DEFAULT_GATEWAY = nil
+
+ # This endpoint will be used by default when updating statuses with media
+ DEFAULT_SEARCH_ENDPOINT = 'https://search.twitter.com/'.freeze
# @private
attr_accessor *VALID_OPTIONS_KEYS
@@ -93,6 +97,7 @@ def reset
self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
self.user_agent = DEFAULT_USER_AGENT
self.gateway = DEFAULT_GATEWAY
+ self.media_endpoint = MEDIA_ENDPOINT
self
end
end
View
7 lib/twitter/connection.rb
@@ -10,17 +10,18 @@ module Twitter
module Connection
private
- def connection(format=format)
+ def connection(format=format, media=false)
options = {
:headers => {
:accept => "application/#{format}",
:user_agent => user_agent,
},
:proxy => proxy,
:ssl => {:verify => false},
- :url => api_endpoint,
}
-
+
+ options[:url] = media ? media_endpoint : api_endpoint
+
Faraday.new(options) do |builder|
builder.use Faraday::Request::MultipartWithFile
builder.use Faraday::Request::TwitterOAuth, authentication if authenticated?
View
9 lib/twitter/request.rb
@@ -6,9 +6,8 @@ def get(path, options={}, format=format)
request(:get, path, options, format)
end
- # Perform an HTTP POST request
- def post(path, options={}, format=format)
- request(:post, path, options, format)
+ def post(path, options={}, format=format, media=false)
+ request(:post, path, options, format, media)
end
# Perform an HTTP PUT request
@@ -24,8 +23,8 @@ def delete(path, options={}, format=format)
private
# Perform an HTTP request
- def request(method, path, options, format)
- response = connection(format).send(method) do |request|
+ def request(method, path, options, format, media=false)
+ response = connection(format, media).send(method) do |request|
case method.to_sym
when :get, :delete
request.url(formatted_path(path, format), options)

0 comments on commit cdf717b

Please sign in to comment.
Something went wrong with that request. Please try again.