diff --git a/README.md b/README.md index b22538469..cf2e17bd7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ wiki][apps]! [apps]: https://github.com/jnunemaker/twitter/wiki/apps ## What's new in version 3? +### Hashes +All returned hashes now use symbols as keys instead of strings. + ### Methods The following methods now accept multiple users or ids as arguments and return arrays: @@ -57,18 +60,18 @@ The `Twitter::Client#direct_messages` method has been renamed to The `Twitter::Client#profile_image` method has been removed. -Additionally, the `Twitter::Client#follow` method now checks to make sure the -user isn't already being followed. If you don't wish to perform that check -(which does require an extra HTTP request), you can use the new -`Twitter::Client#follow!` method instead. **Note**: This may re-send an email -notification to the user, even if they are already being followed. - The `Twitter::Client#search` now returns a `Twitter::SearchResult` object, which contains metadata and a results array. In the previous major version, this method returned an array of `Twitter::Status` objects, which is now accessible by sending the `results` message to a `Twitter::SearchResults` object. +Additionally, the `Twitter::Client#follow` method now checks to make sure the +user isn't already being followed. If you don't wish to perform that check +(which does require an extra HTTP request), you can use the new +`Twitter::Client#follow!` method instead. **Note**: This may re-send an email +notification to the user, even if they are already being followed. + ##### Version 2 Twitter::Client.search("query").map(&:full_text) diff --git a/lib/twitter/action/favorite.rb b/lib/twitter/action/favorite.rb index bd3a2cb49..783711cf8 100644 --- a/lib/twitter/action/favorite.rb +++ b/lib/twitter/action/favorite.rb @@ -9,7 +9,7 @@ class Favorite < Twitter::Action::Status # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |status| + @targets = Array(@attrs[:targets]).map do |status| Twitter::Status.fetch_or_new(status) end end diff --git a/lib/twitter/action/follow.rb b/lib/twitter/action/follow.rb index c6bdd084d..9c9e837f7 100644 --- a/lib/twitter/action/follow.rb +++ b/lib/twitter/action/follow.rb @@ -12,7 +12,7 @@ class Follow < Twitter::Base # # @return [Array] def sources - @sources = Array(@attrs['sources']).map do |user| + @sources = Array(@attrs[:sources]).map do |user| Twitter::User.fetch_or_new(user) end end @@ -21,7 +21,7 @@ def sources # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |user| + @targets = Array(@attrs[:targets]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/action/list_member_added.rb b/lib/twitter/action/list_member_added.rb index 9a6178809..83b745770 100644 --- a/lib/twitter/action/list_member_added.rb +++ b/lib/twitter/action/list_member_added.rb @@ -13,7 +13,7 @@ class ListMemberAdded < Twitter::Base # # @return [Array] def sources - @sources = Array(@attrs['sources']).map do |user| + @sources = Array(@attrs[:sources]).map do |user| Twitter::User.fetch_or_new(user) end end @@ -22,7 +22,7 @@ def sources # # @return [Array] def target_objects - @target_objects = Array(@attrs['target_objects']).map do |list| + @target_objects = Array(@attrs[:target_objects]).map do |list| Twitter::List.fetch_or_new(list) end end @@ -31,7 +31,7 @@ def target_objects # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |user| + @targets = Array(@attrs[:targets]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/action/mention.rb b/lib/twitter/action/mention.rb index 9cb299250..4214eb559 100644 --- a/lib/twitter/action/mention.rb +++ b/lib/twitter/action/mention.rb @@ -13,7 +13,7 @@ class Mention < Twitter::Base # # @return [Array] def sources - @sources = Array(@attrs['sources']).map do |user| + @sources = Array(@attrs[:sources]).map do |user| Twitter::User.fetch_or_new(user) end end @@ -29,7 +29,7 @@ def source # # @return [Array] def target_objects - @target_objects = Array(@attrs['target_objects']).map do |status| + @target_objects = Array(@attrs[:target_objects]).map do |status| Twitter::Status.fetch_or_new(status) end end @@ -38,7 +38,7 @@ def target_objects # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |user| + @targets = Array(@attrs[:targets]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/action/reply.rb b/lib/twitter/action/reply.rb index 4857032ef..920c5f3aa 100644 --- a/lib/twitter/action/reply.rb +++ b/lib/twitter/action/reply.rb @@ -8,7 +8,7 @@ class Reply < Twitter::Action::Status # # @return [Array] def target_objects - @target_objects = Array(@attrs['target_objects']).map do |status| + @target_objects = Array(@attrs[:target_objects]).map do |status| Twitter::Status.fetch_or_new(status) end end @@ -17,7 +17,7 @@ def target_objects # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |status| + @targets = Array(@attrs[:targets]).map do |status| Twitter::Status.fetch_or_new(status) end end diff --git a/lib/twitter/action/retweet.rb b/lib/twitter/action/retweet.rb index 00f26f4de..a11e9338a 100644 --- a/lib/twitter/action/retweet.rb +++ b/lib/twitter/action/retweet.rb @@ -8,7 +8,7 @@ class Retweet < Twitter::Action::Status # # @return [Array] def target_objects - @target_objects = Array(@attrs['target_objects']).map do |status| + @target_objects = Array(@attrs[:target_objects]).map do |status| Twitter::Status.fetch_or_new(status) end end @@ -17,7 +17,7 @@ def target_objects # # @return [Array] def targets - @targets = Array(@attrs['targets']).map do |user| + @targets = Array(@attrs[:targets]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/action/status.rb b/lib/twitter/action/status.rb index bcf3d3940..c0c5875ca 100644 --- a/lib/twitter/action/status.rb +++ b/lib/twitter/action/status.rb @@ -11,7 +11,7 @@ class Status < Twitter::Base # @return [Array] def sources - @sources = Array(@attrs['sources']).map do |user| + @sources = Array(@attrs[:sources]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/action_factory.rb b/lib/twitter/action_factory.rb index b8d25e603..c00deeeca 100644 --- a/lib/twitter/action_factory.rb +++ b/lib/twitter/action_factory.rb @@ -13,13 +13,13 @@ class ActionFactory # Instantiates a new action object # # @param attrs [Hash] - # @raise [ArgumentError] Error raised when supplied argument is missing an 'action' key. + # @raise [ArgumentError] Error raised when supplied argument is missing an :action key. # @return [Twitter::Action::Favorite, Twitter::Action::Follow, Twitter::Action::ListMemberAdded, Twitter::Action::Mention, Twitter::Action::Reply, Twitter::Action::Retweet] def self.new(attrs={}) - if type = attrs.delete('action') + if type = attrs.delete(:action) Twitter::Action.const_get(camelize(type).to_sym).fetch_or_new(attrs) else - raise ArgumentError, "argument must have an 'action' key" + raise ArgumentError, "argument must have an :action key" end end diff --git a/lib/twitter/base.rb b/lib/twitter/base.rb index cc5597bc3..b1a632bd4 100644 --- a/lib/twitter/base.rb +++ b/lib/twitter/base.rb @@ -19,7 +19,7 @@ def self.attr_reader(*attrs) attrs.each do |attribute| class_eval do define_method attribute do - @attrs[attribute.to_s] + @attrs[attribute.to_sym] end end end diff --git a/lib/twitter/client.rb b/lib/twitter/client.rb index f488b01eb..f38d4ce1e 100644 --- a/lib/twitter/client.rb +++ b/lib/twitter/client.rb @@ -144,7 +144,7 @@ def update_profile(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. # @example Update the authenticating user's profile background image # Twitter.update_profile_background_image(File.new("we_concept_bg2.png")) - # Twitter.update_profile_background_image('io' => StringIO.new(pic), 'type' => 'jpg') + # Twitter.update_profile_background_image(:io => StringIO.new(pic), :type => 'jpg') def update_profile_background_image(image, options={}) response = post("/1/account/update_profile_background_image.json", options.merge(:image => image)) Twitter::User.from_response(response) @@ -182,7 +182,7 @@ def update_profile_colors(options={}) # @param options [Hash] A customizable set of options. # @example Update the authenticating user's profile image # Twitter.update_profile_image(File.new("me.jpeg")) - # Twitter.update_profile_image('io' => StringIO.new(pic), 'type' => 'jpg') + # Twitter.update_profile_image(:io => StringIO.new(pic), :type => 'jpg') def update_profile_image(image, options={}) response = post("/1/account/update_profile_image.json", options.merge(:image => image)) Twitter::User.from_response(response) @@ -938,7 +938,7 @@ def languages(options={}) # @example Return {https://twitter.com/privacy Twitter's Privacy Policy} # Twitter.privacy def privacy(options={}) - get("/1/legal/privacy.json", options)[:body]['privacy'] + get("/1/legal/privacy.json", options)[:body][:privacy] end # Returns {https://twitter.com/tos Twitter's Terms of Service} @@ -950,7 +950,7 @@ def privacy(options={}) # @example Return {https://twitter.com/tos Twitter's Terms of Service} # Twitter.tos def tos(options={}) - get("/1/legal/tos.json", options)[:body]['tos'] + get("/1/legal/tos.json", options)[:body][:tos] end # Returns all lists the authenticating or specified user subscribes to, including their own @@ -1598,7 +1598,7 @@ def list(*args) # Twitter.local_trends(2487956) def local_trends(woeid=1, options={}) response = get("/1/trends/#{woeid}.json", options) - response[:body].first['trends'].map do |trend| + response[:body].first[:trends].map do |trend| Twitter::Trend.fetch_or_new(trend) end end @@ -1685,7 +1685,7 @@ def disable_notifications(*args) # Twitter.places_nearby(:ip => "74.125.19.104") def places_nearby(options={}) response = get("/1/geo/search.json", options) - response[:body]['result']['places'].map do |place| + response[:body][:result][:places].map do |place| Twitter::Place.fetch_or_new(place) end end @@ -1708,7 +1708,7 @@ def places_nearby(options={}) # Twitter.places_similar(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ") def places_similar(options={}) response = get("/1/geo/similar_places.json", options) - response[:body]['result']['places'].map do |place| + response[:body][:result][:places].map do |place| Twitter::Place.fetch_or_new(place) end end @@ -1730,7 +1730,7 @@ def places_similar(options={}) # Twitter.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116") def reverse_geocode(options={}) response = get("/1/geo/reverse_geocode.json", options) - response[:body]['result']['places'].map do |place| + response[:body][:result][:places].map do |place| Twitter::Place.fetch_or_new(place) end end @@ -1907,7 +1907,7 @@ def search(q, options={}) # Twitter.phoenix_search('twitter') def phoenix_search(q, options={}) response = get("/phoenix_search.phoenix", options.merge(:q => q)) - response[:body]['statuses'].map do |status| + response[:body][:statuses].map do |status| Twitter::Status.fetch_or_new(status) end end @@ -2226,7 +2226,7 @@ def network_timeline(options={}) def trends_daily(date=Date.today, options={}) response = get("/1/trends/daily.json", options.merge(:date => date.strftime('%Y-%m-%d'))) trends = {} - response[:body]['trends'].each do |key, value| + response[:body][:trends].each do |key, value| trends[key] = [] value.each do |trend| trends[key] << Twitter::Trend.fetch_or_new(trend) @@ -2249,7 +2249,7 @@ def trends_daily(date=Date.today, options={}) def trends_weekly(date=Date.today, options={}) response = get("/1/trends/weekly.json", options.merge(:date => date.strftime('%Y-%m-%d'))) trends = {} - response[:body]['trends'].each do |key, value| + response[:body][:trends].each do |key, value| trends[key] = [] value.each do |trend| trends[key] << Twitter::Trend.fetch_or_new(trend) @@ -2358,7 +2358,7 @@ def statuses(*args) # Twitter.status_activity(25938088801) def status_activity(id, options={}) response = get("/i/statuses/#{id}/activity/summary.json", options) - response[:body].merge!('id' => id) if response[:body] + response[:body].merge!(:id => id) if response[:body] Twitter::Status.from_response(response) end @@ -2477,8 +2477,8 @@ def retweet(*args) args.flatten.threaded_map do |id| response = post("/1/statuses/retweet/#{id}.json", options) retweeted_status = response.dup - retweeted_status[:body] = response[:body].delete('retweeted_status') - retweeted_status[:body]['retweeted_status'] = response[:body] + retweeted_status[:body] = response[:body].delete(:retweeted_status) + retweeted_status[:body][:retweeted_status] = response[:body] Twitter::Status.from_response(retweeted_status) end end @@ -2525,7 +2525,7 @@ def update(status, options={}) # @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. # @example Update the authenticating user's status # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg')) - # Twitter.update_with_media("I'm tweeting with @gem!", {'io' => StringIO.new(pic), 'type' => 'jpg'}) + # Twitter.update_with_media("I'm tweeting with @gem!", {:io => StringIO.new(pic), :type => 'jpg'}) def update_with_media(status, media, options={}) response = post("/1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status), :endpoint => media_endpoint) Twitter::Status.from_response(response) @@ -2713,7 +2713,7 @@ def recommendations(*args) response = get("/1/users/recommendations.json", options) Twitter::RateLimit.instance.update(response[:response_headers]) response[:body].map do |recommendation| - Twitter::User.fetch_or_new(recommendation['user']) + Twitter::User.fetch_or_new(recommendation[:user]) end end diff --git a/lib/twitter/configuration.rb b/lib/twitter/configuration.rb index a9eef97fd..466f95147 100644 --- a/lib/twitter/configuration.rb +++ b/lib/twitter/configuration.rb @@ -10,7 +10,7 @@ class Configuration < Twitter::Base # # @return [Array] def photo_sizes - @photo_sizes ||= Array(@attrs['photo_sizes']).inject({}) do |object, (key, value)| + @photo_sizes ||= Array(@attrs[:photo_sizes]).inject({}) do |object, (key, value)| object[key] = Twitter::Size.fetch_or_new(value) object end diff --git a/lib/twitter/creatable.rb b/lib/twitter/creatable.rb index 234ae0d88..2dcd38f13 100644 --- a/lib/twitter/creatable.rb +++ b/lib/twitter/creatable.rb @@ -7,7 +7,7 @@ module Creatable # # @return [Time] def created_at - @created_at ||= Time.parse(@attrs['created_at']) unless @attrs['created_at'].nil? + @created_at ||= Time.parse(@attrs[:created_at]) unless @attrs[:created_at].nil? end end diff --git a/lib/twitter/cursor.rb b/lib/twitter/cursor.rb index 5aa6dc00d..8cec6d7e1 100644 --- a/lib/twitter/cursor.rb +++ b/lib/twitter/cursor.rb @@ -13,7 +13,7 @@ class Cursor # @params method [String, Symbol] The name of the method to return the collection # @params klass [Class] The class to instantiate object in the collection # @return [Twitter::Cursor] - def self.from_response(response={}, method='ids', klass=nil) + def self.from_response(response={}, method=:ids, klass=nil) self.new(response[:body], response[:response_headers], method, klass) end @@ -22,10 +22,10 @@ def self.from_response(response={}, method='ids', klass=nil) # @param attrs [Hash] # @param response_headers [Hash] # @return [Twitter::Base] - def initialize(attrs={}, response_headers={}, method='ids', klass=nil) + def initialize(attrs={}, response_headers={}, method=:ids, klass=nil) self.update(attrs) self.update_rate_limit(response_headers) unless response_headers.empty? - @collection = Array(attrs[method.to_s]).map do |item| + @collection = Array(attrs[method.to_sym]).map do |item| if klass klass.fetch_or_new(item) else @@ -38,12 +38,12 @@ def initialize(attrs={}, response_headers={}, method='ids', klass=nil) end def next_cursor - @attrs['next_cursor'] + @attrs[:next_cursor] end alias next next_cursor def previous_cursor - @attrs['previous_cursor'] + @attrs[:previous_cursor] end alias previous previous_cursor diff --git a/lib/twitter/direct_message.rb b/lib/twitter/direct_message.rb index 9633c0b25..55d9846f7 100644 --- a/lib/twitter/direct_message.rb +++ b/lib/twitter/direct_message.rb @@ -9,12 +9,12 @@ class DirectMessage < Twitter::Identifiable # @return [Twitter::User] def recipient - @recipient ||= Twitter::User.fetch_or_new(@attrs['recipient']) unless @attrs['recipient'].nil? + @recipient ||= Twitter::User.fetch_or_new(@attrs[:recipient]) unless @attrs[:recipient].nil? end # @return [Twitter::User] def sender - @sender ||= Twitter::User.fetch_or_new(@attrs['sender']) unless @attrs['sender'].nil? + @sender ||= Twitter::User.fetch_or_new(@attrs[:sender]) unless @attrs[:sender].nil? end end diff --git a/lib/twitter/error/client_error.rb b/lib/twitter/error/client_error.rb index 4c3534de2..343240aa5 100644 --- a/lib/twitter/error/client_error.rb +++ b/lib/twitter/error/client_error.rb @@ -18,12 +18,12 @@ def self.from_env(env) def self.error_body(message) if message.nil? '' - elsif message['error'] - message['error'] - elsif message['errors'] - first = Array(message['errors']).first + elsif message[:error] + message[:error] + elsif message[:errors] + first = Array(message[:errors]).first if first.kind_of?(Hash) - first['message'].chomp + first[:message].chomp else first.chomp end diff --git a/lib/twitter/geo_factory.rb b/lib/twitter/geo_factory.rb index 29f8d64b3..1a26f0bbc 100644 --- a/lib/twitter/geo_factory.rb +++ b/lib/twitter/geo_factory.rb @@ -7,13 +7,13 @@ class GeoFactory # Instantiates a new geo object # # @param attrs [Hash] - # @raise [ArgumentError] Error raised when supplied argument is missing a 'type' key. + # @raise [ArgumentError] Error raised when supplied argument is missing a :type key. # @return [Twitter::Point, Twitter::Polygon] def self.new(attrs={}) - if type = attrs.delete('type') + if type = attrs.delete(:type) Twitter.const_get(type.capitalize.to_sym).fetch_or_new(attrs) else - raise ArgumentError, "argument must have a 'type' key" + raise ArgumentError, "argument must have a :type key" end end diff --git a/lib/twitter/identifiable.rb b/lib/twitter/identifiable.rb index fc4f4d08b..8607dd240 100644 --- a/lib/twitter/identifiable.rb +++ b/lib/twitter/identifiable.rb @@ -4,7 +4,7 @@ module Twitter class Identifiable < Base def self.fetch(attrs) - id = attrs['id'] + id = attrs[:id] @@identity_map[self] ||= {} id && @@identity_map[self][id] && @@identity_map[self][id].update(attrs) || super(attrs) end @@ -15,11 +15,11 @@ def self.fetch(attrs) # @param response_headers [Hash] # @return [Twitter::Base] def initialize(attrs={}, response_headers={}) - if attrs['id'] + if attrs[:id] self.update(attrs) self.update_rate_limit(response_headers) unless response_headers.empty? @@identity_map[self.class] ||= {} - @@identity_map[self.class][attrs['id']] = self + @@identity_map[self.class][attrs[:id]] = self else super end @@ -33,7 +33,7 @@ def ==(other) # @return [Integer] def id - @attrs['id'] + @attrs[:id] end end diff --git a/lib/twitter/list.rb b/lib/twitter/list.rb index e53629de1..a7c359771 100644 --- a/lib/twitter/list.rb +++ b/lib/twitter/list.rb @@ -11,7 +11,7 @@ class List < Twitter::Identifiable # @return [Twitter::User] def user - @user ||= Twitter::User.fetch_or_new(@attrs['user']) unless @attrs['user'].nil? + @user ||= Twitter::User.fetch_or_new(@attrs[:user]) unless @attrs[:user].nil? end end diff --git a/lib/twitter/media_factory.rb b/lib/twitter/media_factory.rb index c982f66b0..2acd2c76f 100644 --- a/lib/twitter/media_factory.rb +++ b/lib/twitter/media_factory.rb @@ -6,13 +6,13 @@ class MediaFactory # Instantiates a new media object # # @param attrs [Hash] - # @raise [ArgumentError] Error raised when supplied argument is missing a 'type' key. + # @raise [ArgumentError] Error raised when supplied argument is missing a :type key. # @return [Twitter::Photo] def self.new(attrs={}) - if type = attrs.delete('type') + if type = attrs.delete(:type) Twitter.const_get(type.capitalize.to_sym).fetch_or_new(attrs) else - raise ArgumentError, "argument must have a 'type' key" + raise ArgumentError, "argument must have a :type key" end end diff --git a/lib/twitter/photo.rb b/lib/twitter/photo.rb index d9e9b4c7d..ec9660b34 100644 --- a/lib/twitter/photo.rb +++ b/lib/twitter/photo.rb @@ -8,7 +8,7 @@ class Photo < Twitter::Identifiable # @return [Array] def sizes - @sizes ||= Array(@attrs['sizes']).inject({}) do |object, (key, value)| + @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)| object[key] = Twitter::Size.fetch_or_new(value) object end diff --git a/lib/twitter/place.rb b/lib/twitter/place.rb index f0b876e46..aa8b2b4c3 100644 --- a/lib/twitter/place.rb +++ b/lib/twitter/place.rb @@ -8,22 +8,22 @@ class Place < Twitter::Identifiable # @return [Twitter::Point, Twitter::Polygon] def bounding_box - @bounding_box ||= Twitter::GeoFactory.new(@attrs['bounding_box']) unless @attrs['bounding_box'].nil? + @bounding_box ||= Twitter::GeoFactory.new(@attrs[:bounding_box]) unless @attrs[:bounding_box].nil? end # @return [String] def country_code - @country_code ||= @attrs['country_code'] || @attrs['countryCode'] + @country_code ||= @attrs[:country_code] || @attrs[:countryCode] end # @return [Integer] def parent_id - @parent_id ||= @attrs['parentid'] + @parent_id ||= @attrs[:parentid] end # @return [String] def place_type - @place_type ||= @attrs['place_type'] || @attrs['placeType'] && @attrs['placeType']['name'] + @place_type ||= @attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name] end end diff --git a/lib/twitter/rate_limit_status.rb b/lib/twitter/rate_limit_status.rb index 77aa08ca7..4f5ea3def 100644 --- a/lib/twitter/rate_limit_status.rb +++ b/lib/twitter/rate_limit_status.rb @@ -8,7 +8,7 @@ class RateLimitStatus < Twitter::Base # # @return [Time] def reset_time - @reset_time ||= Time.parse(@attrs['reset_time']) unless @attrs['reset_time'].nil? + @reset_time ||= Time.parse(@attrs[:reset_time]) unless @attrs[:reset_time].nil? end end diff --git a/lib/twitter/relationship.rb b/lib/twitter/relationship.rb index 489429763..837ed9aaa 100644 --- a/lib/twitter/relationship.rb +++ b/lib/twitter/relationship.rb @@ -7,12 +7,12 @@ class Relationship < Twitter::Base # @return [Twitter::User] def source - @source ||= Twitter::User.fetch_or_new(@attrs['source']) unless @attrs['source'].nil? + @source ||= Twitter::User.fetch_or_new(@attrs[:source]) unless @attrs[:source].nil? end # @return [Twitter::User] def target - @target ||= Twitter::User.fetch_or_new(@attrs['target']) unless @attrs['target'].nil? + @target ||= Twitter::User.fetch_or_new(@attrs[:target]) unless @attrs[:target].nil? end # Update the attributes of a Relationship @@ -21,7 +21,7 @@ def target # @return [Twitter::Relationship] def update(attrs) @attrs ||= {} - @attrs.update(attrs['relationship']) unless attrs['relationship'].nil? + @attrs.update(attrs[:relationship]) unless attrs[:relationship].nil? self end diff --git a/lib/twitter/request/multipart_with_file.rb b/lib/twitter/request/multipart_with_file.rb index d8cdadeed..7e427956a 100644 --- a/lib/twitter/request/multipart_with_file.rb +++ b/lib/twitter/request/multipart_with_file.rb @@ -9,8 +9,8 @@ def call(env) env[:body].each do |key, value| if value.is_a?(File) env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path) - elsif value.is_a?(Hash) && (value['io'].is_a?(IO) || value['io'].is_a?(StringIO)) - env[:body][key] = Faraday::UploadIO.new(value['io'], mime_type('.' + value['type']), '') + elsif value.is_a?(Hash) && (value[:io].is_a?(IO) || value[:io].is_a?(StringIO)) + env[:body][key] = Faraday::UploadIO.new(value[:io], mime_type('.' + value[:type]), '') end end end diff --git a/lib/twitter/requestable.rb b/lib/twitter/requestable.rb index be3b0b564..fe75e8a3b 100644 --- a/lib/twitter/requestable.rb +++ b/lib/twitter/requestable.rb @@ -40,13 +40,13 @@ def request(method, path, params, options) request_headers = {} if credentials? # When posting a file, don't sign any params - signature_params = if :post == method.to_sym && params.values.any?{|value| value.is_a?(File) || (value.is_a?(Hash) && (value['io'].is_a?(IO) || value['io'].is_a?(StringIO)))} + signature_params = if :post == method.to_sym && params.values.any?{|value| value.is_a?(File) || (value.is_a?(Hash) && (value[:io].is_a?(IO) || value[:io].is_a?(StringIO)))} {} else params end authorization = SimpleOAuth::Header.new(method, uri, signature_params, credentials) - request_headers['Authorization'] = authorization.to_s + request_headers[:authorization] = authorization.to_s end connection.url_prefix = options[:endpoint] || endpoint diff --git a/lib/twitter/response/parse_json.rb b/lib/twitter/response/parse_json.rb index 31bd00f6b..ae7327991 100644 --- a/lib/twitter/response/parse_json.rb +++ b/lib/twitter/response/parse_json.rb @@ -14,12 +14,12 @@ def parse(body) when 'false' false else - MultiJson.load(body) + MultiJson.load(body, :symbolize_keys => true) end end def on_complete(env) - if respond_to? :parse + if respond_to?(:parse) env[:body] = parse(env[:body]) unless [204, 304].include?(env[:status]) end end diff --git a/lib/twitter/search_results.rb b/lib/twitter/search_results.rb index 330142289..0b5efe0c8 100644 --- a/lib/twitter/search_results.rb +++ b/lib/twitter/search_results.rb @@ -7,7 +7,7 @@ class SearchResults < Twitter::Base # @return [Array] def results - @results ||= Array(@attrs['results']).map do |status| + @results ||= Array(@attrs[:results]).map do |status| Twitter::Status.fetch_or_new(status) end end diff --git a/lib/twitter/settings.rb b/lib/twitter/settings.rb index 502a29a44..548ebecee 100644 --- a/lib/twitter/settings.rb +++ b/lib/twitter/settings.rb @@ -10,7 +10,7 @@ class Settings < Twitter::Base # @return [Twitter::Place] def trend_location - @trend_location ||= Twitter::Place.fetch_or_new(@attrs['trend_location'].first) unless @attrs['trend_location'].nil? || @attrs['trend_location'].empty? + @trend_location ||= Twitter::Place.fetch_or_new(@attrs[:trend_location].first) unless @attrs[:trend_location].nil? || @attrs[:trend_location].empty? end end diff --git a/lib/twitter/status.rb b/lib/twitter/status.rb index d8805821e..e31dd20ab 100644 --- a/lib/twitter/status.rb +++ b/lib/twitter/status.rb @@ -26,14 +26,14 @@ class Status < Twitter::Identifiable # @return [Integer] def favoriters_count - @favoriters_count ||= @attrs['favoriters_count'] + @favoriters_count ||= @attrs[:favoriters_count] @favoriters_count.to_i if @favoriters_count end alias favorite_count favoriters_count # @return [String] def from_user - @attrs['from_user'] || self.user && self.user.screen_name + @attrs[:from_user] || self.user && self.user.screen_name end # @return [String] @@ -44,14 +44,14 @@ def full_text # @return [Twitter::Point, Twitter::Polygon] def geo - @geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil? + @geo ||= Twitter::GeoFactory.new(@attrs[:geo]) unless @attrs[:geo].nil? end # @note Must include entities in your request for this method to work # @return [Array] def hashtags - @hashtags ||= unless @attrs['entities'].nil? - Array(@attrs['entities']['hashtags']).map do |hashtag| + @hashtags ||= unless @attrs[:entities].nil? + Array(@attrs[:entities][:hashtags]).map do |hashtag| Twitter::Entity::Hashtag.fetch_or_new(hashtag) end else @@ -62,8 +62,8 @@ def hashtags # @note Must include entities in your request for this method to work # @return [Array] def media - @media ||= unless @attrs['entities'].nil? - Array(@attrs['entities']['media']).map do |media| + @media ||= unless @attrs[:entities].nil? + Array(@attrs[:entities][:media]).map do |media| Twitter::MediaFactory.new(media) end else @@ -73,23 +73,23 @@ def media # @return [Twitter::Metadata] def metadata - @metadata ||= Twitter::Metadata.fetch_or_new(@attrs['metadata']) unless @attrs['metadata'].nil? + @metadata ||= Twitter::Metadata.fetch_or_new(@attrs[:metadata]) unless @attrs[:metadata].nil? end # @return [Twitter::OEmbed] def oembed(options={}) @client ||= Twitter::Client.new - @client.oembed(@attrs['id'], options) unless @attrs['id'].nil? + @client.oembed(@attrs[:id], options) unless @attrs[:id].nil? end # @return [Twitter::Place] def place - @place ||= Twitter::Place.fetch_or_new(@attrs['place']) unless @attrs['place'].nil? + @place ||= Twitter::Place.fetch_or_new(@attrs[:place]) unless @attrs[:place].nil? end # @return [Integer] def repliers_count - @repliers_count ||= @attrs['repliers_count'] + @repliers_count ||= @attrs[:repliers_count] @repliers_count.to_i if @repliers_count end alias reply_count repliers_count @@ -98,12 +98,12 @@ def repliers_count # # @return [Twitter::Status] def retweeted_status - @retweeted_status ||= self.class.fetch_or_new(@attrs['retweeted_status']) unless @attrs['retweeted_status'].nil? + @retweeted_status ||= self.class.fetch_or_new(@attrs[:retweeted_status]) unless @attrs[:retweeted_status].nil? end # @return [String] def retweeters_count - @retweeters_count ||= (@attrs['retweet_count'] || @attrs['retweeters_count']) + @retweeters_count ||= (@attrs[:retweet_count] || @attrs[:retweeters_count]) @retweeters_count.to_i if @retweeters_count end alias retweet_count retweeters_count @@ -111,8 +111,8 @@ def retweeters_count # @note Must include entities in your request for this method to work # @return [Array] def urls - @urls ||= unless @attrs['entities'].nil? - Array(@attrs['entities']['urls']).map do |url| + @urls ||= unless @attrs[:entities].nil? + Array(@attrs[:entities][:urls]).map do |url| Twitter::Entity::Url.fetch_or_new(url) end else @@ -122,14 +122,14 @@ def urls # @return [Twitter::User] def user - @user ||= Twitter::User.fetch_or_new(@attrs.dup['user'].merge('status' => @attrs.except('user'))) unless @attrs['user'].nil? + @user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => @attrs.except(:user))) unless @attrs[:user].nil? end # @note Must include entities in your request for this method to work # @return [Array] def user_mentions - @user_mentions ||= unless @attrs['entities'].nil? - Array(@attrs['entities']['user_mentions']).map do |user_mention| + @user_mentions ||= unless @attrs[:entities].nil? + Array(@attrs[:entities][:user_mentions]).map do |user_mention| Twitter::Entity::UserMention.fetch_or_new(user_mention) end else diff --git a/lib/twitter/suggestion.rb b/lib/twitter/suggestion.rb index 707a57502..c953bc99c 100644 --- a/lib/twitter/suggestion.rb +++ b/lib/twitter/suggestion.rb @@ -13,7 +13,7 @@ def ==(other) # @return [Array] def users - @users = Array(@attrs['users']).map do |user| + @users = Array(@attrs[:users]).map do |user| Twitter::User.fetch_or_new(user) end end diff --git a/lib/twitter/user.rb b/lib/twitter/user.rb index 34bbdabed..99d4985e8 100644 --- a/lib/twitter/user.rb +++ b/lib/twitter/user.rb @@ -52,7 +52,7 @@ class User < Twitter::Identifiable # @return [Twitter::Status] def status - @status ||= Twitter::Status.fetch_or_new(@attrs.dup['status'].merge('user' => @attrs.except('status'))) unless @attrs['status'].nil? + @status ||= Twitter::Status.fetch_or_new(@attrs.dup[:status].merge(:user => @attrs.except(:status))) unless @attrs[:status].nil? end end diff --git a/spec/twitter/action/favorite_spec.rb b/spec/twitter/action/favorite_spec.rb index 2cd6aa42f..e9ef2f15e 100644 --- a/spec/twitter/action/favorite_spec.rb +++ b/spec/twitter/action/favorite_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who favorited a status" do - sources = Twitter::Action::Favorite.new('sources' => [{}]).sources + sources = Twitter::Action::Favorite.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#targets" do it "returns a collection containing the favorited status" do - targets = Twitter::Action::Favorite.new('targets' => [{}]).targets + targets = Twitter::Action::Favorite.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::Status end diff --git a/spec/twitter/action/follow_spec.rb b/spec/twitter/action/follow_spec.rb index 42069df5f..473caea88 100644 --- a/spec/twitter/action/follow_spec.rb +++ b/spec/twitter/action/follow_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who followed a user" do - sources = Twitter::Action::Follow.new('sources' => [{}]).sources + sources = Twitter::Action::Follow.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#targets" do it "returns a collection containing the followed user" do - targets = Twitter::Action::Follow.new('targets' => [{}]).targets + targets = Twitter::Action::Follow.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::User end diff --git a/spec/twitter/action/list_member_added_spec.rb b/spec/twitter/action/list_member_added_spec.rb index 6367109e6..326e4464e 100644 --- a/spec/twitter/action/list_member_added_spec.rb +++ b/spec/twitter/action/list_member_added_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who added a user to a list" do - sources = Twitter::Action::ListMemberAdded.new('sources' => [{}]).sources + sources = Twitter::Action::ListMemberAdded.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#target_objects" do it "returns a collection of lists that were added to" do - targets = Twitter::Action::ListMemberAdded.new('target_objects' => [{}]).target_objects + targets = Twitter::Action::ListMemberAdded.new(:target_objects => [{}]).target_objects targets.should be_an Array targets.first.should be_a Twitter::List end @@ -28,7 +28,7 @@ describe "#targets" do it "returns a collection of users who were added to a list" do - targets = Twitter::Action::ListMemberAdded.new('targets' => [{}]).targets + targets = Twitter::Action::ListMemberAdded.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::User end diff --git a/spec/twitter/action/mention_spec.rb b/spec/twitter/action/mention_spec.rb index 37b9f0e9d..0a633f539 100644 --- a/spec/twitter/action/mention_spec.rb +++ b/spec/twitter/action/mention_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who mentioned a user" do - sources = Twitter::Action::Mention.new('sources' => [{}]).sources + sources = Twitter::Action::Mention.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#source" do it "returns the user who mentioned a user" do - source = Twitter::Action::Mention.new('sources' => [{}]).source + source = Twitter::Action::Mention.new(:sources => [{}]).source source.should be_a Twitter::User end it "returns nil when not set" do @@ -27,7 +27,7 @@ describe "#target_objects" do it "returns a collection of statuses that mention a user" do - targets = Twitter::Action::Mention.new('target_objects' => [{}]).target_objects + targets = Twitter::Action::Mention.new(:target_objects => [{}]).target_objects targets.should be_an Array targets.first.should be_a Twitter::Status end @@ -39,7 +39,7 @@ describe "#targets" do it "returns a collection containing the mentioned user" do - targets = Twitter::Action::Mention.new('targets' => [{}]).targets + targets = Twitter::Action::Mention.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::User end diff --git a/spec/twitter/action/reply_spec.rb b/spec/twitter/action/reply_spec.rb index 9cdb941c4..93acc7032 100644 --- a/spec/twitter/action/reply_spec.rb +++ b/spec/twitter/action/reply_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who replied to a user" do - sources = Twitter::Action::Reply.new('sources' => [{}]).sources + sources = Twitter::Action::Reply.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#target_objects" do it "returns a collection of statuses that reply to a user" do - targets = Twitter::Action::Reply.new('target_objects' => [{}]).target_objects + targets = Twitter::Action::Reply.new(:target_objects => [{}]).target_objects targets.should be_an Array targets.first.should be_a Twitter::Status end @@ -28,7 +28,7 @@ describe "#targets" do it "returns a collection that contains the replied-to status" do - targets = Twitter::Action::Reply.new('targets' => [{}]).targets + targets = Twitter::Action::Reply.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::Status end diff --git a/spec/twitter/action/retweet_spec.rb b/spec/twitter/action/retweet_spec.rb index c1de8eca1..9f655c189 100644 --- a/spec/twitter/action/retweet_spec.rb +++ b/spec/twitter/action/retweet_spec.rb @@ -4,7 +4,7 @@ describe "#sources" do it "returns a collection of users who retweeted a user" do - sources = Twitter::Action::Retweet.new('sources' => [{}]).sources + sources = Twitter::Action::Retweet.new(:sources => [{}]).sources sources.should be_an Array sources.first.should be_a Twitter::User end @@ -16,7 +16,7 @@ describe "#target_objects" do it "returns a collection of retweets" do - targets = Twitter::Action::Retweet.new('target_objects' => [{}]).target_objects + targets = Twitter::Action::Retweet.new(:target_objects => [{}]).target_objects targets.should be_an Array targets.first.should be_a Twitter::Status end @@ -28,7 +28,7 @@ describe "#targets" do it "returns a collection containing the retweeted user" do - targets = Twitter::Action::Retweet.new('targets' => [{}]).targets + targets = Twitter::Action::Retweet.new(:targets => [{}]).targets targets.should be_an Array targets.first.should be_a Twitter::User end diff --git a/spec/twitter/action_factory_spec.rb b/spec/twitter/action_factory_spec.rb index 07325947d..80bcf494e 100644 --- a/spec/twitter/action_factory_spec.rb +++ b/spec/twitter/action_factory_spec.rb @@ -4,33 +4,33 @@ describe ".new" do it "generates a Favorite" do - action = Twitter::ActionFactory.new('action' => 'favorite') + action = Twitter::ActionFactory.new(:action => 'favorite') action.should be_a Twitter::Action::Favorite end it "generates a Follow" do - action = Twitter::ActionFactory.new('action' => 'follow') + action = Twitter::ActionFactory.new(:action => 'follow') action.should be_a Twitter::Action::Follow end it "generates a ListMemberAdded" do - action = Twitter::ActionFactory.new('action' => 'list_member_added') + action = Twitter::ActionFactory.new(:action => 'list_member_added') action.should be_a Twitter::Action::ListMemberAdded end it "generates a Mention" do - action = Twitter::ActionFactory.new('action' => 'mention') + action = Twitter::ActionFactory.new(:action => 'mention') action.should be_a Twitter::Action::Mention end it "generates a Reply" do - action = Twitter::ActionFactory.new('action' => 'reply') + action = Twitter::ActionFactory.new(:action => 'reply') action.should be_a Twitter::Action::Reply end it "generates a Retweet" do - action = Twitter::ActionFactory.new('action' => 'retweet') + action = Twitter::ActionFactory.new(:action => 'retweet') action.should be_a Twitter::Action::Retweet end it "raises an ArgumentError when action is not specified" do lambda do Twitter::ActionFactory.new - end.should raise_error(ArgumentError, "argument must have an 'action' key") + end.should raise_error(ArgumentError, "argument must have an :action key") end end diff --git a/spec/twitter/action_spec.rb b/spec/twitter/action_spec.rb index 384f7106d..074e80e27 100644 --- a/spec/twitter/action_spec.rb +++ b/spec/twitter/action_spec.rb @@ -4,7 +4,7 @@ describe "#created_at" do it "returns a Time when created_at is set" do - user = Twitter::User.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + user = Twitter::User.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") user.created_at.should be_a Time end it "returns nil when created_at is not set" do diff --git a/spec/twitter/base_spec.rb b/spec/twitter/base_spec.rb index 45f8edf0f..2b1660af8 100644 --- a/spec/twitter/base_spec.rb +++ b/spec/twitter/base_spec.rb @@ -3,7 +3,7 @@ describe Twitter::Base do before do - @base = Twitter::Base.new('id' => 1) + @base = Twitter::Base.new(:id => 1) end describe "#[]" do @@ -22,13 +22,13 @@ describe "#to_hash" do it "returns a hash" do @base.to_hash.should be_a Hash - @base.to_hash['id'].should eq 1 + @base.to_hash[:id].should eq 1 end end describe "identical objects" do it "have the same object_id" do - @base.object_id.should eq Twitter::Base.fetch('id' => 1).object_id + @base.object_id.should eq Twitter::Base.fetch(:id => 1).object_id end end diff --git a/spec/twitter/client/accounts_spec.rb b/spec/twitter/client/accounts_spec.rb index 42778d297..a3ce8f23e 100644 --- a/spec/twitter/client/accounts_spec.rb +++ b/spec/twitter/client/accounts_spec.rb @@ -52,7 +52,7 @@ end it "returns a null cookie" do end_session = @client.end_session - end_session['error'].should eq "Logged out." + end_session[:error].should eq "Logged out." end end diff --git a/spec/twitter/client/friends_and_followers_spec.rb b/spec/twitter/client/friends_and_followers_spec.rb index f16fec4bb..49262115c 100644 --- a/spec/twitter/client/friends_and_followers_spec.rb +++ b/spec/twitter/client/friends_and_followers_spec.rb @@ -134,8 +134,8 @@ to_return(:body => fixture("true.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('screen_name' => 'sferik') - user2 = Twitter::User.new('screen_name' => 'pengwynn') + user1 = Twitter::User.new(:screen_name => 'sferik') + user2 = Twitter::User.new(:screen_name => 'pengwynn') @client.friendship?(user1, user2) a_get("/1/friendships/exists.json"). with(:query => {:screen_name_a => "sferik", :screen_name_b => "pengwynn"}). @@ -149,8 +149,8 @@ to_return(:body => fixture("true.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('id' => '7505382') - user2 = Twitter::User.new('id' => '14100886') + user1 = Twitter::User.new(:id => '7505382') + user2 = Twitter::User.new(:id => '14100886') @client.friendship?(user1, user2) a_get("/1/friendships/exists.json"). with(:query => {:user_id_a => "7505382", :user_id_b => "14100886"}). @@ -253,8 +253,8 @@ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('screen_name' => 'sferik') - user2 = Twitter::User.new('screen_name' => 'pengwynn') + user1 = Twitter::User.new(:screen_name => 'sferik') + user2 = Twitter::User.new(:screen_name => 'pengwynn') @client.friendship(user1, user2) a_get("/1/friendships/show.json"). with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}). @@ -268,8 +268,8 @@ to_return(:body => fixture("relationship.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('id' => '7505382') - user2 = Twitter::User.new('id' => '14100886') + user1 = Twitter::User.new(:id => '7505382') + user2 = Twitter::User.new(:id => '14100886') @client.friendship(user1, user2) a_get("/1/friendships/show.json"). with(:query => {:source_id => "7505382", :target_id => "14100886"}). diff --git a/spec/twitter/client/lists_spec.rb b/spec/twitter/client/lists_spec.rb index 7a383b94b..ac50ee5bb 100644 --- a/spec/twitter/client/lists_spec.rb +++ b/spec/twitter/client/lists_spec.rb @@ -330,7 +330,7 @@ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('slug' => 'presidents', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:slug => 'presidents', :user => {:screen_name => 'sferik'}) @client.list_subscriber?(list, 813286) a_get("/1/lists/subscribers/show.json"). with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}). @@ -344,7 +344,7 @@ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('id' => 12345678, 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:id => 12345678, :user => {:screen_name => 'sferik'}) @client.list_subscriber?(list, 813286) a_get("/1/lists/subscribers/show.json"). with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}). @@ -582,7 +582,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('slug' => 'presidents', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:slug => 'presidents', :user => {:screen_name => 'sferik'}) @client.list_member?(list, 813286) a_get("/1/lists/members/show.json"). with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}). @@ -596,7 +596,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('id' => 12345678, 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:id => 12345678, :user => {:screen_name => 'sferik'}) @client.list_member?(list, 813286) a_get("/1/lists/members/show.json"). with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}). @@ -763,7 +763,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('slug' => 'presidents', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:slug => 'presidents', :user => {:screen_name => 'sferik'}) @client.list_destroy(list) a_delete("/1/lists/destroy.json"). with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}). @@ -777,7 +777,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('id' => '12345678', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:id => '12345678', :user => {:screen_name => 'sferik'}) @client.list_destroy(list) a_delete("/1/lists/destroy.json"). with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'}). @@ -842,7 +842,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('slug' => 'presidents', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:slug => 'presidents', :user => {:screen_name => 'sferik'}) @client.list_update(list, :description => "Presidents of the United States of America") a_post("/1/lists/update.json"). with(:body => {:owner_screen_name => 'sferik', :slug => "presidents", :description => "Presidents of the United States of America"}). @@ -856,7 +856,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('id' => '12345678', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:id => '12345678', :user => {:screen_name => 'sferik'}) @client.list_update(list, :description => "Presidents of the United States of America") a_post("/1/lists/update.json"). with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :description => "Presidents of the United States of America"}). @@ -968,7 +968,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user = Twitter::User.new('id' => '12345678') + user = Twitter::User.new(:id => '12345678') @client.list(user, 'presidents') a_get("/1/lists/show.json"). with(:query => {:owner_id => '12345678', :slug => 'presidents'}). @@ -982,7 +982,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user = Twitter::User.new('screen_name' => 'sferik') + user = Twitter::User.new(:screen_name => 'sferik') @client.list(user, "presidents") a_get("/1/lists/show.json"). with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}). @@ -1026,7 +1026,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('slug' => 'presidents', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:slug => 'presidents', :user => {:screen_name => 'sferik'}) @client.list(list) a_get("/1/lists/show.json"). with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}). @@ -1040,7 +1040,7 @@ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new('id' => '12345678', 'user' => {'screen_name' => 'sferik'}) + list = Twitter::List.new(:id => '12345678', :user => {:screen_name => 'sferik'}) @client.list(list) a_get("/1/lists/show.json"). with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'}). diff --git a/spec/twitter/client/trends_spec.rb b/spec/twitter/client/trends_spec.rb index 7c2c73b66..ed20b9439 100644 --- a/spec/twitter/client/trends_spec.rb +++ b/spec/twitter/client/trends_spec.rb @@ -21,9 +21,9 @@ it "returns the top 20 trending topics for each hour in a given day" do trends = @client.trends_daily(Date.parse("2010-10-24")) trends.should be_a Hash - trends["2010-10-24 17:00"].should be_an Array - trends["2010-10-24 17:00"].first.should be_a Twitter::Trend - trends["2010-10-24 17:00"].first.name.should eq "#bigbangcomeback" + trends["2010-10-24 17:00".to_sym].should be_an Array + trends["2010-10-24 17:00".to_sym].first.should be_a Twitter::Trend + trends["2010-10-24 17:00".to_sym].first.name.should eq "#bigbangcomeback" end end @@ -42,9 +42,9 @@ it "returns the top 30 trending topics for each day in a given week" do trends = @client.trends_weekly(Date.parse("2010-10-24")) trends.should be_a Hash - trends["2010-10-24"].should be_an Array - trends["2010-10-24"].first.should be_a Twitter::Trend - trends["2010-10-24"].first.name.should eq "#youcantbeuglyand" + trends["2010-10-24".to_sym].should be_an Array + trends["2010-10-24".to_sym].first.should be_a Twitter::Trend + trends["2010-10-24".to_sym].first.name.should eq "#youcantbeuglyand" end end diff --git a/spec/twitter/client/tweets_spec.rb b/spec/twitter/client/tweets_spec.rb index bb2f7c529..b6a67c4af 100644 --- a/spec/twitter/client/tweets_spec.rb +++ b/spec/twitter/client/tweets_spec.rb @@ -243,12 +243,12 @@ end context "an IO" do it "requests the correct resource" do - @client.update_with_media("You always have options", {'io' => StringIO.new, 'type' => 'gif'}) + @client.update_with_media("You always have options", {:io => StringIO.new, :type => 'gif'}) a_post("/1/statuses/update_with_media.json", Twitter.media_endpoint). should have_been_made end it 'returns the media as an entity' do - status = @client.update_with_media("You always have options", {'io' => StringIO.new, 'type' => 'gif'}) + status = @client.update_with_media("You always have options", {:io => StringIO.new, :type => 'gif'}) status.media.should be end end diff --git a/spec/twitter/client/users_spec.rb b/spec/twitter/client/users_spec.rb index a8c50fb68..022af5ecb 100644 --- a/spec/twitter/client/users_spec.rb +++ b/spec/twitter/client/users_spec.rb @@ -73,8 +73,8 @@ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('id' => '7505382') - user2 = Twitter::User.new('id' => '14100886') + user1 = Twitter::User.new(:id => '7505382') + user2 = Twitter::User.new(:id => '14100886') @client.users(user1, user2) a_get("/1/users/lookup.json"). with(:query => {:user_id => "7505382,14100886"}). @@ -88,8 +88,8 @@ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('screen_name' => 'sferik') - user2 = Twitter::User.new('screen_name' => 'pengwynn') + user1 = Twitter::User.new(:screen_name => 'sferik') + user2 = Twitter::User.new(:screen_name => 'pengwynn') @client.users(user1, user2) a_get("/1/users/lookup.json"). with(:query => {:screen_name => "sferik,pengwynn"}). @@ -103,8 +103,8 @@ to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new('screen_name' => 'sferik') - user2 = Twitter::User.new('id' => '14100886') + user1 = Twitter::User.new(:screen_name => 'sferik') + user2 = Twitter::User.new(:id => '14100886') @client.users(user1, user2) a_get("/1/users/lookup.json"). with(:query => {:screen_name => "sferik", :user_id => "14100886"}). @@ -200,7 +200,7 @@ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user = Twitter::User.new('id' => 7505382) + user = Twitter::User.new(:id => 7505382) @client.user(user) a_get("/1/users/show.json"). with(:query => {:user_id => "7505382"}). @@ -214,7 +214,7 @@ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user = Twitter::User.new('screen_name' => 'sferik') + user = Twitter::User.new(:screen_name => 'sferik') @client.user(user) a_get("/1/users/show.json"). with(:query => {:screen_name => "sferik"}). diff --git a/spec/twitter/configuration_spec.rb b/spec/twitter/configuration_spec.rb index 8437cd240..258caccae 100644 --- a/spec/twitter/configuration_spec.rb +++ b/spec/twitter/configuration_spec.rb @@ -4,9 +4,9 @@ describe "#photo_sizes" do it "returns a hash of sizes when photo_sizes is set" do - photo_sizes = Twitter::Configuration.new('photo_sizes' => {'small' => {'h' => 226, 'w' => 340, 'resize' => 'fit'}, 'large' => {'h' => 466, 'w' => 700, 'resize' => 'fit'}, 'medium' => {'h' => 399, 'w' => 600, 'resize' => 'fit'}, 'thumb' => {'h' => 150, 'w' => 150, 'resize' => 'crop'}}).photo_sizes + photo_sizes = Twitter::Configuration.new(:photo_sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).photo_sizes photo_sizes.should be_a Hash - photo_sizes['small'].should be_a Twitter::Size + photo_sizes[:small].should be_a Twitter::Size end it "is empty when photo_sizes is not set" do photo_sizes = Twitter::Configuration.new().photo_sizes diff --git a/spec/twitter/cursor_spec.rb b/spec/twitter/cursor_spec.rb index f3fd41f0c..a18362af7 100644 --- a/spec/twitter/cursor_spec.rb +++ b/spec/twitter/cursor_spec.rb @@ -5,7 +5,7 @@ describe "#first?" do context "when previous cursor equals zero" do before do - @cursor = Twitter::Cursor.new('previous_cursor' => 0) + @cursor = Twitter::Cursor.new(:previous_cursor => 0) end it "returns true" do @cursor.first?.should be_true @@ -13,7 +13,7 @@ end context "when previous cursor does not equal zero" do before do - @cursor = Twitter::Cursor.new('previous_cursor' => 1) + @cursor = Twitter::Cursor.new(:previous_cursor => 1) end it "returns true" do @cursor.first?.should be_false @@ -24,7 +24,7 @@ describe "#last?" do context "when next cursor equals zero" do before do - @cursor = Twitter::Cursor.new('next_cursor' => 0) + @cursor = Twitter::Cursor.new(:next_cursor => 0) end it "returns true" do @cursor.last?.should be_true @@ -32,7 +32,7 @@ end context "when next cursor does not equal zero" do before do - @cursor = Twitter::Cursor.new('next_cursor' => 1) + @cursor = Twitter::Cursor.new(:next_cursor => 1) end it "returns false" do @cursor.last?.should be_false diff --git a/spec/twitter/direct_message_spec.rb b/spec/twitter/direct_message_spec.rb index 46cdb34aa..a3dc2ea5c 100644 --- a/spec/twitter/direct_message_spec.rb +++ b/spec/twitter/direct_message_spec.rb @@ -4,25 +4,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - direct_message = Twitter::DirectMessage.new('id' => 1) - other = Twitter::DirectMessage.new('id' => 1) + direct_message = Twitter::DirectMessage.new(:id => 1) + other = Twitter::DirectMessage.new(:id => 1) (direct_message == other).should be_true end it "returns false when classes are not equal" do - direct_message = Twitter::DirectMessage.new('id' => 1) - other = Twitter::User.new('id' => 1) + direct_message = Twitter::DirectMessage.new(:id => 1) + other = Twitter::User.new(:id => 1) (direct_message == other).should be_false end it "returns false when ids are not equal" do - direct_message = Twitter::DirectMessage.new('id' => 1) - other = Twitter::DirectMessage.new('id' => 2) + direct_message = Twitter::DirectMessage.new(:id => 1) + other = Twitter::DirectMessage.new(:id => 2) (direct_message == other).should be_false end end describe "#created_at" do it "returns a Time when created_at is set" do - direct_message = Twitter::DirectMessage.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + direct_message = Twitter::DirectMessage.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") direct_message.created_at.should be_a Time end it "returns nil when created_at is not set" do @@ -33,7 +33,7 @@ describe "#recipient" do it "returns a User when recipient is set" do - recipient = Twitter::DirectMessage.new('recipient' => {}).recipient + recipient = Twitter::DirectMessage.new(:recipient => {}).recipient recipient.should be_a Twitter::User end it "returns nil when status is not set" do @@ -44,7 +44,7 @@ describe "#sender" do it "returns a User when sender is set" do - sender = Twitter::DirectMessage.new('sender' => {}).sender + sender = Twitter::DirectMessage.new(:sender => {}).sender sender.should be_a Twitter::User end it "returns nil when status is not set" do diff --git a/spec/twitter/geo_factory_spec.rb b/spec/twitter/geo_factory_spec.rb index 8f329d201..ed02c8772 100644 --- a/spec/twitter/geo_factory_spec.rb +++ b/spec/twitter/geo_factory_spec.rb @@ -4,17 +4,17 @@ describe ".new" do it "generates a Point" do - geo = Twitter::GeoFactory.new('type' => 'Point') + geo = Twitter::GeoFactory.new(:type => 'Point') geo.should be_a Twitter::Point end it "generates a Polygon" do - geo = Twitter::GeoFactory.new('type' => 'Polygon') + geo = Twitter::GeoFactory.new(:type => 'Polygon') geo.should be_a Twitter::Polygon end it "raises an ArgumentError when type is not specified" do lambda do Twitter::GeoFactory.new - end.should raise_error(ArgumentError, "argument must have a 'type' key") + end.should raise_error(ArgumentError, "argument must have a :type key") end end diff --git a/spec/twitter/list_spec.rb b/spec/twitter/list_spec.rb index 3175bfb76..44631cf0c 100644 --- a/spec/twitter/list_spec.rb +++ b/spec/twitter/list_spec.rb @@ -4,25 +4,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - list = Twitter::List.new('id' => 1) - other = Twitter::List.new('id' => 1) + list = Twitter::List.new(:id => 1) + other = Twitter::List.new(:id => 1) (list == other).should be_true end it "returns false when classes are not equal" do - list = Twitter::List.new('id' => 1) - other = Twitter::User.new('id' => 1) + list = Twitter::List.new(:id => 1) + other = Twitter::User.new(:id => 1) (list == other).should be_false end it "returns false when ids are not equal" do - list = Twitter::List.new('id' => 1) - other = Twitter::List.new('id' => 2) + list = Twitter::List.new(:id => 1) + other = Twitter::List.new(:id => 2) (list == other).should be_false end end describe "#created_at" do it "returns a Time when created_at is set" do - user = Twitter::List.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + user = Twitter::List.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") user.created_at.should be_a Time end it "returns nil when created_at is not set" do @@ -33,7 +33,7 @@ describe "#user" do it "returns a User when user is set" do - user = Twitter::List.new('user' => {}).user + user = Twitter::List.new(:user => {}).user user.should be_a Twitter::User end it "returns nil when status is not set" do diff --git a/spec/twitter/media_factory_spec.rb b/spec/twitter/media_factory_spec.rb index 2ef7230ff..e5d0afd12 100644 --- a/spec/twitter/media_factory_spec.rb +++ b/spec/twitter/media_factory_spec.rb @@ -4,13 +4,13 @@ describe ".new" do it "generates a Photo" do - media = Twitter::MediaFactory.new('type' => 'photo') + media = Twitter::MediaFactory.new(:type => 'photo') media.should be_a Twitter::Photo end it "raises an ArgumentError when type is not specified" do lambda do Twitter::MediaFactory.new - end.should raise_error(ArgumentError, "argument must have a 'type' key") + end.should raise_error(ArgumentError, "argument must have a :type key") end end diff --git a/spec/twitter/oembed_spec.rb b/spec/twitter/oembed_spec.rb index cb79cc322..21f9e73cb 100644 --- a/spec/twitter/oembed_spec.rb +++ b/spec/twitter/oembed_spec.rb @@ -3,7 +3,7 @@ describe Twitter::OEmbed do describe "#author_url" do it "returns the author's url" do - oembed = Twitter::OEmbed.new('author_url' => 'https://twitter.com/sferik') + oembed = Twitter::OEmbed.new(:author_url => 'https://twitter.com/sferik') oembed.author_url.should eq "https://twitter.com/sferik" end @@ -15,7 +15,7 @@ describe "#author_name" do it "returns the author's name" do - oembed = Twitter::OEmbed.new('author_name' => 'Erik Michaels-Ober') + oembed = Twitter::OEmbed.new(:author_name => 'Erik Michaels-Ober') oembed.author_name.should eq "Erik Michaels-Ober" end @@ -27,7 +27,7 @@ describe "#cache_age" do it "returns the cache_age" do - oembed = Twitter::OEmbed.new('cache_age' => '31536000000') + oembed = Twitter::OEmbed.new(:cache_age => '31536000000') oembed.cache_age.should eq "31536000000" end @@ -39,12 +39,12 @@ describe "#height" do it "returns the height" do - oembed = Twitter::OEmbed.new('height' => 200) + oembed = Twitter::OEmbed.new(:height => 200) oembed.height.should eq 200 end it "returns it as an Integer" do - oembed = Twitter::OEmbed.new('height' => 200) + oembed = Twitter::OEmbed.new(:height => 200) oembed.height.should be_an Integer end @@ -56,7 +56,7 @@ describe "#html" do it "returns the html" do - oembed = Twitter::OEmbed.new('html' => '
all my witty tweet stuff here
') + oembed = Twitter::OEmbed.new(:html => '
all my witty tweet stuff here
') oembed.html.should eq "
all my witty tweet stuff here
" end @@ -68,7 +68,7 @@ describe "#provider_name" do it "returns the provider_name" do - oembed = Twitter::OEmbed.new('provider_name' => 'Twitter') + oembed = Twitter::OEmbed.new(:provider_name => 'Twitter') oembed.provider_name.should eq "Twitter" end @@ -80,7 +80,7 @@ describe "#provider_url" do it "returns the provider_url" do - oembed = Twitter::OEmbed.new('provider_url' => 'http://twitter.com') + oembed = Twitter::OEmbed.new(:provider_url => 'http://twitter.com') oembed.provider_url.should eq "http://twitter.com" end @@ -92,7 +92,7 @@ describe "#type" do it "returns the type" do - oembed = Twitter::OEmbed.new('type' => 'rich') + oembed = Twitter::OEmbed.new(:type => 'rich') oembed.type.should eq "rich" end @@ -104,12 +104,12 @@ describe "#width" do it "returns the width" do - oembed = Twitter::OEmbed.new('width' => 550) + oembed = Twitter::OEmbed.new(:width => 550) oembed.width.should eq 550 end it "returns it as an Integer" do - oembed = Twitter::OEmbed.new('width' => 550) + oembed = Twitter::OEmbed.new(:width => 550) oembed.width.should be_an Integer end @@ -121,7 +121,7 @@ describe "#url" do it "returns the url" do - oembed = Twitter::OEmbed.new('url' => 'https://twitter.com/twitterapi/status/133640144317198338') + oembed = Twitter::OEmbed.new(:url => 'https://twitter.com/twitterapi/status/133640144317198338') oembed.url.should eq "https://twitter.com/twitterapi/status/133640144317198338" end @@ -133,7 +133,7 @@ describe "#version" do it "returns the version" do - oembed = Twitter::OEmbed.new('version' => '1.0') + oembed = Twitter::OEmbed.new(:version => '1.0') oembed.version.should eq "1.0" end diff --git a/spec/twitter/photo_spec.rb b/spec/twitter/photo_spec.rb index 6b823d3f8..945ff1dcc 100644 --- a/spec/twitter/photo_spec.rb +++ b/spec/twitter/photo_spec.rb @@ -4,27 +4,27 @@ describe "#==" do it "returns true when ids and classes are equal" do - photo = Twitter::Photo.new('id' => 1) - other = Twitter::Photo.new('id' => 1) + photo = Twitter::Photo.new(:id => 1) + other = Twitter::Photo.new(:id => 1) (photo == other).should be_true end it "returns false when classes are not equal" do - photo = Twitter::Photo.new('id' => 1) - other = Twitter::User.new('id' => 1) + photo = Twitter::Photo.new(:id => 1) + other = Twitter::User.new(:id => 1) (photo == other).should be_false end it "returns false when ids are not equal" do - photo = Twitter::Photo.new('id' => 1) - other = Twitter::Photo.new('id' => 2) + photo = Twitter::Photo.new(:id => 1) + other = Twitter::Photo.new(:id => 2) (photo == other).should be_false end end describe "#sizes" do it "returns a hash of Sizes when sizes is set" do - sizes = Twitter::Photo.new('sizes' => {'small' => {'h' => 226, 'w' => 340, 'resize' => 'fit'}, 'large' => {'h' => 466, 'w' => 700, 'resize' => 'fit'}, 'medium' => {'h' => 399, 'w' => 600, 'resize' => 'fit'}, 'thumb' => {'h' => 150, 'w' => 150, 'resize' => 'crop'}}).sizes + sizes = Twitter::Photo.new(:sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).sizes sizes.should be_a Hash - sizes['small'].should be_a Twitter::Size + sizes[:small].should be_a Twitter::Size end it "is empty when sizes is not set" do sizes = Twitter::Photo.new.sizes diff --git a/spec/twitter/place_spec.rb b/spec/twitter/place_spec.rb index 37cf2d977..b52726ae2 100644 --- a/spec/twitter/place_spec.rb +++ b/spec/twitter/place_spec.rb @@ -4,25 +4,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - place = Twitter::Place.new('id' => 1) - other = Twitter::Place.new('id' => 1) + place = Twitter::Place.new(:id => 1) + other = Twitter::Place.new(:id => 1) (place == other).should be_true end it "returns false when classes are not equal" do - place = Twitter::Place.new('id' => 1) - other = Twitter::User.new('id' => 1) + place = Twitter::Place.new(:id => 1) + other = Twitter::User.new(:id => 1) (place == other).should be_false end it "returns false when ids are not equal" do - place = Twitter::Place.new('id' => 1) - other = Twitter::Place.new('id' => 2) + place = Twitter::Place.new(:id => 1) + other = Twitter::Place.new(:id => 2) (place == other).should be_false end end describe "#bounding_box" do it "returns a Twitter::Place when set" do - place = Twitter::Place.new('bounding_box' => {'type' => 'Polygon', 'coordinates' => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]}) + place = Twitter::Place.new(:bounding_box => {:type => 'Polygon', :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]}) place.bounding_box.should be_a Twitter::Polygon end it "returns nil when not set" do @@ -33,11 +33,11 @@ describe "#country_code" do it "returns a country code when set with country_code" do - place = Twitter::Place.new('country_code' => 'US') + place = Twitter::Place.new(:country_code => 'US') place.country_code.should eq 'US' end it "returns a country code when set with countryCode" do - place = Twitter::Place.new('countryCode' => 'US') + place = Twitter::Place.new(:countryCode => 'US') place.country_code.should eq 'US' end it "returns nil when not set" do @@ -48,7 +48,7 @@ describe "#parent_id" do it "returns a parent ID when set with parentid" do - place = Twitter::Place.new('parentid' => 1) + place = Twitter::Place.new(:parentid => 1) place.parent_id.should eq 1 end it "returns nil when not set" do @@ -59,11 +59,11 @@ describe "#place_type" do it "returns a place type when set with place_type" do - place = Twitter::Place.new('place_type' => 'city') + place = Twitter::Place.new(:place_type => 'city') place.place_type.should eq 'city' end it "returns a place type when set with placeType[name]" do - place = Twitter::Place.new('placeType' => {'name' => 'Town'}) + place = Twitter::Place.new(:placeType => {:name => 'Town'}) place.place_type.should eq 'Town' end it "returns nil when not set" do diff --git a/spec/twitter/point_spec.rb b/spec/twitter/point_spec.rb index 6ee6d6022..8fc1f1cbf 100644 --- a/spec/twitter/point_spec.rb +++ b/spec/twitter/point_spec.rb @@ -3,16 +3,16 @@ describe Twitter::Point do before do - @point = Twitter::Point.new('coordinates' => [-122.399983, 37.788299]) + @point = Twitter::Point.new(:coordinates => [-122.399983, 37.788299]) end describe "#==" do it "returns true when coordinates are equal" do - other = Twitter::Point.new('coordinates' => [-122.399983, 37.788299]) + other = Twitter::Point.new(:coordinates => [-122.399983, 37.788299]) (@point == other).should be_true end it "returns false when coordinates are not equal" do - other = Twitter::Point.new('coordinates' => [37.788299, -122.399983]) + other = Twitter::Point.new(:coordinates => [37.788299, -122.399983]) (@point == other).should be_false end end diff --git a/spec/twitter/polygon_spec.rb b/spec/twitter/polygon_spec.rb index 2e3934d7d..80429923a 100644 --- a/spec/twitter/polygon_spec.rb +++ b/spec/twitter/polygon_spec.rb @@ -3,16 +3,16 @@ describe Twitter::Polygon do before do - @polygon = Twitter::Polygon.new('coordinates' => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]) + @polygon = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]) end describe "#==" do it "returns true when coordinates are equal" do - other = Twitter::Polygon.new('coordinates' => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]) + other = Twitter::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]) (@polygon == other).should be_true end it "returns false when coordinates are not equal" do - other = Twitter::Polygon.new('coordinates' => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]]) + other = Twitter::Polygon.new(:coordinates => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]]) (@polygon == other).should be_false end end diff --git a/spec/twitter/rate_limit_status_spec.rb b/spec/twitter/rate_limit_status_spec.rb index 9e5ed831d..f0c65c573 100644 --- a/spec/twitter/rate_limit_status_spec.rb +++ b/spec/twitter/rate_limit_status_spec.rb @@ -4,7 +4,7 @@ describe "#reset_time" do it "returns a Time when reset_time is set" do - rate_limit_status = Twitter::RateLimitStatus.new('reset_time' => "Mon Jul 16 12:59:01 +0000 2007") + rate_limit_status = Twitter::RateLimitStatus.new(:reset_time => "Mon Jul 16 12:59:01 +0000 2007") rate_limit_status.reset_time.should be_a Time end it "returns nil when reset_time is not set" do diff --git a/spec/twitter/relationship_spec.rb b/spec/twitter/relationship_spec.rb index 9830c788b..fbcd8b1f3 100644 --- a/spec/twitter/relationship_spec.rb +++ b/spec/twitter/relationship_spec.rb @@ -4,7 +4,7 @@ describe "#source" do it "returns a User when source is set" do - source = Twitter::Relationship.new('relationship' => {'source' => {}}).source + source = Twitter::Relationship.new(:relationship => {:source => {}}).source source.should be_a Twitter::User end it "returns nil when source is not set" do @@ -15,7 +15,7 @@ describe "#target" do it "returns a User when target is set" do - target = Twitter::Relationship.new('relationship' => {'target' => {}}).target + target = Twitter::Relationship.new(:relationship => {:target => {}}).target target.should be_a Twitter::User end it "returns nil when target is not set" do diff --git a/spec/twitter/saved_search_spec.rb b/spec/twitter/saved_search_spec.rb index 09832d5b1..fdd76de44 100644 --- a/spec/twitter/saved_search_spec.rb +++ b/spec/twitter/saved_search_spec.rb @@ -4,25 +4,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - saved_search = Twitter::SavedSearch.new('id' => 1) - other = Twitter::SavedSearch.new('id' => 1) + saved_search = Twitter::SavedSearch.new(:id => 1) + other = Twitter::SavedSearch.new(:id => 1) (saved_search == other).should be_true end it "returns false when classes are not equal" do - saved_search = Twitter::SavedSearch.new('id' => 1) - other = Twitter::User.new('id' => 1) + saved_search = Twitter::SavedSearch.new(:id => 1) + other = Twitter::User.new(:id => 1) (saved_search == other).should be_false end it "returns false when ids are not equal" do - saved_search = Twitter::SavedSearch.new('id' => 1) - other = Twitter::SavedSearch.new('id' => 2) + saved_search = Twitter::SavedSearch.new(:id => 1) + other = Twitter::SavedSearch.new(:id => 2) (saved_search == other).should be_false end end describe "#created_at" do it "returns a Time when created_at is set" do - saved_search = Twitter::SavedSearch.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + saved_search = Twitter::SavedSearch.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") saved_search.created_at.should be_a Time end it "returns nil when created_at is not set" do diff --git a/spec/twitter/search_results_spec.rb b/spec/twitter/search_results_spec.rb index 2eaabad0f..6271be84e 100644 --- a/spec/twitter/search_results_spec.rb +++ b/spec/twitter/search_results_spec.rb @@ -4,7 +4,7 @@ describe "#results" do it "contains twitter status objects" do - search_results = Twitter::SearchResults.new('results' => [{'text' => 'tweet!'}]) + search_results = Twitter::SearchResults.new(:results => [{:text => 'tweet!'}]) search_results.results.should be_a Array search_results.results.first.should be_a Twitter::Status end diff --git a/spec/twitter/settings_spec.rb b/spec/twitter/settings_spec.rb index 96ed3c65d..3acc82a69 100644 --- a/spec/twitter/settings_spec.rb +++ b/spec/twitter/settings_spec.rb @@ -4,7 +4,7 @@ describe "#trend_location" do it "returns a Twitter::Place when set" do - place = Twitter::Settings.new('trend_location' => [{'countryCode' => 'US', 'name' => 'San Francisco', 'country' => 'United States', 'placeType' => {'name' => 'Town', 'code' => 7}, 'woeid' => 2487956, 'parentid' => 23424977, 'url' => 'http://where.yahooapis.com/v1/place/2487956'}]) + place = Twitter::Settings.new(:trend_location => [{:countryCode => 'US', :name => 'San Francisco', :country => 'United States', :placeType => {:name => 'Town', :code => 7}, :woeid => 2487956, :parentid => 23424977, :url => 'http://where.yahooapis.com/v1/place/2487956'}]) place.trend_location.should be_a Twitter::Place end it "returns nil when not set" do diff --git a/spec/twitter/size_spec.rb b/spec/twitter/size_spec.rb index 7ea3523d3..e0edb0ead 100644 --- a/spec/twitter/size_spec.rb +++ b/spec/twitter/size_spec.rb @@ -4,13 +4,13 @@ describe "#==" do it "returns true when height and width are equal" do - size = Twitter::Size.new('h' => 1, 'w' => 1) - other = Twitter::Size.new('h' => 1, 'w' => 1) + size = Twitter::Size.new(:h => 1, :w => 1) + other = Twitter::Size.new(:h => 1, :w => 1) (size == other).should be_true end it "returns false when height and width are not equal" do - size = Twitter::Size.new('h' => 1, 'w' => 1) - other = Twitter::Size.new('h' => 1, 'w' => 2) + size = Twitter::Size.new(:h => 1, :w => 1) + other = Twitter::Size.new(:h => 1, :w => 2) (size == other).should be_false end end diff --git a/spec/twitter/status_spec.rb b/spec/twitter/status_spec.rb index ddb93226f..3c467fd88 100644 --- a/spec/twitter/status_spec.rb +++ b/spec/twitter/status_spec.rb @@ -13,25 +13,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - status = Twitter::Status.new('id' => 1) - other = Twitter::Status.new('id' => 1) + status = Twitter::Status.new(:id => 1) + other = Twitter::Status.new(:id => 1) (status == other).should be_true end it "returns false when classes are not equal" do - status = Twitter::Status.new('id' => 1) - other = Twitter::User.new('id' => 1) + status = Twitter::Status.new(:id => 1) + other = Twitter::User.new(:id => 1) (status == other).should be_false end it "returns false when ids are not equal" do - status = Twitter::Status.new('id' => 1) - other = Twitter::Status.new('id' => 2) + status = Twitter::Status.new(:id => 1) + other = Twitter::Status.new(:id => 2) (status == other).should be_false end end describe "#created_at" do it "returns a Time when set" do - status = Twitter::Status.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + status = Twitter::Status.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") status.created_at.should be_a Time end it "returns nil when not set" do @@ -42,7 +42,7 @@ describe "#favoriters_count" do it "returns the count of favoriters when favoriters_count is set" do - status = Twitter::Status.new('favoriters_count' => '1') + status = Twitter::Status.new(:favoriters_count => '1') status.favoriters_count.should be_an Integer status.favoriters_count.should eq 1 end @@ -54,12 +54,12 @@ describe "#from_user" do it "returns a screen name when from_user is set" do - status = Twitter::Status.new('from_user' => 'sferik') + status = Twitter::Status.new(:from_user => 'sferik') status.from_user.should be_a String status.from_user.should eq "sferik" end it "returns a screen name when screen_name is set" do - status = Twitter::Status.new('user' => {'screen_name' => 'sferik'}) + status = Twitter::Status.new(:user => {:screen_name => 'sferik'}) status.from_user.should be_a String status.from_user.should eq "sferik" end @@ -71,17 +71,17 @@ describe "#full_text" do it "returns the text of a status" do - status = Twitter::Status.new('text' => 'BOOSH') + status = Twitter::Status.new(:text => 'BOOSH') status.full_text.should be_a String status.full_text.should eq "BOOSH" end it "returns the text of a status without a user" do - status = Twitter::Status.new('text' => 'BOOSH', 'retweeted_status' => {'text' => 'BOOSH'}) + status = Twitter::Status.new(:text => 'BOOSH', :retweeted_status => {:text => 'BOOSH'}) status.full_text.should be_a String status.full_text.should eq "BOOSH" end it "returns the full text of a retweeted status" do - status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH', 'user' => {'screen_name' => 'sferik'}}) + status = Twitter::Status.new(:retweeted_status => {:text => 'BOOSH', :user => {:screen_name => 'sferik'}}) status.full_text.should be_a String status.full_text.should eq "RT @sferik: BOOSH" end @@ -93,7 +93,7 @@ describe "#geo" do it "returns a Twitter::Point when set" do - status = Twitter::Status.new('geo' => {'type' => 'Point'}) + status = Twitter::Status.new(:geo => {:type => 'Point'}) status.geo.should be_a Twitter::Point end it "returns nil when not set" do @@ -106,11 +106,11 @@ it "returns an Array of Entity::Hashtag when entities are set" do hashtags_hash = [ { - 'text' => 'twitter', - 'indices' => [10, 33], + :text => 'twitter', + :indices => [10, 33], } ] - hashtags = Twitter::Status.new('entities' => {'hashtags' => hashtags_hash}).hashtags + hashtags = Twitter::Status.new(:entities => {:hashtags => hashtags_hash}).hashtags hashtags.should be_an Array hashtags.first.should be_an Twitter::Entity::Hashtag hashtags.first.indices.should eq [10, 33] @@ -128,7 +128,7 @@ describe "#media" do it "returns media" do - media = Twitter::Status.new('entities' => {'media' => [{'type' => 'photo'}]}).media + media = Twitter::Status.new(:entities => {:media => [{:type => 'photo'}]}).media media.should be_an Array media.first.should be_a Twitter::Photo end @@ -144,7 +144,7 @@ describe "#metadata" do it "returns a User when user is set" do - metadata = Twitter::Status.new('metadata' => {}).metadata + metadata = Twitter::Status.new(:metadata => {}).metadata metadata.should be_a Twitter::Metadata end it "returns nil when user is not set" do @@ -157,7 +157,7 @@ before do stub_get("/1/statuses/oembed.json?id=25938088801"). to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - @status = Twitter::Status.new('id' => 25938088801) + @status = Twitter::Status.new(:id => 25938088801) end it "requests the correct resource" do @status.oembed @@ -178,7 +178,7 @@ describe "#place" do it "returns a Twitter::Place when set" do - status = Twitter::Status.new('place' => {}) + status = Twitter::Status.new(:place => {}) status.place.should be_a Twitter::Place end it "returns nil when not set" do @@ -189,7 +189,7 @@ describe "#repliers_count" do it "returns the count of favoriters when repliers_count is set" do - status = Twitter::Status.new('repliers_count' => '1') + status = Twitter::Status.new(:repliers_count => '1') status.repliers_count.should be_an Integer status.repliers_count.should eq 1 end @@ -201,12 +201,12 @@ describe "#retweeters_count" do it "returns the count of favoriters when retweet_count is set" do - status = Twitter::Status.new('retweet_count' => '1') + status = Twitter::Status.new(:retweet_count => '1') status.retweeters_count.should be_an Integer status.retweeters_count.should eq 1 end it "returns the count of favoriters when retweeters_count is set" do - status = Twitter::Status.new('retweeters_count' => '1') + status = Twitter::Status.new(:retweeters_count => '1') status.retweeters_count.should be_an Integer status.retweeters_count.should eq 1 end @@ -218,7 +218,7 @@ describe "#retweeted_status" do it "returns a Status when retweeted_status is set" do - status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'}) + status = Twitter::Status.new(:retweeted_status => {:text => 'BOOSH'}) status.retweeted_status.should be_a Twitter::Status end it "returns nil when retweeted_status is not set" do @@ -226,7 +226,7 @@ status.retweeted_status.should be_nil end it "has text when retweeted_status is set" do - status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'}) + status = Twitter::Status.new(:retweeted_status => {:text => 'BOOSH'}) status.retweeted_status.text.should eq 'BOOSH' end end @@ -235,13 +235,13 @@ it "returns an Array of Entity::Url when entities are set" do urls_hash = [ { - 'url' => 'http://example.com/t.co', - 'expanded_url' => 'http://example.com/expanded', - 'display_url' => 'example.com/expanded', - 'indices' => [10, 33], + :url => 'http://example.com/t.co', + :expanded_url => 'http://example.com/expanded', + :display_url => 'example.com/expanded', + :indices => [10, 33], } ] - urls = Twitter::Status.new('entities' => {'urls' => urls_hash}).urls + urls = Twitter::Status.new(:entities => {:urls => urls_hash}).urls urls.should be_an Array urls.first.should be_an Twitter::Entity::Url urls.first.indices.should eq [10, 33] @@ -259,7 +259,7 @@ describe "#user" do it "returns a User when user is set" do - user = Twitter::Status.new('user' => {}).user + user = Twitter::Status.new(:user => {}).user user.should be_a Twitter::User end it "returns nil when user is not set" do @@ -267,7 +267,7 @@ user.should be_nil end it "has a status when status is set" do - user = Twitter::Status.new('text' => 'Tweet text.', 'user' => {}).user + user = Twitter::Status.new(:text => 'Tweet text.', :user => {}).user user.status.should be_a Twitter::Status user.status.text.should eq 'Tweet text.' end @@ -277,14 +277,14 @@ it "returns an Array of Entity::UserMention when entities are set" do user_mentions_hash = [ { - 'screen_name' => 'sferik', - 'name' => 'Erik Michaels-Ober', - 'id_str' => '7505382', - 'indices' => [0, 6], - 'id' => 7505382, + :screen_name => 'sferik', + :name => 'Erik Michaels-Ober', + :id_str => '7505382', + :indices => [0, 6], + :id => 7505382, } ] - user_mentions = Twitter::Status.new('entities' => {'user_mentions' => user_mentions_hash}).user_mentions + user_mentions = Twitter::Status.new(:entities => {:user_mentions => user_mentions_hash}).user_mentions user_mentions.should be_an Array user_mentions.first.should be_an Twitter::Entity::UserMention user_mentions.first.indices.should eq [0, 6] diff --git a/spec/twitter/suggestion_spec.rb b/spec/twitter/suggestion_spec.rb index a1858bba9..d0845e045 100644 --- a/spec/twitter/suggestion_spec.rb +++ b/spec/twitter/suggestion_spec.rb @@ -3,16 +3,16 @@ describe Twitter::Suggestion do before do - @suggestion = Twitter::Suggestion.new('slug' => 'art-design') + @suggestion = Twitter::Suggestion.new(:slug => 'art-design') end describe "#==" do it "returns true when slugs are equal" do - other = Twitter::Suggestion.new('slug' => 'art-design') + other = Twitter::Suggestion.new(:slug => 'art-design') (@suggestion == other).should be_true end it "returns false when coordinates are not equal" do - other = Twitter::Suggestion.new('slug' => 'design-art') + other = Twitter::Suggestion.new(:slug => 'design-art') (@suggestion == other).should be_false end end diff --git a/spec/twitter/trend_spec.rb b/spec/twitter/trend_spec.rb index 596d6126f..3263e37a5 100644 --- a/spec/twitter/trend_spec.rb +++ b/spec/twitter/trend_spec.rb @@ -3,16 +3,16 @@ describe Twitter::Trend do before do - @trend = Twitter::Trend.new('name' => '#sevenwordsaftersex') + @trend = Twitter::Trend.new(:name => '#sevenwordsaftersex') end describe "#==" do it "returns true when names are equal" do - other = Twitter::Trend.new('name' => '#sevenwordsaftersex') + other = Twitter::Trend.new(:name => '#sevenwordsaftersex') (@trend == other).should be_true end it "returns false when coordinates are not equal" do - other = Twitter::Trend.new('name' => '#sixwordsaftersex') + other = Twitter::Trend.new(:name => '#sixwordsaftersex') (@trend == other).should be_false end end diff --git a/spec/twitter/user_spec.rb b/spec/twitter/user_spec.rb index 6ed8a729e..48dc47e4c 100644 --- a/spec/twitter/user_spec.rb +++ b/spec/twitter/user_spec.rb @@ -4,25 +4,25 @@ describe "#==" do it "returns true when ids and classes are equal" do - user = Twitter::User.new('id' => 1) - other = Twitter::User.new('id' => 1) + user = Twitter::User.new(:id => 1) + other = Twitter::User.new(:id => 1) (user == other).should be_true end it "returns false when classes are not equal" do - user = Twitter::User.new('id' => 1) - other = Twitter::Status.new('id' => 1) + user = Twitter::User.new(:id => 1) + other = Twitter::Status.new(:id => 1) (user == other).should be_false end it "returns false when ids are not equal" do - user = Twitter::User.new('id' => 1) - other = Twitter::User.new('id' => 2) + user = Twitter::User.new(:id => 1) + other = Twitter::User.new(:id => 2) (user == other).should be_false end end describe "#created_at" do it "returns a Time when created_at is set" do - user = Twitter::User.new('created_at' => "Mon Jul 16 12:59:01 +0000 2007") + user = Twitter::User.new(:created_at => "Mon Jul 16 12:59:01 +0000 2007") user.created_at.should be_a Time end it "returns nil when created_at is not set" do @@ -33,7 +33,7 @@ describe "#status" do it "returns a Status when status is set" do - status = Twitter::User.new('status' => {}).status + status = Twitter::User.new(:status => {}).status status.should be_a Twitter::Status end it "returns nil when status is not set" do @@ -41,7 +41,7 @@ status.should be_nil end it "includes a User when user is set" do - status = Twitter::User.new('screen_name' => 'sferik', 'status' => {}).status + status = Twitter::User.new(:screen_name => 'sferik', :status => {}).status status.user.should be_a Twitter::User status.user.screen_name.should eq 'sferik' end