Skip to content

Commit

Permalink
Autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Nov 28, 2023
1 parent fc0345f commit ebbef6b
Show file tree
Hide file tree
Showing 113 changed files with 307 additions and 339 deletions.
83 changes: 70 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,90 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-07-30 09:56:31 +0800 using RuboCop version 0.73.0.
# on 2023-11-28 00:44:55 UTC using RuboCop version 1.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 23
# Offense count: 6
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'test/stripe/api_operations_test.rb'
- 'test/stripe/api_resource_test.rb'
- 'test/stripe/stripe_object_test.rb'

# Offense count: 2
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'lib/stripe/stripe_client.rb'

# Offense count: 5
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'test/stripe/apple_pay_domain_test.rb'
- 'test/stripe/quote_test.rb'
- 'test/stripe/stripe_client_test.rb'

# Offense count: 3
Lint/FloatComparison:
Exclude:
- 'test/stripe/stripe_client_test.rb'

# Offense count: 2
Lint/HashCompareByIdentity:
Exclude:
- 'lib/stripe/stripe_client.rb'

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'lib/stripe/errors.rb'

# Offense count: 26
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 51
Max: 50

# Offense count: 12
# Configuration parameters: CountComments.
# Offense count: 9
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 694
Max: 587

# Offense count: 12
# Offense count: 13
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 15
Max: 16

# Offense count: 6
# Configuration parameters: CountKeywordArgs.
# Offense count: 10
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 7

# Offense count: 8
# Offense count: 9
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 17
Max: 18

# Offense count: 86
# Offense count: 39
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'lib/stripe/stripe_client.rb'
- 'lib/stripe/stripe_object.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 135
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ task :update_certs do
require "uri"

fetch_file "https://curl.haxx.se/ca/cacert.pem",
::File.expand_path("../lib/data/ca-certificates.crt", __FILE__)
File.expand_path("lib/data/ca-certificates.crt", __dir__)
end

#
# helpers
#

def fetch_file(uri, dest)
::File.open(dest, "w") do |file|
File.open(dest, "w") do |file|
resp = Net::HTTP.get_response(URI.parse(uri))
unless resp.code.to_i == 200
abort("bad response when fetching: #{uri}\n" \
"Status #{resp.code}: #{resp.body}")
"Status #{resp.code}: #{resp.body}")
end
file.write(resp.body)
puts "Successfully fetched: #{uri}"
Expand Down
2 changes: 1 addition & 1 deletion bin/stripe-console
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "irb"
require "irb/completion"

require "#{::File.dirname(__FILE__)}/../lib/stripe"
require "#{File.dirname(__FILE__)}/../lib/stripe"

# Config IRB to enable --simple-prompt and auto indent
IRB.conf[:PROMPT_MODE] = :SIMPLE
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
require "stripe/oauth"

module Stripe
DEFAULT_CA_BUNDLE_PATH = __dir__ + "/data/ca-certificates.crt"
DEFAULT_CA_BUNDLE_PATH = "#{__dir__}/data/ca-certificates.crt"

# map to the same values as the standard library's logger
LEVEL_DEBUG = Logger::DEBUG
Expand Down
8 changes: 3 additions & 5 deletions lib/stripe/api_operations/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def execute_resource_request_stream(method, url,

raise ArgumentError,
"request option '#{opt}' should be a string value " \
"(was a #{val.class})"
"(was a #{val.class})"
end
end

Expand All @@ -98,14 +98,12 @@ def execute_resource_request_stream(method, url,

raise ArgumentError,
"request params should be either a Hash or nil " \
"(was a #{params.class})"
"(was a #{params.class})"
end

private def warn_on_opts_in_params(params)
Util::OPTS_USER_SPECIFIED.each do |opt|
if params.key?(opt)
warn("WARNING: '#{opt}' should be in opts instead of params.")
end
warn("WARNING: '#{opt}' should be in opts instead of params.") if params.key?(opt)
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lib/stripe/api_operations/save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ module ClassMethods
# {APIOperations::Request.execute_resource_request}.
def update(id, params = {}, opts = {})
params.each_key do |k|
if protected_fields.include?(k)
raise ArgumentError, "Cannot update protected field: #{k}"
end
raise ArgumentError, "Cannot update protected field: #{k}" if protected_fields.include?(k)
end

request_stripe_object(
Expand Down Expand Up @@ -64,17 +62,17 @@ def save(params = {}, opts = {})

values = serialize_params(self).merge(params)

# note that id gets removed here our call to #url above has already
# NOTE: that id gets removed here our call to #url above has already
# generated a uri for this object with an identifier baked in
values.delete(:id)

resp, opts = execute_resource_request(:post, save_url, values, opts, ["save"])
initialize_from(resp.data, opts)
end
extend Gem::Deprecate
deprecate :save, "the `update` class method (for examples"\
" see https://github.com/stripe/stripe-ruby"\
"/wiki/Migration-guide-for-v8)", 2022, 11
deprecate :save, "the `update` class method (for examples " \
"see https://github.com/stripe/stripe-ruby" \
"/wiki/Migration-guide-for-v8)", 2022, 11

def self.included(base)
# Set `metadata` as additive so that when it's set directly we remember
Expand Down
4 changes: 2 additions & 2 deletions lib/stripe/api_resource_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def self.custom_method(name, http_verb:, http_path: nil)
end

def self.resource_url
"/v1/test_helpers/"\
"#{self::RESOURCE_CLASS::OBJECT_NAME.downcase.tr('.', '/')}s"
"/v1/test_helpers/" \
"#{self::RESOURCE_CLASS::OBJECT_NAME.downcase.tr('.', '/')}s"
end

def resource_url
Expand Down
12 changes: 5 additions & 7 deletions lib/stripe/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def execute_request(method, uri, body: nil, headers: nil, query: nil,

u = URI.parse(uri)
path = if query
u.path + "?" + query
"#{u.path}?#{query}"
else
u.path
end
Expand Down Expand Up @@ -157,9 +157,7 @@ def execute_request(method, uri, body: nil, headers: nil, query: nil,

connection.open_timeout = config.open_timeout
connection.read_timeout = config.read_timeout
if connection.respond_to?(:write_timeout=)
connection.write_timeout = config.write_timeout
end
connection.write_timeout = config.write_timeout if connection.respond_to?(:write_timeout=)

connection.use_ssl = uri.scheme == "https"

Expand Down Expand Up @@ -192,9 +190,9 @@ def execute_request(method, uri, body: nil, headers: nil, query: nil,

@verify_ssl_warned = true
warn("WARNING: Running without SSL cert verification. " \
"You should never do this in production. " \
"Execute `Stripe.verify_ssl_certs = true` to enable " \
"verification.")
"You should never do this in production. " \
"Execute `Stripe.verify_ssl_certs = true` to enable " \
"verification.")
end
end
end
12 changes: 2 additions & 10 deletions lib/stripe/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ module Stripe
# StripeError is the base error from which all other more specific Stripe
# errors derive.
class StripeError < StandardError
attr_reader :message
attr_reader :message, :code, :error, :http_body, :http_headers, :http_status, :json_body, :request_id

# Response contains a StripeResponse object that has some basic information
# about the response that conveyed the error.
attr_accessor :response

attr_reader :code
attr_reader :error
attr_reader :http_body
attr_reader :http_headers
attr_reader :http_status
attr_reader :json_body # equivalent to #data
attr_reader :request_id
attr_accessor :response # equivalent to #data

# Initializes a StripeError.
def initialize(message = nil, http_status: nil, http_body: nil,
Expand Down
30 changes: 7 additions & 23 deletions lib/stripe/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Stripe
class Instrumentation
# Event emitted on `request_begin` callback.
class RequestBeginEvent
attr_reader :method
attr_reader :path
attr_reader :method, :path

# Arbitrary user-provided data in the form of a Ruby hash that's passed
# from subscribers on `request_begin` to subscribers on `request_end`.
Expand All @@ -27,16 +26,8 @@ def initialize(method:, path:, user_data:)

# Event emitted on `request_end` callback.
class RequestEndEvent
attr_reader :duration
attr_reader :http_status
attr_reader :method
attr_reader :num_retries
attr_reader :path
attr_reader :request_id
attr_reader :response_header
attr_reader :response_body
attr_reader :request_header
attr_reader :request_body
attr_reader :duration, :http_status, :method, :num_retries, :path, :request_id, :response_header, :response_body,
:request_header, :request_body

# Arbitrary user-provided data in the form of a Ruby hash that's passed
# from subscribers on `request_begin` to subscribers on `request_end`.
Expand All @@ -62,12 +53,7 @@ def initialize(request_context:, response_context:,
end

class RequestContext
attr_reader :duration
attr_reader :method
attr_reader :path
attr_reader :request_id
attr_reader :body
attr_reader :header
attr_reader :duration, :method, :path, :request_id, :body, :header

def initialize(duration:, context:, header:)
@duration = duration
Expand All @@ -80,14 +66,12 @@ def initialize(duration:, context:, header:)
end

class ResponseContext
attr_reader :http_status
attr_reader :body
attr_reader :header
attr_reader :http_status, :body, :header

def initialize(http_status:, response:)
@http_status = http_status
@header = response ? response.to_hash : nil
@body = response ? response.body : nil
@header = response&.to_hash
@body = response&.body
end
end

Expand Down
16 changes: 8 additions & 8 deletions lib/stripe/multipart_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,26 @@ def encode(params)
end

private def write_field(name, data, filename:)
if !@first_field
@body << "\r\n"
else
if @first_field
@first_field = false
else
@body << "\r\n"
end

@body << "--#{@boundary}\r\n"

# Rubocop gets confused by trying to parse (" foo="..." ...")
# rubocop:disable Lint/Syntax
if filename
@body << %(Content-Disposition: form-data) +
%(; name="#{escape(name.to_s)}") +
%(; filename="#{escape(filename)}"\r\n)
@body << ("Content-Disposition: form-data; name="#{escape(name.to_s)}"; filename="#{escape(filename)}"\r\n")
@body << %(Content-Type: application/octet-stream\r\n)
else
@body << %(Content-Disposition: form-data) +
%(; name="#{escape(name.to_s)}"\r\n)
@body << ("Content-Disposition: form-data; name="#{escape(name.to_s)}"\r\n")
end

@body << "\r\n"
@body << data.to_s
end
# rubocop:enable Lint/Syntax
end
end
14 changes: 7 additions & 7 deletions lib/stripe/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ def self.get_client_id(params = {})
client_id = params[:client_id] || Stripe.client_id
unless client_id
raise AuthenticationError, "No client_id provided. " \
'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
"You can find your client_ids in your Stripe dashboard at " \
"https://dashboard.stripe.com/account/applications/settings, " \
"after registering your account as a platform. See " \
"https://stripe.com/docs/connect/standalone-accounts for details, " \
"or email [email protected] if you have any questions."
'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
"You can find your client_ids in your Stripe dashboard at " \
"https://dashboard.stripe.com/account/applications/settings, " \
"after registering your account as a platform. See " \
"https://stripe.com/docs/connect/standalone-accounts for details, " \
"or email [email protected] if you have any questions."
end
client_id
end
Expand All @@ -33,7 +33,7 @@ def self.authorize_url(params = {}, opts = {})
base = opts[:connect_base] || client.config.connect_base

path = "/oauth/authorize"
path = "/express" + path if opts[:express]
path = "/express#{path}" if opts[:express]

params[:client_id] = get_client_id(params)
params[:response_type] ||= "code"
Expand Down
Loading

0 comments on commit ebbef6b

Please sign in to comment.