Class: ProcessOut::CardShipping

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/card_shipping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ CardShipping

Initializes the CardShipping object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/processout/card_shipping.rb', line 65

def initialize(client, data = {})
  @client = client

  self.address1 = data.fetch(:address1, nil)
  self.address2 = data.fetch(:address2, nil)
  self.city = data.fetch(:city, nil)
  self.state = data.fetch(:state, nil)
  self.country_code = data.fetch(:country_code, nil)
  self.zip = data.fetch(:zip, nil)
  self.phone = data.fetch(:phone, nil)
  
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



11
12
13
# File 'lib/processout/card_shipping.rb', line 11

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



12
13
14
# File 'lib/processout/card_shipping.rb', line 12

def address2
  @address2
end

#cityObject

Returns the value of attribute city.



13
14
15
# File 'lib/processout/card_shipping.rb', line 13

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



15
16
17
# File 'lib/processout/card_shipping.rb', line 15

def country_code
  @country_code
end

#phoneObject

Returns the value of attribute phone.



17
18
19
# File 'lib/processout/card_shipping.rb', line 17

def phone
  @phone
end

#stateObject

Returns the value of attribute state.



14
15
16
# File 'lib/processout/card_shipping.rb', line 14

def state
  @state
end

#zipObject

Returns the value of attribute zip.



16
17
18
# File 'lib/processout/card_shipping.rb', line 16

def zip
  @zip
end

Instance Method Details

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/processout/card_shipping.rb', line 99

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "address1"
    self.address1 = data["address1"]
  end
  if data.include? "address2"
    self.address2 = data["address2"]
  end
  if data.include? "city"
    self.city = data["city"]
  end
  if data.include? "state"
    self.state = data["state"]
  end
  if data.include? "country_code"
    self.country_code = data["country_code"]
  end
  if data.include? "zip"
    self.zip = data["zip"]
  end
  if data.include? "phone"
    self.phone = data["phone"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new CardShipping using the current client



79
80
81
# File 'lib/processout/card_shipping.rb', line 79

def new(data = {})
  CardShipping.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/processout/card_shipping.rb', line 131

def prefill(data)
  if data.nil?
    return self
  end
  self.address1 = data.fetch(:address1, self.address1)
  self.address2 = data.fetch(:address2, self.address2)
  self.city = data.fetch(:city, self.city)
  self.state = data.fetch(:state, self.state)
  self.country_code = data.fetch(:country_code, self.country_code)
  self.zip = data.fetch(:zip, self.zip)
  self.phone = data.fetch(:phone, self.phone)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/processout/card_shipping.rb', line 84

def to_json(options)
  {
      "address1": self.address1,
      "address2": self.address2,
      "city": self.city,
      "state": self.state,
      "country_code": self.country_code,
      "zip": self.zip,
      "phone": self.phone,
  }.to_json
end