lib/stripe/util.rb in stripe-1.8.3 vs lib/stripe/util.rb in stripe-1.8.4
- old
+ new
@@ -13,38 +13,41 @@
else
h
end
end
- def self.convert_to_stripe_object(resp, api_key)
- types = {
+ def self.object_classes
+ @object_classes ||= {
'charge' => Charge,
'customer' => Customer,
'invoiceitem' => InvoiceItem,
'invoice' => Invoice,
'plan' => Plan,
'coupon' => Coupon,
'event' => Event,
'transfer' => Transfer,
'recipient' => Recipient,
+ 'card' => Card,
'list' => ListObject
}
+ end
+
+ def self.convert_to_stripe_object(resp, api_key)
case resp
when Array
resp.map { |i| convert_to_stripe_object(i, api_key) }
when Hash
- # Try converting to a known object class. If none available, fall back to generic APIResource
- if klass_name = resp[:object]
- klass = types[klass_name]
- end
- klass ||= StripeObject
- klass.construct_from(resp, api_key)
+ # Try converting to a known object class. If none available, fall back to generic StripeObject
+ object_classes.fetch(resp[:object], StripeObject).construct_from(resp, api_key)
else
resp
end
end
def self.file_readable(file)
+ # This is nominally equivalent to File.readable?, but that can
+ # report incorrect results on some more oddball filesystems
+ # (such as AFS)
begin
File.open(file) { |f| }
rescue
false
else