Class: KondutoOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/konduto-ruby/konduto_order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ KondutoOrder

Returns a new instance of KondutoOrder.


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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/konduto-ruby/konduto_order.rb', line 22

def initialize(*args)
  params = args[0]
  self.shopping_cart = []
  self.payment = []
  if params.nil?
    self.shipping_address = KondutoAddress.new
    self.billing_address = KondutoAddress.new
    self.customer = KondutoCustomer.new
    self.seller = KondutoSeller.new
    self.travel = KondutoTravel.new
    self.device = KondutoDevice.new
    self.geolocation = KondutoGeolocation.new
    self.navigation = KondutoNavigation.new
  else
    params = KondutoUtils.deep_symbolize_keys params
    if params[shipping_address].nil?
      self.shipping_address = KondutoAddress.new
    else
      self.shipping_address = KondutoAddress.new params[:shipping_address]
      params.delete :shipping_address
    end

    if params[:billing_address].nil?
      self.billing_address = KondutoAddress.new
    else
      self.billing_address = KondutoAddress.new params[:billing_address]
      params.delete :billing_address
    end

    if params[:customer].nil?
      self.customer = KondutoCustomer.new
    else
      self.customer = KondutoCustomer.new params[:customer]
      params.delete :customer
    end

    if params[:seller].nil?
      self.seller = KondutoSeller.new
    else
      self.seller = KondutoSeller.new params[:seller]
      params.delete :seller
    end

    if params[:travel].nil?
      self.travel = KondutoTravel.new
    else
      self.travel = KondutoTravel.new params[:travel]
      params.delete :travel
    end

    if params[:device].nil?
      self.device = KondutoDevice.new
    else
      self.device = KondutoDevice.new params[:device]
      params.delete :device
    end

    if params[:geolocation].nil?
      self.geolocation = KondutoGeolocation.new
    else
      self.geolocation = KondutoGeolocation.new params[:geolocation]
      params.delete :geolocation
    end

    if params[:navigation].nil?
      self.navigation = KondutoNavigation.new
    else
      self.navigation = KondutoNavigation.new params[:navigation]
      params.delete :navigation
    end

    unless params[:payment].nil? || params[:payment].empty?
      params[:payment].each do |p|
        self.payment << KondutoPayment.new(p)
      end
      params.delete :payment
    end

    unless params[:shopping_cart].nil? || params[:shopping_cart].empty?
      params[:shopping_cart].each do |i|
        self.shopping_cart << KondutoItem.new(i)
      end
      params.delete :shopping_cart
    end

    params.each do |k,v|
      instance_variable_set("@#{k}", v) unless v.nil?
    end
  end
end

Instance Attribute Details

#analyzeObject

Returns the value of attribute analyze


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def analyze
  @analyze
end

#billing_addressObject

Returns the value of attribute billing_address


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def billing_address
  @billing_address
end

#currencyObject

Returns the value of attribute currency


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def currency
  @currency
end

#customerObject

Returns the value of attribute customer


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def customer
  @customer
end

#deviceObject

Returns the value of attribute device


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def device
  @device
end

#first_messageObject

Returns the value of attribute first_message


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def first_message
  @first_message
end

#geolocationObject

Returns the value of attribute geolocation


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def geolocation
  @geolocation
end

#idObject

Returns the value of attribute id


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def id
  @id
end

#installmentsObject

Returns the value of attribute installments


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def installments
  @installments
end

#ipObject

Returns the value of attribute ip


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def ip
  @ip
end

#messages_enchangedObject

Returns the value of attribute messages_enchanged


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def messages_enchanged
  @messages_enchanged
end

Returns the value of attribute navigation


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def navigation
  @navigation
end

#paymentObject

Returns the value of attribute payment


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def payment
  @payment
end

#purchased_atObject

Returns the value of attribute purchased_at


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def purchased_at
  @purchased_at
end

#recommendationObject

Returns the value of attribute recommendation


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def recommendation
  @recommendation
end

#scoreObject

Returns the value of attribute score


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def score
  @score
end

#sellerObject

Returns the value of attribute seller


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def seller
  @seller
end

#shipping_addressObject

Returns the value of attribute shipping_address


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def shipping_address
  @shipping_address
end

#shipping_amountObject

Returns the value of attribute shipping_amount


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def shipping_amount
  @shipping_amount
end

#shopping_cartObject

Returns the value of attribute shopping_cart


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def shopping_cart
  @shopping_cart
end

#statusObject

Returns the value of attribute status


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def status
  @status
end

#tax_amountObject

Returns the value of attribute tax_amount


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def tax_amount
  @tax_amount
end

#timestampObject

Returns the value of attribute timestamp


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def timestamp
  @timestamp
end

#total_amountObject

Returns the value of attribute total_amount


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def total_amount
  @total_amount
end

#travelObject

Returns the value of attribute travel


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def travel
  @travel
end

#visitorObject

Returns the value of attribute visitor


17
18
19
# File 'lib/konduto-ruby/konduto_order.rb', line 17

def visitor
  @visitor
end

Instance Method Details

#add_item(product) ⇒ Object


113
114
115
# File 'lib/konduto-ruby/konduto_order.rb', line 113

def add_item (product)
  self.shopping_cart << product
end

#add_payment(payment) ⇒ Object


117
118
119
# File 'lib/konduto-ruby/konduto_order.rb', line 117

def add_payment (payment)
  self.payment << payment
end

#to_hashObject


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/konduto-ruby/konduto_order.rb', line 121

def to_hash
  hash = {
      id:self.id,
      visitor:self.visitor,
      total_amount:self.total_amount,
      shipping_amount:self.shipping_amount,
      tax_amount:self.tax_amount,
      currency:self.currency,
      installments:self.installments,
      ip:self.ip,
      first_message:self.first_message,
      messages_exchanged:self.messages_enchanged,
      purchased_at:self.purchased_at,
      analyze:self.analyze,
      customer:self.customer.to_hash,
      payment: KondutoUtils.array_to_hash(self.payment),
      billing:self.billing_address.to_hash,
      shipping:self.shipping_address.to_hash,
      shopping_cart:KondutoUtils.array_to_hash(self.shopping_cart),
      travel:self.travel.to_hash,
      seller:self.seller.to_hash,
      device:self.device.to_hash,
      geolocation:self.geolocation.to_hash,
      navigation:self.navigation.to_hash
  }
  KondutoUtils.remove_nil_keys_from_hash(hash)
end

#to_jsonObject


149
150
151
# File 'lib/konduto-ruby/konduto_order.rb', line 149

def to_json
  self.to_hash.to_json
end