mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-24 00:00:51 -04:00
extract method 'normalize_id' from 'StripeObject#initialize' & 'ListObject#retrieve'
This commit is contained in:
parent
31ccf7c6d3
commit
97c9249ab1
@ -16,12 +16,7 @@ module Stripe
|
||||
end
|
||||
|
||||
def retrieve(id, opts={})
|
||||
if id.kind_of?(Hash) # overloaded id
|
||||
retrieve_params = id
|
||||
id = retrieve_params.delete(:id)
|
||||
else
|
||||
retrieve_params = {}
|
||||
end
|
||||
id, retrieve_params = Util.normalize_id(id)
|
||||
response, opts = request(:get,"#{url}/#{CGI.escape(id)}", retrieve_params, opts)
|
||||
Util.convert_to_stripe_object(response, opts)
|
||||
end
|
||||
|
@ -10,15 +10,7 @@ module Stripe
|
||||
end
|
||||
|
||||
def initialize(id=nil, opts={})
|
||||
# parameter overloading!
|
||||
if id.kind_of?(Hash)
|
||||
@retrieve_params = id.dup
|
||||
@retrieve_params.delete(:id)
|
||||
id = id[:id]
|
||||
else
|
||||
@retrieve_params = {}
|
||||
end
|
||||
|
||||
id, @retrieve_params = Util.normalize_id(id)
|
||||
@opts = opts
|
||||
@values = {}
|
||||
# This really belongs in APIResource, but not putting it there allows us
|
||||
|
@ -120,6 +120,16 @@ module Stripe
|
||||
result
|
||||
end
|
||||
|
||||
def self.normalize_id(id)
|
||||
if id.kind_of?(Hash) # overloaded id
|
||||
params_hash = id.dup
|
||||
id = params_hash.delete(:id)
|
||||
else
|
||||
params_hash = {}
|
||||
end
|
||||
[id, params_hash]
|
||||
end
|
||||
|
||||
# The secondary opts argument can either be a string or hash
|
||||
# Turn this value into an api_key and a set of headers
|
||||
def self.normalize_opts(opts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user