mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-05 00:02:50 -04:00
extract method 'normalize_id' from 'StripeObject#initialize' & 'ListObject#retrieve'
This commit is contained in:
parent
2f9f5d5036
commit
54efdf5405
@ -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
|
||||
|
@ -133,5 +133,15 @@ module Stripe
|
||||
raise TypeError.new('normalize_opts expects a string or a hash')
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user