lib/stripe/util.rb in stripe-1.16.0 vs lib/stripe/util.rb in stripe-1.16.1

- old
+ new

@@ -15,27 +15,30 @@ end end def self.object_classes @object_classes ||= { + # data structures + 'list' => ListObject, + + # business objects + 'application_fee' => ApplicationFee, 'balance' => Balance, 'balance_transaction' => BalanceTransaction, + 'card' => Card, 'charge' => Charge, + 'coupon' => Coupon, 'customer' => Customer, + 'event' => Event, + 'fee_refund' => ApplicationFeeRefund, 'invoiceitem' => InvoiceItem, 'invoice' => Invoice, 'plan' => Plan, - 'coupon' => Coupon, - 'event' => Event, - 'transfer' => Transfer, 'recipient' => Recipient, - 'card' => Card, - 'subscription' => Subscription, - 'list' => ListObject, 'refund' => Refund, - 'application_fee' => ApplicationFee, - 'fee_refund' => ApplicationFeeRefund + 'subscription' => Subscription, + 'transfer' => Transfer } end def self.convert_to_stripe_object(resp, api_key) case resp @@ -63,16 +66,16 @@ end def self.symbolize_names(object) case object when Hash - new = {} + new_hash = {} object.each do |key, value| key = (key.to_sym rescue key) || key - new[key] = symbolize_names(value) + new_hash[key] = symbolize_names(value) end - new + new_hash when Array object.map { |value| symbolize_names(value) } else object end @@ -107,8 +110,30 @@ else result << ["#{calculated_key}[]", elem] end end result + 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.parse_opts(opts) + case opts + when NilClass + return nil, {} + when String + return opts, {} + when Hash + headers = {} + if opts[:idempotency_key] + headers[:idempotency_key] = opts[:idempotency_key] + end + if opts[:stripe_account] + headers[:stripe_account] = opts[:stripe_account] + end + return opts[:api_key], headers + else + raise TypeError.new("parse_opts expects a string or a hash") + end end end end