From 1c4e343b7e97212b728e15f4d1d544791601c52b Mon Sep 17 00:00:00 2001 From: stve Date: Mon, 9 Feb 2015 07:10:23 -0500 Subject: [PATCH] fix all remaining rubocops --- .rubocop.yml | 8 +++++ lib/faraday/response/raise_http_1xxx.rb | 39 ++++++++++++------------- lib/instapaper/client.rb | 12 +++++++- lib/instapaper/client/bookmark.rb | 2 +- lib/instapaper/client/folder.rb | 2 +- lib/instapaper/client/user.rb | 4 +-- lib/instapaper/configuration.rb | 15 ++++++++-- lib/instapaper/connection.rb | 20 ++++++++----- 8 files changed, 66 insertions(+), 36 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6fe7ec2..28ff7f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,11 @@ +AllCops: + Include: + - './Rakefile' + - 'instapaper.gemspec' + - 'lib/**/*.rb' + - 'spec/**/*.rb' + DisplayCopNames: true + Metrics/BlockNesting: Max: 2 diff --git a/lib/faraday/response/raise_http_1xxx.rb b/lib/faraday/response/raise_http_1xxx.rb index e543934..d98a0e6 100644 --- a/lib/faraday/response/raise_http_1xxx.rb +++ b/lib/faraday/response/raise_http_1xxx.rb @@ -3,56 +3,55 @@ require 'faraday' # @private module Faraday # @private - class Response::RaiseHttp1xxx < Response::Middleware - def on_complete(env) + class Response::RaiseHttp1xxx < Response::Middleware # rubocop:disable Style/ClassAndModuleChildren + def on_complete(env) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength case env[:status].to_i # general errors when 1040 - fail Instapaper::Error.new(error_message(env, 'Rate-limit exceeded.')) + fail Instapaper::Error, error_message(env, 'Rate-limit exceeded.') when 1041 - fail Instapaper::Error.new(error_message(env, 'Subscription account required.')) + fail Instapaper::Error, error_message(env, 'Subscription account required.') when 1042 - fail Instapaper::Error.new(error_message(env, 'Application is suspended.')) + fail Instapaper::Error, error_message(env, 'Application is suspended.') # bookmark errors when 1220 - fail Instapaper::Error.new(error_message(env, 'Domain requires full content to be supplied.')) + fail Instapaper::Error, error_message(env, 'Domain requires full content to be supplied.') when 1221 - fail Instapaper::Error.new(error_message(env, 'Domain has opted out of Instapaper compatibility.')) + fail Instapaper::Error, error_message(env, 'Domain has opted out of Instapaper compatibility.') when 1240 - fail Instapaper::Error.new(error_message(env, 'Invalid URL specified.')) + fail Instapaper::Error, error_message(env, 'Invalid URL specified.') when 1241 - fail Instapaper::Error.new(error_message(env, 'Invalid or missing bookmark_id.')) + fail Instapaper::Error, error_message(env, 'Invalid or missing bookmark_id.') when 1242 - fail Instapaper::Error.new(error_message(env, 'Invalid or missing folder_id.')) + fail Instapaper::Error, error_message(env, 'Invalid or missing folder_id.') when 1243 - fail Instapaper::Error.new(error_message(env, 'Invalid or missing progress.')) + fail Instapaper::Error, error_message(env, 'Invalid or missing progress.') when 1244 - fail Instapaper::Error.new(error_message(env, 'Invalid or missing progress_timestamp.')) + fail Instapaper::Error, error_message(env, 'Invalid or missing progress_timestamp.') when 1245 - fail Instapaper::Error.new(error_message(env, 'Private bookmarks require supplied content.')) + fail Instapaper::Error, error_message(env, 'Private bookmarks require supplied content.') when 1250 - fail Instapaper::Error.new(error_message(env, 'Unexpected error when saving bookmark.')) + fail Instapaper::Error, error_message(env, 'Unexpected error when saving bookmark.') # folder errors when 1250 - fail Instapaper::Error.new(error_message(env, 'Invalid or missing title.')) + fail Instapaper::Error, error_message(env, 'Invalid or missing title.') when 1251 - fail Instapaper::Error.new(error_message(env, 'User already has a folder with this title.')) + fail Instapaper::Error, error_message(env, 'User already has a folder with this title.') when 1252 - fail Instapaper::Error.new(error_message(env, 'Cannot add bookmarks to this folder.')) + fail Instapaper::Error, error_message(env, 'Cannot add bookmarks to this folder.') # operational errors when 1500 - fail Instapaper::Error.new(error_message(env, 'Unexpected service error.')) + fail Instapaper::Error, error_message(env, 'Unexpected service error.') when 1550 - fail Instapaper::Error.new(error_message(env, 'Error generating text version of this URL.')) - + fail Instapaper::Error, error_message(env, 'Error generating text version of this URL.') end end diff --git a/lib/instapaper/client.rb b/lib/instapaper/client.rb index 1369e2d..e23572e 100644 --- a/lib/instapaper/client.rb +++ b/lib/instapaper/client.rb @@ -6,7 +6,17 @@ module Instapaper # Wrapper for the Instapaper REST API class Client # @private - attr_accessor *Configuration::VALID_OPTIONS_KEYS + attr_accessor :adapter + attr_accessor :consumer_key + attr_accessor :consumer_secret + attr_accessor :endpoint + attr_accessor :oauth_token + attr_accessor :oauth_token_secret + attr_accessor :proxy + attr_accessor :version + attr_accessor :path_prefix + attr_accessor :user_agent + attr_accessor :connection_options alias_method :api_endpoint, :endpoint alias_method :api_version, :version diff --git a/lib/instapaper/client/bookmark.rb b/lib/instapaper/client/bookmark.rb index 4cc92da..7005c09 100644 --- a/lib/instapaper/client/bookmark.rb +++ b/lib/instapaper/client/bookmark.rb @@ -12,7 +12,7 @@ module Instapaper # Updates the user's reading progress on a single article. # @param bookmark_id [String] The id of the bookmark to update. - # @param progress [Float] The user’s progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the user’s current viewport, expressed as a percentage of the article’s total length. + # @param progress [Float] The user's progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the user's current viewport, expressed as a percentage of the article's total length. # @param progress_timestamp [Integer] The Unix timestamp value of the time that the progress was recorded. def update_read_progress(bookmark_id, progress, progress_timestamp = Time.now) post('bookmarks/update_read_progress', bookmark_id: bookmark_id, progress: progress, progress_timestamp: progress_timestamp.to_i).first diff --git a/lib/instapaper/client/folder.rb b/lib/instapaper/client/folder.rb index 449d5ff..04bf45d 100644 --- a/lib/instapaper/client/folder.rb +++ b/lib/instapaper/client/folder.rb @@ -24,7 +24,7 @@ module Instapaper # @param order [Array] An array of folder_id:position pairs joined by commas. # @example Ordering folder_ids 100, 200, and 300 # Instapaper.set_order(['100:1','200:2','300:3']) - def set_order(order = []) + def set_order(order = []) # rubocop:disable Style/AccessorMethodName post('folders/set_order', order: order.join(',')) end end diff --git a/lib/instapaper/client/user.rb b/lib/instapaper/client/user.rb index 96602dd..7bfb202 100644 --- a/lib/instapaper/client/user.rb +++ b/lib/instapaper/client/user.rb @@ -7,9 +7,7 @@ module Instapaper response = post('oauth/access_token', {x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth'}, true) params = response.body.split('&') values = params.map { |part| part.split('=') }.flatten - if values.length == 1 - values.unshift('error') - end + values.unshift('error') if values.length == 1 Hash[*values] end end diff --git a/lib/instapaper/configuration.rb b/lib/instapaper/configuration.rb index 4aa0532..8b5e6ca 100644 --- a/lib/instapaper/configuration.rb +++ b/lib/instapaper/configuration.rb @@ -49,8 +49,17 @@ module Instapaper DEFAULT_CONNECTION_OPTIONS = {} - # @private - attr_accessor *VALID_OPTIONS_KEYS + attr_accessor :adapter + attr_accessor :consumer_key + attr_accessor :consumer_secret + attr_accessor :endpoint + attr_accessor :oauth_token + attr_accessor :oauth_token_secret + attr_accessor :proxy + attr_accessor :version + attr_accessor :path_prefix + attr_accessor :user_agent + attr_accessor :connection_options # When this module is extended, set all configuration options to their default values def self.extended(base) @@ -70,7 +79,7 @@ module Instapaper end # Reset all configuration options to defaults - def reset + def reset # rubocop:disable MethodLength self.adapter = DEFAULT_ADAPTER self.consumer_key = DEFAULT_CONSUMER_KEY self.consumer_secret = DEFAULT_CONSUMER_SECRET diff --git a/lib/instapaper/connection.rb b/lib/instapaper/connection.rb index a1f1175..783fd92 100644 --- a/lib/instapaper/connection.rb +++ b/lib/instapaper/connection.rb @@ -6,13 +6,8 @@ module Instapaper module Connection private - def connection(raw = false) - merged_options = connection_options.merge(headers: { - 'Accept' => 'application/json', - 'User-Agent' => user_agent - }, - proxy: proxy, - url: api_endpoint) + def connection(raw = false) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity + merged_options = connection_defaults.merge(connection_options) Faraday.new(merged_options) do |builder| if authenticated? @@ -28,5 +23,16 @@ module Instapaper builder.adapter(adapter) end end + + def connection_defaults + { + headers: { + 'Accept' => 'application/json', + 'User-Agent' => user_agent, + }, + proxy: proxy, + url: api_endpoint, + } + end end end