Module: Conekta::Util
- Defined in:
- lib/conekta/util.rb
Class Method Summary collapse
Class Method Details
.convert_to_conekta_object(name, resp) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/conekta/util.rb', line 22 def self.convert_to_conekta_object(name,resp) if resp.kind_of?(Hash) if resp.has_key?('object') and types[resp['object']] instance = types[resp['object']].new() instance.load_from(resp) return instance elsif name.instance_of? String name = "event_data" if camelize(name) == "Data" name = "obj" if camelize(name) == "Object" if !Object.const_defined?(camelize(name)) instance = Object.const_set(camelize(name), Class.new(ConektaObject)).new else instance = constantize(camelize(name)).new end instance.load_from(resp) return instance end end if resp.kind_of?(Array) instance = ConektaObject.new instance.load_from(resp) if !resp.empty? and resp.first.instance_of? Hash and !resp.first["object"] resp.each_with_index do |r, i| obj = convert_to_conekta_object(name,r) instance.set_val(i,obj) instance[i] = obj end end return instance end return instance end |
.types ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/conekta/util.rb', line 3 def self.types @types ||= { 'webhook_log' => WebhookLog, 'bank_transfer_payout_method' => Method, 'payout' => Payout, 'payee' => Payee, 'payout_method' => PayoutMethod, 'bank_transfer_payment' => PaymentMethod, 'card_payment' => PaymentMethod, 'cash_payment' => PaymentMethod, 'charge' => Charge, 'customer' => Customer, 'card' => Card, 'subscription' => Subscription, 'plan' => Plan, 'token' => Token, 'event' => Event } end |