Skip to content

Commit

Permalink
Take a copy of any options hash if we're modifying it.
Browse files Browse the repository at this point in the history
This will not give the caller a surprise if they are using the hash themselves and saves them having to have the knowledge that some calls modify it.
  • Loading branch information
rob-murray authored and sferik committed Jan 19, 2016
1 parent ddc1f1b commit 347c500
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/twitter/rest/direct_messages.rb
Expand Up @@ -58,6 +58,7 @@ def direct_messages_sent(options = {})
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :full_text Returns the full text of a DM when message text is longer than 140 characters.
def direct_message(id, options = {})
options = options.dup
options[:id] = id
perform_get_with_object('/1.1/direct_messages/show.json', options, Twitter::DirectMessage)
end
Expand Down Expand Up @@ -126,6 +127,7 @@ def destroy_direct_message(*args)
# @param text [String] The text of your direct message, up to 10,000 characters.
# @param options [Hash] A customizable set of options.
def create_direct_message(user, text, options = {})
options = options.dup
merge_user!(options, user)
options[:text] = text
perform_post_with_object('/1.1/direct_messages/new.json', options, Twitter::DirectMessage)
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/rest/friends_and_followers.rb
Expand Up @@ -180,6 +180,7 @@ def friendship_update(user, options = {})
# @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
# @param options [Hash] A customizable set of options.
def friendship(source, target, options = {})
options = options.dup
merge_user!(options, source, 'source')
options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
merge_user!(options, target, 'target')
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/rest/oauth.rb
Expand Up @@ -22,6 +22,7 @@ module OAuth
# client = Twitter::REST::Client.new(consumer_key: 'abc', consumer_secret: 'def')
# bearer_token = client.token
def token(options = {})
options = options.dup
options[:bearer_token_request] = true
options[:grant_type] ||= 'client_credentials'
url = 'https://api.twitter.com/oauth2/token'
Expand All @@ -41,6 +42,7 @@ def token(options = {})
# @param options [Hash] A customizable set of options.
# @return [String] The invalidated token. token_type should be nil.
def invalidate_token(access_token, options = {})
options = options.dup
options[:access_token] = access_token
perform_post('/oauth2/invalidate_token', options)[:access_token]
end
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/rest/search.rb
Expand Up @@ -26,6 +26,7 @@ module Search
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
# @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
def search(q, options = {})
options = options.dup
options[:count] ||= MAX_TWEETS_PER_REQUEST
request = Twitter::REST::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(q: q))
Twitter::SearchResults.new(request)
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/rest/trends.rb
Expand Up @@ -19,6 +19,7 @@ module Trends
# @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
# @return [Array<Twitter::Trend>]
def trends(id = 1, options = {})
options = options.dup
options[:id] = id
response = perform_get('/1.1/trends/place.json', options).first
Twitter::TrendResults.new(response)
Expand Down
3 changes: 3 additions & 0 deletions lib/twitter/rest/tweets.rb
Expand Up @@ -41,6 +41,7 @@ def retweets(tweet, 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.
# @option options [Boolean] :ids_only ('false') Only return user IDs instead of full user objects.
def retweeters_of(tweet, options = {})
options = options.dup
ids_only = !!options.delete(:ids_only)
retweeters = retweets(tweet, options).collect(&:user)
ids_only ? retweeters.collect(&:id) : retweeters
Expand Down Expand Up @@ -221,6 +222,7 @@ def retweet!(*args)
# @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.
def update_with_media(status, media, options = {})
options = options.dup
media_ids = pmap(array_wrap(media)) do |medium|
upload(medium)[:media_id]
end
Expand All @@ -246,6 +248,7 @@ def update_with_media(status, media, options = {})
# @option options [String] :widget_type Set to video to return a Twitter Video embed for the given Tweet.
# @option options [Boolean, String] :hide_tweet Applies to video type only. Set to 1 or true to link directly to the Tweet URL instead of displaying a Tweet overlay when a viewer clicks on the Twitter bird logo.
def oembed(tweet, options = {})
options = options.dup
options[:id] = extract_id(tweet)
perform_get_with_object('/1.1/statuses/oembed.json', options, Twitter::OEmbed)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/rest/users.rb
Expand Up @@ -246,6 +246,7 @@ def user(*args)
# @return [Boolean] true if the user exists, otherwise false.
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
def user?(user, options = {})
options = options.dup
merge_user!(options, user)
perform_get('/1.1/users/show.json', options)
true
Expand All @@ -265,6 +266,7 @@ def user?(user, options = {})
# @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
# @option options [Integer] :page Specifies the page of results to retrieve.
def user_search(query, options = {})
options = options.dup
perform_get_with_objects('/1.1/users/search.json', options.merge(q: query), Twitter::User)
end

Expand Down

0 comments on commit 347c500

Please sign in to comment.