Skip to content

Commit

Permalink
Convert hash rockets to colons
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 6, 2015
1 parent 3dd2a5c commit 3476cee
Show file tree
Hide file tree
Showing 88 changed files with 1,448 additions and 1,307 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ Style/Documentation:
Style/DoubleNegation:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'jruby-openssl', :platforms => :jruby
gem 'jruby-openssl', platforms: :jruby
gem 'rake'
gem 'yard'

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end

```ruby
topics = ["coffee", "tea"]
client.filter(:track => topics.join(",")) do |object|
client.filter(track: topics.join(",")) do |object|
puts object.text if object.is_a?(Twitter::Tweet)
end
```
Expand Down Expand Up @@ -528,14 +528,14 @@ client.status(27558893223)
**Collect the three most recent marriage proposals to @justinbieber**
```ruby
client.search("to:justinbieber marry me", :result_type => "recent").take(3).collect do |tweet|
client.search("to:justinbieber marry me", result_type: "recent").take(3).collect do |tweet|
"#{tweet.user.screen_name}: #{tweet.text}"
end
```
**Find a Japanese-language Tweet tagged #ruby (excluding retweets)**
```ruby
client.search("#ruby -rt", :lang => "ja").first.text
client.search("#ruby -rt", lang: "ja").first.text
```
For more usage examples, please see the full [documentation][].
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :test => :spec
task test: :spec

require 'rubocop/rake_task'
RuboCop::RakeTask.new
Expand All @@ -28,4 +28,4 @@ Yardstick::Rake::Verify.new do |verify|
verify.threshold = 59.1
end

task :default => [:spec, :rubocop, :verify_measurements]
task default: [:spec, :rubocop, :verify_measurements]
2 changes: 1 addition & 1 deletion examples/AllTweets.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end

def client.get_all_tweets(user)
collect_with_max_id do |max_id|
options = {:count => 200, :include_rts => true}
options = {count: 200, include_rts: true}
options[:max_id] = max_id unless max_id.nil?
user_timeline(user, options)
end
Expand Down
4 changes: 2 additions & 2 deletions examples/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ If you prefer, you can pass in configuration as a `Hash`:

```ruby
config = {
:consumer_key => "YOUR_CONSUMER_KEY",
:consumer_secret => "YOUR_CONSUMER_SECRET",
consumer_key: "YOUR_CONSUMER_KEY",
consumer_secret: "YOUR_CONSUMER_SECRET",
}

client = Twitter::REST::Client.new(config)
Expand Down
2 changes: 1 addition & 1 deletion examples/Search.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Here's a simple example of how to search for tweets. This query will return the
three most recent marriage proposals to @justinbieber.

```ruby
client.search("to:justinbieber marry me", :result_type => "recent").take(3).each do |tweet|
client.search("to:justinbieber marry me", result_type: "recent").take(3).each do |tweet|
puts tweet.text
end
```
2 changes: 1 addition & 1 deletion examples/Streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Instructions on how to configure a client can be found in
Here's a simple example of how to stream tweets from San Francisco:

```ruby
client.filter(:locations => "-122.75,36.8,-121.75,37.8") do |tweet|
client.filter(locations: "-122.75,36.8,-121.75,37.8") do |tweet|
puts tweet.text
end
```
10 changes: 5 additions & 5 deletions examples/Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ client.update("I'm tweeting with @gem!")
Post an update in reply to another tweet.

```ruby
client.update("I'm tweeting with @gem!", :in_reply_to_status_id => 402712877960019968)
client.update("I'm tweeting with @gem!", in_reply_to_status_id: 402712877960019968)
```

Post an update with precise coordinates.

```ruby
client.update("I'm tweeting with @gem!", :lat => 37.7821120598956, :long => -122.400612831116, :display_coordinates => true)
client.update("I'm tweeting with @gem!", lat: 37.7821120598956, long: -122.400612831116, display_coordinates: true)
```

Post an update from a specific place. Place IDs can be retrieved using the
Expand All @@ -31,7 +31,7 @@ Post an update from a specific place. Place IDs can be retrieved using the
[reverse_geocode]: http://rdoc.info/gems/twitter/Twitter/REST/API/PlacesAndGeo#reverse_geocode-instance_method

```ruby
client.update("I'm tweeting with @gem!", :place_id => "df51dec6f4ee2b2c")
client.update("I'm tweeting with @gem!", place_id: "df51dec6f4ee2b2c")
```

Post an update with an image.
Expand All @@ -43,7 +43,7 @@ client.update_with_media("I'm tweeting with @gem!", File.new("/path/to/media.png
Post an update with a possibly-sensitive image.

```ruby
client.update_with_media("I'm tweeting with @gem!", File.new("/path/to/sensitive-media.png"), :possibly_sensitive => true)
client.update_with_media("I'm tweeting with @gem!", File.new("/path/to/sensitive-media.png"), possibly_sensitive: true)
```

Post an update with multiple images.
Expand All @@ -56,7 +56,7 @@ media_ids = %w(/path/to/media1.png /path/to/media2.png).map do |filename|
end
end.map(&:value)

client.update("I'm tweeting with @gem!", :media_ids => media_ids.join(','))
client.update("I'm tweeting with @gem!", media_ids: media_ids.join(','))
```

For more information, see the documentation for the [`#update`][update] and
Expand Down
10 changes: 5 additions & 5 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def user_agent
# @return [Hash]
def credentials
{
:consumer_key => consumer_key,
:consumer_secret => consumer_secret,
:token => access_token,
:token_secret => access_token_secret,
:ignore_extra_keys => true,
consumer_key: consumer_key,
consumer_secret: consumer_secret,
token: access_token,
token_secret: access_token_secret,
ignore_extra_keys: true,
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def last?

# @return [Hash]
def fetch_next_page
response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(:cursor => next_cursor)).perform
response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(cursor: next_cursor)).perform
self.attrs = response
end

Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def favorite(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |tweet|
begin
perform_post_with_object('/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
perform_post_with_object('/1.1/favorites/create.json', arguments.options.merge(id: extract_id(tweet)), Twitter::Tweet)
rescue Twitter::Error::AlreadyFavorited, Twitter::Error::NotFound
next
end
Expand All @@ -96,7 +96,7 @@ def favorite(*args)
def favorite!(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |tweet|
perform_post_with_object('/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
perform_post_with_object('/1.1/favorites/create.json', arguments.options.merge(id: extract_id(tweet)), Twitter::Tweet)
end
end
alias_method :create_favorite!, :favorite!
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def list_update(*args)
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
def create_list(name, options = {})
perform_post_with_object('/1.1/lists/create.json', options.merge(:name => name), Twitter::List)
perform_post_with_object('/1.1/lists/create.json', options.merge(name: name), Twitter::List)
end
deprecate_alias :list_create, :create_list

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def upload(media, options = {})
fail(Twitter::Error::UnacceptableIO) unless media.respond_to?(:to_io)
url = 'https://upload.twitter.com/1.1/media/upload.json'
headers = Twitter::Headers.new(self, :post, url, options).request_headers
HTTP.with(headers).post(url, :form => options).parse['media_id']
HTTP.with(headers).post(url, form: options).parse['media_id']
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/rest/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ module OAuth
# @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
# @param options [Hash] A customizable set of options.
# @example Generate a Bearer Token
# client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
# client = Twitter::REST::Client.new(consumer_key: 'abc', consumer_secret: 'def')
# bearer_token = client.token
def token(options = {})
options[:bearer_token_request] = true
options[:grant_type] ||= 'client_credentials'
headers = Twitter::Headers.new(self, :post, 'https://api.twitter.com/oauth2/token', options).request_headers
response = HTTP.with(headers).post('https://api.twitter.com/oauth2/token', :form => options)
response = HTTP.with(headers).post('https://api.twitter.com/oauth2/token', form: options)
Twitter::Token.new(symbolize_keys!(response.parse))
end
alias_method :bearer_token, :token
Expand Down Expand Up @@ -56,10 +56,10 @@ def invalidate_token(access_token, options = {})
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [String] The token string.
def reverse_token
options = {:x_auth_mode => 'reverse_auth'}
options = {x_auth_mode: 'reverse_auth'}
url = 'https://api.twitter.com/oauth/request_token'
auth_header = Twitter::Headers.new(self, :post, url, options).oauth_auth_header.to_s
HTTP.with(:authorization => auth_header).post(url, :params => options).to_s
HTTP.with(authorization: auth_header).post(url, params: options).to_s
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/request/multipart_with_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def mime_type(path)
end
end

Faraday::Request.register_middleware :twitter_multipart_with_file => Twitter::REST::Request::MultipartWithFile
Faraday::Request.register_middleware twitter_multipart_with_file: Twitter::REST::Request::MultipartWithFile
2 changes: 1 addition & 1 deletion lib/twitter/rest/saved_searches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def saved_search(id, options = {})
# @param query [String] The query of the search the user would like to save.
# @param options [Hash] A customizable set of options.
def create_saved_search(query, options = {})
perform_post_with_object('/1.1/saved_searches/create.json', options.merge(:query => query), Twitter::SavedSearch)
perform_post_with_object('/1.1/saved_searches/create.json', options.merge(query: query), Twitter::SavedSearch)
end
deprecate_alias :saved_search_create, :create_saved_search

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Search
# @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
def search(q, options = {})
options[:count] ||= MAX_TWEETS_PER_REQUEST
request = Twitter::REST::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
request = Twitter::REST::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(q: q))
Twitter::SearchResults.new(request)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def status(tweet, options = {})
def statuses(*args)
arguments = Twitter::Arguments.new(args)
flat_pmap(arguments.each_slice(MAX_TWEETS_PER_REQUEST)) do |tweets|
perform_post_with_objects('/1.1/statuses/lookup.json', arguments.options.merge(:id => tweets.collect { |u| extract_id(u) }.join(',')), Twitter::Tweet)
perform_post_with_objects('/1.1/statuses/lookup.json', arguments.options.merge(id: tweets.collect { |u| extract_id(u) }.join(',')), Twitter::Tweet)
end
end

Expand Down Expand Up @@ -127,7 +127,7 @@ def destroy_status(*args)
def update(status, options = {})
update!(status, options)
rescue Twitter::Error::DuplicateStatus
user_timeline(:count => 1).first
user_timeline(count: 1).first
end

# Updates the authenticating user's status
Expand Down Expand Up @@ -155,7 +155,7 @@ def update!(status, options = {})
hash = options.dup
hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil?
perform_post_with_object('/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet)
perform_post_with_object('/1.1/statuses/update.json', hash.merge(status: status), Twitter::Tweet)
end

# Retweets the specified Tweets as the authenticating user
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/undocumented.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def following_followers_of(*args)
# @param url [String, URI] A URL.
# @param options [Hash] A customizable set of options.
def tweet_count(url, options = {})
HTTP.get('https://cdn.api.twitter.com/1/urls/count.json', :params => options.merge(:url => url.to_s)).parse['count']
HTTP.get('https://cdn.api.twitter.com/1/urls/count.json', params: options.merge(url: url.to_s)).parse['count']
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/twitter/rest/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def settings(options = {})
request_method = options.size.zero? ? :get : :post
response = perform_request(request_method.to_sym, '/1.1/account/settings.json', options)
# https://dev.twitter.com/issues/59
response.update(:trend_location => response.fetch(:trend_location, []).first)
response.update(trend_location: response.fetch(:trend_location, []).first)
Twitter::Settings.new(response)
end

Expand Down Expand Up @@ -62,7 +62,7 @@ def verify_credentials(options = {})
# @param device [String] Must be one of: 'sms', 'none'.
# @param options [Hash] A customizable set of options.
def update_delivery_device(device, options = {})
perform_post_with_object('/1.1/account/update_delivery_device.json', options.merge(:device => device), Twitter::User)
perform_post_with_object('/1.1/account/update_delivery_device.json', options.merge(device: device), Twitter::User)
end

# Sets values that users are able to set under the "Account" tab of their settings page
Expand Down Expand Up @@ -93,7 +93,7 @@ def update_profile(options = {})
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
def update_profile_background_image(image, options = {})
perform_post_with_object('/1.1/account/update_profile_background_image.json', options.merge(:image => image), Twitter::User)
perform_post_with_object('/1.1/account/update_profile_background_image.json', options.merge(image: image), Twitter::User)
end

# Sets one or more hex values that control the color scheme of the authenticating user's profile
Expand Down Expand Up @@ -125,7 +125,7 @@ def update_profile_colors(options = {})
# @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
# @param options [Hash] A customizable set of options.
def update_profile_image(image, options = {})
perform_post_with_object('/1.1/account/update_profile_image.json', options.merge(:image => image), Twitter::User)
perform_post_with_object('/1.1/account/update_profile_image.json', options.merge(image: image), Twitter::User)
end

# Returns an array of user objects that the authenticating user is blocking
Expand Down Expand Up @@ -286,7 +286,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 = {})
perform_get_with_objects('/1.1/users/search.json', options.merge(:q => query), Twitter::User)
perform_get_with_objects('/1.1/users/search.json', options.merge(q: query), Twitter::User)
end

# Returns an array of users that the specified user can contribute to
Expand Down Expand Up @@ -357,7 +357,7 @@ def remove_profile_banner(options = {})
# @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
# @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
def update_profile_banner(banner, options = {})
perform_post('/1.1/account/update_profile_banner.json', options.merge(:banner => banner))
perform_post('/1.1/account/update_profile_banner.json', options.merge(banner: banner))
true
end

Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def objects_from_response_with_user(klass, request_method, path, args)
def parallel_objects_from_response(klass, request_method, path, args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |object|
perform_request_with_object(request_method, path, arguments.options.merge(:id => extract_id(object)), klass)
perform_request_with_object(request_method, path, arguments.options.merge(id: extract_id(object)), klass)
end
end

Expand All @@ -163,7 +163,7 @@ def cursor_from_response_with_user(collection_name, klass, path, args)
end

def user_id
@user_id ||= verify_credentials(:skip_status => true).id
@user_id ||= verify_credentials(skip_status: true).id
end

def user_id?
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/streaming/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sample(options = {}, &block)
def site(*args, &block)
arguments = Arguments.new(args)
user_ids = collect_user_ids(arguments)
request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(:follow => user_ids.join(',')), &block)
request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(follow: user_ids.join(',')), &block)
end

# Streams messages for a single user
Expand Down Expand Up @@ -109,7 +109,7 @@ def before_request(&block)
def request(method, uri, params)
before_request.call
authorization = Twitter::Headers.new(self, method, uri, params).oauth_auth_header.to_s
headers = default_headers.merge(:authorization => authorization)
headers = default_headers.merge(authorization: authorization)
request = HTTP::Request.new(method, uri + '?' + to_url_params(params), headers)
response = Streaming::Response.new do |data|
if item = Streaming::MessageParser.parse(data) # rubocop:disable AssignmentInCondition
Expand All @@ -127,8 +127,8 @@ def to_url_params(params)

def default_headers
@default_headers ||= {
:accept => '*/*',
:user_agent => user_agent,
accept: '*/*',
user_agent: user_agent,
}
end

Expand Down
Loading

0 comments on commit 3476cee

Please sign in to comment.