Skip to content

Commit

Permalink
Replace remaining Hashie::Mash instances with hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Oct 12, 2011
1 parent e5332b8 commit 5f53536
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 83 deletions.
8 changes: 4 additions & 4 deletions lib/twitter/client/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def verify_credentials(options={})
#
# This will return the requesting IP's rate limit status. If you want the authenticating user's rate limit status you must authenticate.
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash]
# @return [Hash]
# @example Return the remaining number of API requests available to the requesting user
# Twitter.rate_limit_status
def rate_limit_status(options={})
Expand All @@ -41,7 +41,7 @@ def rate_limit_status(options={})
# @rate_limited No
# @requires_authentication Yes
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash]
# @return [Hash]
# @example End the session of the authenticating user
# Twitter.end_session
def end_session(options={})
Expand Down Expand Up @@ -143,7 +143,7 @@ def update_profile(options={})
# @see https://dev.twitter.com/docs/api/1/get/account/totals
# @rate_limited Yes
# @requires_authentication Yes
# @return [Hashie::Mash] the current count of friends, followers, updates, and favorites of the authenticating user.
# @return [Hash] 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
Expand All @@ -165,7 +165,7 @@ def totals(options={})
# @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
# @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
# @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1/get/help/languages GET help/languages}.
# @return [Hashie::Mash]
# @return [Hash]
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the settings for the authenticating user.
# Twitter.settings
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/client/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module FriendsAndFollowers
#
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array] Numeric IDs.
# @return [Hash]
# @example Return the authenticated user's friends' IDs
# Twitter.friend_ids
# @overload friend_ids(user, options={})
Expand All @@ -21,7 +21,7 @@ module FriendsAndFollowers
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array] Numeric IDs.
# @return [Hash]
# @example Return @sferik's friends' IDs
# Twitter.friend_ids("sferik")
# Twitter.friend_ids(7505382) # Same as above
Expand All @@ -43,7 +43,7 @@ def friend_ids(*args)
#
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array] Numeric IDs.
# @return [Hash]
# @example Return the authenticated user's followers' IDs
# Twitter.follower_ids
# @overload follower_ids(user, options={})
Expand All @@ -52,7 +52,7 @@ def friend_ids(*args)
# @param user [Integer, String] A Twitter user ID or screen name.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Array] Numeric IDs.
# @return [Hash]
# @example Return @sferik's followers' IDs
# Twitter.follower_ids("sferik")
# Twitter.follower_ids(7505382) # Same as above
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/client/friendship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def friendship?(user_a, user_b, options={})
# @option options [String] :source_screen_name The screen_name of the subject user.
# @option options [Integer] :target_id The ID of the target user.
# @option options [String] :target_screen_name The screen_name of the target user.
# @return [Hashie::Mash]
# @return [Hash]
# @example Return the relationship between @sferik and @pengwynn
# Twitter.friendship(:source_screen_name => "sferik", :target_screen_name => "pengwynn")
# Twitter.friendship(:source_id => 7505382, :target_id => 14100886)
Expand All @@ -86,7 +86,7 @@ def friendship(options={})
# @requires_authentication Yes
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Hashie::Mash]
# @return [Hash]
# @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user
# Twitter.friendships_incoming
def friendships_incoming(options={})
Expand All @@ -101,7 +101,7 @@ def friendships_incoming(options={})
# @requires_authentication Yes
# @param options [Hash] A customizable set of options.
# @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
# @return [Hashie::Mash]
# @return [Hash]
# @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
# Twitter.friendships_outgoing
def friendships_outgoing(options={})
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/client/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Help
# @see https://dev.twitter.com/docs/api/1/get/help/configuration
# @rate_limited Yes
# @requires_authentication No
# @return [Hashie::Mash] Twitter's configuration.
# @return [Hash] Twitter's configuration.
# @example Return the current configuration used by Twitter
# Twitter.configuration
def configuration(options={})
Expand All @@ -19,7 +19,7 @@ def configuration(options={})
# @see https://dev.twitter.com/docs/api/1/get/help/languages
# @rate_limited Yes
# @requires_authentication No
# @return [Array]
# @return [Array<Hash>]
# @example Return the list of languages Twitter supports
# Twitter.languages
def languages(options={})
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/client/local_trends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def trend_locations(options={})
# @example Return the top 10 trending topics for San Francisco
# Twitter.local_trends(2487956)
def local_trends(woeid=1, options={})
response = get("/1/trends/#{woeid}.json", options)
response.first.trends.map{|trend| trend.name}
get("/1/trends/#{woeid}.json", options).first['trends'].map do |trend|
trend['name']
end
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/client/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def update(status, options={})
# @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.
# @return [Twitter::Status] The created status.
# @see http://dev.twitter.com/docs/api/1/post/statuses/update_with_media
# @example Update the authenticating user's status
# When you have a File instance (e.g. the pic is already on your disk)
Expand All @@ -68,7 +68,8 @@ def update(status, options={})
# download the pic and put the response in a StringIO object
# Twitter.update_with_media("I just posted a status update with a pic via the Twitter Ruby Gem!", {'io' => StringIO.new(pic), 'type' => 'jpg'})
def update_with_media(status, image, options={})
post("/1/statuses/update_with_media.json", options.merge('media[]' => image, 'status' => status), :endpoint => media_endpoint)
status = post("/1/statuses/update_with_media.json", options.merge('media[]' => image, 'status' => status), :endpoint => media_endpoint)
Twitter::Status.new(status)
end

# Destroys the specified status
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/client/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Urls
# @overload resolve(urls, options={})
# @param urls [String] A list of shortened URLs.
# @param options [Hash] A customizable set of options.
# @return [Hashie::Mash] A hash of URLs with the shortened URLs as the key
# @return [Hash] A hash of URLs with the shortened URLs as the key
# @example Return the canonical version of a URL shortened by Twitter
# Twitter.resolve('http://t.co/uw5bn1w', 'http://t.co/dXvMz9i')
# Twitter.resolve(['http://t.co/uw5bn1w', 'http://t.co/dXvMz9i']) # Same as above
Expand Down
6 changes: 1 addition & 5 deletions lib/twitter/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'twitter/request/multipart_with_file'
require 'twitter/request/phoenix'
require 'twitter/request/oauth'
require 'twitter/response/mashify'
require 'twitter/response/parse_json'
require 'twitter/response/raise_http_4xx'
require 'twitter/response/raise_http_5xx'
Expand Down Expand Up @@ -30,10 +29,7 @@ def connection(options={})
builder.use Faraday::Request::UrlEncoded
builder.use Twitter::Request::Gateway, gateway if gateway
builder.use Twitter::Response::RaiseHttp4xx
unless options[:raw]
builder.use Twitter::Response::Mashify
builder.use Twitter::Response::ParseJson
end
builder.use Twitter::Response::ParseJson unless options[:raw]
builder.use Twitter::Response::RaiseHttp5xx
builder.adapter(adapter)
end
Expand Down
26 changes: 0 additions & 26 deletions lib/twitter/response/mashify.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/twitter/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def next_page?
def fetch_next_page
if next_page?
@cache = get("/search.json", CGI.parse(@cache["next_page"][1..-1]), :format => :json)
@cache.results
@cache['results']
end
end

Expand All @@ -466,12 +466,12 @@ def fetch(force=false)
options[:q] = options[:q].join(" ")
@cache = get("/search.json", options, :format => :json)
end
@cache.results
@cache['results']
end

# Calls block once for each element in self, passing that element as a parameter
#
# @yieldparam [Hashie::Mash] result Tweet that matches specified query.
# @yieldparam [Hash] result Tweet that matches specified query.
# @return [Array] Tweets that match specified query.
# @example
# Twitter::Search.new.containing('marry me').to('justinbieber').each do |result|
Expand Down
17 changes: 15 additions & 2 deletions spec/twitter/client/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

it "should return the remaining number of API requests available to the requesting user before the API limit is reached" do
rate_limit_status = @client.rate_limit_status
rate_limit_status.remaining_hits.should == 19993
rate_limit_status.should be_a Hash
rate_limit_status['remaining_hits'].should == 19993
end

end
Expand All @@ -61,7 +62,7 @@

it "should return a null cookie" do
end_session = @client.end_session
end_session.error.should == "Logged out."
end_session['error'].should == "Logged out."
end

end
Expand Down Expand Up @@ -189,6 +190,12 @@
should have_been_made
end

it "should return a hash" do
totals = @client.totals
totals.should be_a Hash
totals['favorites'].should == 2811
end

end

describe ".settings" do
Expand All @@ -207,6 +214,12 @@
should have_been_made
end

it "should return a hash" do
settings = @client.settings
settings.should be_a Hash
settings['language'].should == 'en'
end

it "should get the correct resource on POST" do
@client.settings(:trend_location_woeid => "23424803")
a_post("/1/account/settings.json").
Expand Down
28 changes: 16 additions & 12 deletions spec/twitter/client/friends_and_followers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
end

it "should return an array of numeric IDs for every user the specified user is following" do
id_list = @client.friend_ids("sferik")
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
friend_ids = @client.friend_ids("sferik")
friend_ids.should be_a Hash
friend_ids['ids'].should be_an Array
friend_ids['ids'].first.should == 146197851
end

end
Expand All @@ -46,9 +47,10 @@
end

it "should return an array of numeric IDs for every user the specified user is following" do
id_list = @client.friend_ids
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
friend_ids = @client.friend_ids
friend_ids.should be_a Hash
friend_ids['ids'].should be_an Array
friend_ids['ids'].first.should == 146197851
end

end
Expand All @@ -73,9 +75,10 @@
end

it "should return an array of numeric IDs for every user following the specified user" do
id_list = @client.follower_ids("sferik")
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
follower_ids = @client.follower_ids("sferik")
follower_ids.should be_a Hash
follower_ids['ids'].should be_an Array
follower_ids['ids'].first.should == 146197851
end

end
Expand All @@ -96,9 +99,10 @@
end

it "should return an array of numeric IDs for every user following the specified user" do
id_list = @client.follower_ids
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
follower_ids = @client.follower_ids
follower_ids.should be_a Hash
follower_ids['ids'].should be_an Array
follower_ids['ids'].first.should == 146197851
end
end
end
Expand Down
17 changes: 10 additions & 7 deletions spec/twitter/client/friendship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@

it "should return detailed information about the relationship between two users" do
relationship = @client.friendship(:source_screen_name => "sferik", :target_screen_name => "pengwynn")
relationship.source.screen_name.should == "sferik"
relationship.should be_a Hash
relationship['source']['screen_name'].should == "sferik"
end

end
Expand All @@ -169,9 +170,10 @@
end

it "should return an array of numeric IDs for every user who has a pending request to follow the authenticating user" do
id_list = @client.friendships_incoming
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
friendships_incoming = @client.friendships_incoming
friendships_incoming.should be_a Hash
friendships_incoming['ids'].should be_an Array
friendships_incoming['ids'].first.should == 146197851
end

end
Expand All @@ -192,9 +194,10 @@
end

it "should return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request" do
id_list = @client.friendships_outgoing
id_list.ids.should be_an Array
id_list.ids.first.should == 146197851
friendships_outgoing = @client.friendships_outgoing
friendships_outgoing.should be_a Hash
friendships_outgoing['ids'].should be_an Array
friendships_outgoing['ids'].first.should == 146197851
end
end
end
7 changes: 5 additions & 2 deletions spec/twitter/client/help_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

it "should return Twitter's current configuration" do
configuration = @client.configuration
configuration.characters_reserved_per_media.to_s.should == '20'
configuration.should be_a Hash
configuration['characters_reserved_per_media'].should == 20
end

end
Expand All @@ -40,7 +41,9 @@

it "should return the list of languages supported by Twitter" do
languages = @client.languages
languages.first.name.should == "Portuguese"
languages.should be_an Array
languages.first.should be_a Hash
languages.first['name'].should == "Portuguese"
end
end
end
3 changes: 2 additions & 1 deletion spec/twitter/client/local_trends_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
it "should return the locations that Twitter has trending topic information for" do
locations = @client.trend_locations
locations.should be_an Array
locations.first.name.should == "Ireland"
locations.first.should be_a Hash
locations.first['name'].should == "Ireland"
end

end
Expand Down

0 comments on commit 5f53536

Please sign in to comment.