Class: ProcessOut::CardContact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the CardContact object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/processout/card_contact.rb', line 48

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)
  
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



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

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



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

def address2
  @address2
end

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



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

def country_code
  @country_code
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#zipObject

Returns the value of attribute zip.



16
17
18
# File 'lib/processout/card_contact.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



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
# File 'lib/processout/card_contact.rb', line 80

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
  
  self
end

#new(data = {}) ⇒ Object

Create a new CardContact using the current client



61
62
63
# File 'lib/processout/card_contact.rb', line 61

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

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/processout/card_contact.rb', line 109

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
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



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

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