Module: Conekta::Util
- Defined in:
- lib/conekta/util.rb
Class Method Summary collapse
Class Method Details
.convert_to_conekta_object(name, resp) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/conekta/util.rb', line 43 def self.convert_to_conekta_object(name,resp) # these json strings should not be parsed into objects return resp if ["data", "request_body", "request_headers", "response_headers", "response_body", "query_string", "metadata", "vertical_info"].include?(name) if resp.kind_of?(Hash) if resp.has_key?('object') and types[resp['object']] if resp['object'] == "list" instance = types[resp['object']].new(name, resp) else instance = types[resp['object']].new() end instance.load_from(resp) return instance elsif name.instance_of? String name = "shippin_line_method" if name == "method" 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 begin instance = constantize("Conekta::"+camelize(name)).new rescue # Class is not defined instance = constantize(camelize(name)).new end 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
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/conekta/util.rb', line 4 def self.types @types ||= { 'customer_info' => ::Conekta::CustomerInfo, 'details' => ::Conekta::Details, 'bank_transfer_payment' => ::Conekta::PaymentMethod, 'bank_transfer_payout_method' => ::Conekta::Method, 'card' => ::Conekta::Card, 'card_payment' => ::Conekta::PaymentMethod, 'cash_payment' => ::Conekta::PaymentMethod, 'charge' => ::Conekta::Charge, 'customer' => ::Conekta::Customer, 'event' => ::Conekta::Event, 'log' => ::Conekta::Log, 'payee' => ::Conekta::Payee, 'payout' => ::Conekta::Payout, 'payout_method' => ::Conekta::PayoutMethod, 'destination' => ::Conekta::Destination, 'plan' => ::Conekta::Plan, 'subscription' => ::Conekta::Subscription, 'token' => ::Conekta::Token, 'webhook' => ::Conekta::Webhook, 'webhook_log' => ::Conekta::WebhookLog, 'refund' => ::Conekta::Refund, 'line_item' => ::Conekta::LineItem, 'address' => ::Conekta::Address, 'billing_address' => ::Conekta::Address, 'shipping_address' => ::Conekta::Address, 'order' => ::Conekta::Order, 'payment_source' => ::Conekta::PaymentSource, 'tax_line' => ::Conekta::TaxLine, 'shipping_line' => ::Conekta::ShippingLine, 'discount_line' => ::Conekta::DiscountLine, 'fiscal_entity' => ::Conekta::FiscalEntity, 'shipping_contact' => ::Conekta::ShippingContact, 'list' => ::Conekta::List, 'return' => ::Conekta::Return } end |
.underscore(str) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/conekta/util.rb', line 92 def self.underscore(str) str.split(/::/).last. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |