lib/stripe/util.rb in stripe-1.55.0 vs lib/stripe/util.rb in stripe-1.55.1
- old
+ new
@@ -21,42 +21,43 @@
@object_classes ||= {
# data structures
'list' => ListObject,
# business objects
- 'account' => Account,
- 'alipay_account' => AlipayAccount,
- 'application_fee' => ApplicationFee,
- 'balance' => Balance,
- 'balance_transaction' => BalanceTransaction,
- 'bank_account' => BankAccount,
- 'card' => Card,
- 'charge' => Charge,
- 'country_spec' => CountrySpec,
- 'coupon' => Coupon,
- 'customer' => Customer,
- 'event' => Event,
- 'fee_refund' => ApplicationFeeRefund,
- 'invoiceitem' => InvoiceItem,
- 'invoice' => Invoice,
- 'plan' => Plan,
- 'recipient' => Recipient,
- 'refund' => Refund,
- 'subscription' => Subscription,
- 'file_upload' => FileUpload,
- 'token' => Token,
- 'transfer' => Transfer,
- 'transfer_reversal' => Reversal,
- 'bitcoin_receiver' => BitcoinReceiver,
- 'bitcoin_transaction' => BitcoinTransaction,
- 'dispute' => Dispute,
- 'product' => Product,
- 'sku' => SKU,
- 'order' => Order,
- 'order_return' => OrderReturn,
- 'three_d_secure' => ThreeDSecure,
- 'apple_pay_domain' => ApplePayDomain,
+ 'account' => Account,
+ 'alipay_account' => AlipayAccount,
+ 'apple_pay_domain' => ApplePayDomain,
+ 'application_fee' => ApplicationFee,
+ 'balance' => Balance,
+ 'balance_transaction' => BalanceTransaction,
+ 'bank_account' => BankAccount,
+ 'bitcoin_receiver' => BitcoinReceiver,
+ 'bitcoin_transaction' => BitcoinTransaction,
+ 'card' => Card,
+ 'charge' => Charge,
+ 'country_spec' => CountrySpec,
+ 'coupon' => Coupon,
+ 'customer' => Customer,
+ 'dispute' => Dispute,
+ 'event' => Event,
+ 'fee_refund' => ApplicationFeeRefund,
+ 'file_upload' => FileUpload,
+ 'invoice' => Invoice,
+ 'invoiceitem' => InvoiceItem,
+ 'order' => Order,
+ 'order_return' => OrderReturn,
+ 'plan' => Plan,
+ 'product' => Product,
+ 'recipient' => Recipient,
+ 'refund' => Refund,
+ 'sku' => SKU,
+ 'subscription' => Subscription,
+ 'subscription_item' => SubscriptionItem,
+ 'token' => Token,
+ 'transfer' => Transfer,
+ 'transfer_reversal' => Reversal,
+ 'three_d_secure' => ThreeDSecure,
}
end
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
# array of +StripeObject+s. These new objects will be created as a concrete
@@ -116,9 +117,23 @@
# involves escaping special characters from parameter keys and values (e.g.
# `&`).
def self.encode_parameters(params)
Util.flatten_params(params).
map { |k,v| "#{url_encode(k)}=#{url_encode(v)}" }.join('&')
+ end
+
+ # Transforms an array into a hash with integer keys. Used for a small
+ # number of API endpoints. If the argument is not an Array, return it
+ # unchanged. Example: [{foo: 'bar'}] => {"0" => {foo: "bar"}}
+ def self.array_to_hash(array)
+ case array
+ when Array
+ hash = {}
+ array.each_with_index { |v,i| hash[i.to_s] = v }
+ hash
+ else
+ array
+ end
end
# Encodes a string in a way that makes it suitable for use in a set of
# query parameters in a URI or in a set of form parameters in a request
# body.