fix all remaining rubocops

This commit is contained in:
stve 2015-02-09 07:10:23 -05:00
parent 72a7e27143
commit 1c4e343b7e
8 changed files with 66 additions and 36 deletions

View file

@ -1,3 +1,11 @@
AllCops:
Include:
- './Rakefile'
- 'instapaper.gemspec'
- 'lib/**/*.rb'
- 'spec/**/*.rb'
DisplayCopNames: true
Metrics/BlockNesting: Metrics/BlockNesting:
Max: 2 Max: 2

View file

@ -3,56 +3,55 @@ require 'faraday'
# @private # @private
module Faraday module Faraday
# @private # @private
class Response::RaiseHttp1xxx < Response::Middleware class Response::RaiseHttp1xxx < Response::Middleware # rubocop:disable Style/ClassAndModuleChildren
def on_complete(env) def on_complete(env) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength
case env[:status].to_i case env[:status].to_i
# general errors # general errors
when 1040 when 1040
fail Instapaper::Error.new(error_message(env, 'Rate-limit exceeded.')) fail Instapaper::Error, error_message(env, 'Rate-limit exceeded.')
when 1041 when 1041
fail Instapaper::Error.new(error_message(env, 'Subscription account required.')) fail Instapaper::Error, error_message(env, 'Subscription account required.')
when 1042 when 1042
fail Instapaper::Error.new(error_message(env, 'Application is suspended.')) fail Instapaper::Error, error_message(env, 'Application is suspended.')
# bookmark errors # bookmark errors
when 1220 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 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 when 1240
fail Instapaper::Error.new(error_message(env, 'Invalid URL specified.')) fail Instapaper::Error, error_message(env, 'Invalid URL specified.')
when 1241 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 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 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 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 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 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 # folder errors
when 1250 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 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 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 # operational errors
when 1500 when 1500
fail Instapaper::Error.new(error_message(env, 'Unexpected service error.')) fail Instapaper::Error, error_message(env, 'Unexpected service error.')
when 1550 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
end end

View file

@ -6,7 +6,17 @@ module Instapaper
# Wrapper for the Instapaper REST API # Wrapper for the Instapaper REST API
class Client class Client
# @private # @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_endpoint, :endpoint
alias_method :api_version, :version alias_method :api_version, :version

View file

@ -12,7 +12,7 @@ module Instapaper
# Updates the user's reading progress on a single article. # Updates the user's reading progress on a single article.
# @param bookmark_id [String] The id of the bookmark to update. # @param bookmark_id [String] The id of the bookmark to update.
# @param progress [Float] The users progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the users current viewport, expressed as a percentage of the articles 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. # @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) 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 post('bookmarks/update_read_progress', bookmark_id: bookmark_id, progress: progress, progress_timestamp: progress_timestamp.to_i).first

View file

@ -24,7 +24,7 @@ module Instapaper
# @param order [Array] An array of folder_id:position pairs joined by commas. # @param order [Array] An array of folder_id:position pairs joined by commas.
# @example Ordering folder_ids 100, 200, and 300 # @example Ordering folder_ids 100, 200, and 300
# Instapaper.set_order(['100:1','200:2','300:3']) # 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(',')) post('folders/set_order', order: order.join(','))
end end
end end

View file

@ -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) response = post('oauth/access_token', {x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth'}, true)
params = response.body.split('&') params = response.body.split('&')
values = params.map { |part| part.split('=') }.flatten values = params.map { |part| part.split('=') }.flatten
if values.length == 1 values.unshift('error') if values.length == 1
values.unshift('error')
end
Hash[*values] Hash[*values]
end end
end end

View file

@ -49,8 +49,17 @@ module Instapaper
DEFAULT_CONNECTION_OPTIONS = {} DEFAULT_CONNECTION_OPTIONS = {}
# @private attr_accessor :adapter
attr_accessor *VALID_OPTIONS_KEYS 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 # When this module is extended, set all configuration options to their default values
def self.extended(base) def self.extended(base)
@ -70,7 +79,7 @@ module Instapaper
end end
# Reset all configuration options to defaults # Reset all configuration options to defaults
def reset def reset # rubocop:disable MethodLength
self.adapter = DEFAULT_ADAPTER self.adapter = DEFAULT_ADAPTER
self.consumer_key = DEFAULT_CONSUMER_KEY self.consumer_key = DEFAULT_CONSUMER_KEY
self.consumer_secret = DEFAULT_CONSUMER_SECRET self.consumer_secret = DEFAULT_CONSUMER_SECRET

View file

@ -6,13 +6,8 @@ module Instapaper
module Connection module Connection
private private
def connection(raw = false) def connection(raw = false) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
merged_options = connection_options.merge(headers: { merged_options = connection_defaults.merge(connection_options)
'Accept' => 'application/json',
'User-Agent' => user_agent
},
proxy: proxy,
url: api_endpoint)
Faraday.new(merged_options) do |builder| Faraday.new(merged_options) do |builder|
if authenticated? if authenticated?
@ -28,5 +23,16 @@ module Instapaper
builder.adapter(adapter) builder.adapter(adapter)
end end
end end
def connection_defaults
{
headers: {
'Accept' => 'application/json',
'User-Agent' => user_agent,
},
proxy: proxy,
url: api_endpoint,
}
end
end end
end end