Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe committed Dec 11, 2023
1 parent 7e23610 commit 9c7a649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions lib/stripe/singleton_api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ def resource_url
self.class.resource_url
end

def self.retrieve(paramsOrOpts = {}, definitelyOpts = nil)
def self.retrieve(params_or_opts = {}, definitely_opts = nil)
opts = nil
params = nil
if !definitelyOpts.nil?
opts = definitelyOpts
params = paramsOrOpts
else
unrecognized_key = paramsOrOpts.keys.find { |k| !Util::OPTS_USER_SPECIFIED.include?(k) }
if unrecognized_key
if definitely_opts.nil?
unrecognized_key = params_or_opts.keys.find { |k| !Util::OPTS_USER_SPECIFIED.include?(k) }
if unrecognized_key
raise ArgumentError,
"Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as retrieve params?" \
" If so, you must explicitly pass an opts hash as a second argument. For example: .retrieve({#{unrecognized_key}: 'foo'}, {})"
"Unrecognized request option: #{unrecognized_key}. Did you mean to specify this as retrieve params? " \
"If so, you must explicitly pass an opts hash as a second argument. " \
"For example: .retrieve({#{unrecognized_key}: 'foo'}, {})"
end

opts = paramsOrOpts
opts = params_or_opts
else
opts = definitely_opts
params = params_or_opts
end


instance = new(params, Util.normalize_opts(opts))
instance.refresh
instance
Expand Down
8 changes: 4 additions & 4 deletions test/stripe/balance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ class BalanceTest < Test::Unit::TestCase
assert balance.is_a?(Stripe::Balance)
end
should "be retrievable with opts only" do
balance = Stripe::Balance.retrieve({stripe_account: "acct_123"})
balance = Stripe::Balance.retrieve({ stripe_account: "acct_123" })
assert_requested :get, "#{Stripe.api_base}/v1/balance" do |req|
assert_equal("acct_123", req.headers["Stripe-Account"])
true
end
assert balance.is_a?(Stripe::Balance)
end
should "be retrievable with opts and params" do
balance = Stripe::Balance.retrieve({expand: ["available"]}, {stripe_account: "acct_123"})
balance = Stripe::Balance.retrieve({ expand: ["available"] }, { stripe_account: "acct_123" })
assert_requested :get, "#{Stripe.api_base}/v1/balance?expand[]=available" do |req|
assert_equal("acct_123", req.headers["Stripe-Account"])
true
end
assert balance.is_a?(Stripe::Balance)
end
should "be retrievable with params and an explicitly empty opts" do
balance = Stripe::Balance.retrieve({expand: ["available"]}, {})
balance = Stripe::Balance.retrieve({ expand: ["available"] }, {})
assert_requested :get, "#{Stripe.api_base}/v1/balance?expand[]=available" do |req|
assert_nil(req.headers["Stripe-Account"])
true
Expand All @@ -35,7 +35,7 @@ class BalanceTest < Test::Unit::TestCase
end
should "warn you if you are attempting to pass only params" do
exception = assert_raises(ArgumentError) do
Stripe::Balance.retrieve({expand: ["available"]})
Stripe::Balance.retrieve({ expand: ["available"] })
end
assert_match(/Unrecognized request option/, exception.message)
end
Expand Down

0 comments on commit 9c7a649

Please sign in to comment.