Skip to content

Commit

Permalink
Remove support for XML response format
Browse files Browse the repository at this point in the history
Twitter stopped providing XML responses for all resources and there's no
benefit in supporting XML, especially now that JSON parsing is provided
by the Ruby standard library.
  • Loading branch information
sferik committed Oct 7, 2011
1 parent c3a19dc commit e60b9ca
Show file tree
Hide file tree
Showing 111 changed files with 3,197 additions and 31,525 deletions.
1 change: 0 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
--protected
--tag rate_limited:"Rate Limited?"
--tag requires_authentication:"Requires Authentication?"
--tag response_format:"Response Formats"
--markup markdown
-
HISTORY.md
Expand Down
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ namespace :doc do
task.options = [
'--protected',
'--output-dir', 'doc/yard',
'--tag', 'format:Supported formats',
'--tag', 'authenticated:Requires Authentication',
'--tag', 'rate_limited:Rate Limited',
'--tag', 'requires_authentication:Requires Authentication?',
'--tag', 'rate_limited:Rate Limited?',
'--markup', 'markdown',
]
end
Expand Down
56 changes: 13 additions & 43 deletions lib/twitter/client/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ module Account
# @see https://dev.twitter.com/docs/api/1/get/account/verify_credentials
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
# @return [Hashie::Mash] The authenticated user.
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the requesting user if authentication was successful
# Twitter.verify_credentials
def verify_credentials(options={})
response = get('1/account/verify_credentials', options)
format.to_s.downcase == 'xml' ? response['user'] : response
get("/1/account/verify_credentials.json", options)
end

# Returns the remaining number of API requests available to the requesting user
Expand All @@ -27,58 +24,47 @@ def verify_credentials(options={})
# @requires_authentication No
#
# This will return the requesting IP's rate limit status. If you want the authenticating user's rate limit status you must authenticate.
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash]
# @example Return the remaining number of API requests available to the requesting user
# Twitter.rate_limit_status
def rate_limit_status(options={})
response = get('1/account/rate_limit_status', options)
format.to_s.downcase == 'xml' ? response['hash'] : response
get("/1/account/rate_limit_status.json", options)
end

# Ends the session of the authenticating user
#
# @see https://dev.twitter.com/docs/api/1/post/account/end_session
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash]
# @example End the session of the authenticating user
# Twitter.end_session
def end_session(options={})
response = post('1/account/end_session', options)
format.to_s.downcase == 'xml' ? response['hash'] : response
post("/1/account/end_session.json", options)
end

# Sets which device Twitter delivers updates to for the authenticating user
#
# @see https://dev.twitter.com/docs/api/1/post/account/update_delivery_device
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param device [String] Must be one of: 'sms', 'none'.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
# @return [Hashie::Mash] The authenticated user.
# @example Turn SMS updates on for the authenticating user
# Twitter.update_delivery_device('sms')
def update_delivery_device(device, options={})
response = post('1/account/update_delivery_device', options.merge(:device => device))
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/account/update_delivery_device.json", options.merge(:device => device))
end

# Sets one or more hex values that control the color scheme of the authenticating user's profile
#
# @see https://dev.twitter.com/docs/api/1/post/account/update_profile_colors
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [String] :profile_background_color Profile background color.
# @option options [String] :profile_text_color Profile text color.
Expand All @@ -90,8 +76,7 @@ def update_delivery_device(device, options={})
# @example Set authenticating user's profile background to black
# Twitter.update_profile_colors(:profile_background_color => '000000')
def update_profile_colors(options={})
response = post('1/account/update_profile_colors', options)
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/account/update_profile_colors.json", options)
end

# Updates the authenticating user's profile image
Expand All @@ -100,26 +85,21 @@ def update_profile_colors(options={})
# @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using {Twitter::Client::User#profile_image}.
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param image [String] The avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
# @return [Hashie::Mash] The authenticated user.
# @example Update the authenticating user's profile image
# Twitter.update_profile_image(File.new("me.jpeg"))
def update_profile_image(image, options={})
response = post('1/account/update_profile_image', options.merge(:image => image))
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/account/update_profile_image.json", options.merge(:image => image))
end

# Updates the authenticating user's profile background image
#
# @see https://dev.twitter.com/docs/api/1/post/account/update_profile_background_image
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param image [String] The background image for the profile. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be scaled down.
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
Expand All @@ -128,8 +108,7 @@ def update_profile_image(image, options={})
# @example Update the authenticating user's profile background image
# Twitter.update_profile_background_image(File.new("we_concept_bg2.png"))
def update_profile_background_image(image, options={})
response = post('1/account/update_profile_background_image', options.merge(:image => image))
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/account/update_profile_background_image.json", options.merge(:image => image))
end

# Sets values that users are able to set under the "Account" tab of their settings page
Expand All @@ -138,8 +117,6 @@ def update_profile_background_image(image, options={})
# @note Only the options specified will be updated.
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
# @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
Expand All @@ -150,24 +127,20 @@ def update_profile_background_image(image, options={})
# @example Set authenticating user's name to Erik Michaels-Ober
# Twitter.update_profile(:name => "Erik Michaels-Ober")
def update_profile(options={})
response = post('1/account/update_profile', options)
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/account/update_profile.json", options)
end

# Returns the current count of friends, followers, updates (statuses) and favorites of the authenticating user.
#
# @see https://dev.twitter.com/docs/api/1/get/account/totals
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @return [Hashie::Mash] the current count of friends, followers, updates, and favorites of the authenticating user.
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the totals for the authenticating user.
# Twitter.totals
def totals()
response = get('1/account/totals')
format.to_s.downcase == 'xml' ? response['hash'] : response
def totals(options={})
get("/1/account/totals.json", options)
end

# Updates the authenticating user's settings.
Expand All @@ -177,8 +150,6 @@ def totals()
# @see https://dev.twitter.com/docs/api/1/get/account/settings
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1/get/trends/available GET trends/available}.
# @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
Expand All @@ -190,14 +161,13 @@ def totals()
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the settings for the authenticating user.
# Twitter.settings
def settings(options = {})
def settings(options={})
case options.length
when 0
response = get('1/account/settings')
get("/1/account/settings.json", options)
else
response = post('1/account/settings', options)
post("/1/account/settings.json", options)
end
format.to_s.downcase == 'xml' ? response['hash'] : response
end

end
Expand Down
6 changes: 2 additions & 4 deletions lib/twitter/client/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Activity
# @note Undocumented
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @param options [Hash] A customizable set of options.
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
Expand All @@ -16,15 +15,14 @@ module Activity
# @example Return activity about me
# Twitter.about_me
def about_me(options={})
get("i/activity/about_me", options, :format => :json, :phoenix => true)
get("/i/activity/about_me.json", options, :phoenix => true)
end

# Returns activity by friends
#
# @note Undocumented
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @param options [Hash] A customizable set of options.
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
Expand All @@ -33,7 +31,7 @@ def about_me(options={})
# @example Return activity by friends
# Twitter.by_friends
def by_friends(options={})
get("i/activity/by_friends", options, :format => :json, :phoenix => true)
get("/i/activity/by_friends.json", options, :phoenix => true)
end
end
end
Expand Down
22 changes: 5 additions & 17 deletions lib/twitter/client/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Block
# @note Destroys a friendship to the blocked user if it exists.
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
Expand All @@ -20,17 +18,14 @@ module Block
# Twitter.block(7505382) # Same as above
def block(user, options={})
merge_user_into_options!(user, options)
response = post('1/blocks/create', options)
format.to_s.downcase == 'xml' ? response['user'] : response
post("/1/blocks/create.json", options)
end

# Un-blocks the user specified by the authenticating user
#
# @see https://dev.twitter.com/docs/api/1/post/blocks/destroy
# @rate_limited No
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
Expand All @@ -40,8 +35,7 @@ def block(user, options={})
# Twitter.unblock(7505382) # Same as above
def unblock(user, options={})
merge_user_into_options!(user, options)
response = delete('1/blocks/destroy', options)
format.to_s.downcase == 'xml' ? response['user'] : response
delete("/1/blocks/destroy.json", options)
end

# Returns true if the authenticating user is blocking a target user
Expand All @@ -57,7 +51,7 @@ def unblock(user, options={})
# Twitter.block?(7505382) # Same as above
def block?(user, options={})
merge_user_into_options!(user, options)
get('1/blocks/exists', options, :format => :json, :raw => true)
get("/1/blocks/exists.json", options, :raw => true)
true
rescue Twitter::NotFound
false
Expand Down Expand Up @@ -85,33 +79,27 @@ def block_exists?(user, options={})
# @see https://dev.twitter.com/docs/api/1/get/blocks/blocking
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [Integer] :page Specifies the page of results to retrieve.
# @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
# @return [Array] User objects that the authenticating user is blocking.
# @example Return an array of user objects that the authenticating user is blocking
# Twitter.blocking
def blocking(options={})
response = get('1/blocks/blocking', options)
format.to_s.downcase == 'xml' ? response['users'] : response
get("/1/blocks/blocking.json", options)
end

# Returns an array of numeric user ids the authenticating user is blocking
#
# @see https://dev.twitter.com/docs/api/1/get/blocks/blocking/ids
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @return [Array] Numeric user ids the authenticating user is blocking.
# @example Return an array of numeric user ids the authenticating user is blocking
# Twitter.blocking_ids
def blocked_ids(options={})
response = get('1/blocks/blocking/ids', options)
format.to_s.downcase == 'xml' ? response['ids']['id'].map{|id| id.to_i} : response
get("/1/blocks/blocking/ids.json", options)
end
end
end
Expand Down
Loading

0 comments on commit e60b9ca

Please sign in to comment.