Class: NewStoreApi::AddressModel

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/address_model.rb

Overview

Address model request without autogenerated fields like created_at, token, id, etc..

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(country_code = nil, address_line_1 = SKIP, address_line_2 = SKIP, city = SKIP, company_name = SKIP, contact_phone = SKIP, full_name = SKIP, state = SKIP, zip_code = SKIP) ⇒ AddressModel

Returns a new instance of AddressModel.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/new_store_api/models/address_model.rb', line 87

def initialize(country_code = nil, address_line_1 = SKIP,
               address_line_2 = SKIP, city = SKIP, company_name = SKIP,
               contact_phone = SKIP, full_name = SKIP, state = SKIP,
               zip_code = SKIP)
  @address_line_1 = address_line_1 unless address_line_1 == SKIP
  @address_line_2 = address_line_2 unless address_line_2 == SKIP
  @city = city unless city == SKIP
  @company_name = company_name unless company_name == SKIP
  @contact_phone = contact_phone unless contact_phone == SKIP
  @country_code = country_code
  @full_name = full_name unless full_name == SKIP
  @state = state unless state == SKIP
  @zip_code = zip_code unless zip_code == SKIP
end

Instance Attribute Details

#address_line_1String

First line of the address. Typically, the street and house number.

Returns:

  • (String)


15
16
17
# File 'lib/new_store_api/models/address_model.rb', line 15

def address_line_1
  @address_line_1
end

#address_line_2String

Second line of the address. Typically, the apartment number or PO box

Returns:

  • (String)


19
20
21
# File 'lib/new_store_api/models/address_model.rb', line 19

def address_line_2
  @address_line_2
end

#cityString

The city/town of the address.

Returns:

  • (String)


23
24
25
# File 'lib/new_store_api/models/address_model.rb', line 23

def city
  @city
end

#company_nameString

Company name.

Returns:

  • (String)


27
28
29
# File 'lib/new_store_api/models/address_model.rb', line 27

def company_name
  @company_name
end

#contact_phoneString

Phone number of the address.

Returns:

  • (String)


31
32
33
# File 'lib/new_store_api/models/address_model.rb', line 31

def contact_phone
  @contact_phone
end

#country_codeString

Country code in ISO 3166-1 alpha-2 format.

Returns:

  • (String)


35
36
37
# File 'lib/new_store_api/models/address_model.rb', line 35

def country_code
  @country_code
end

#full_nameString

Full name.

Returns:

  • (String)


39
40
41
# File 'lib/new_store_api/models/address_model.rb', line 39

def full_name
  @full_name
end

#stateString

State/province or region of the address.

Returns:

  • (String)


43
44
45
# File 'lib/new_store_api/models/address_model.rb', line 43

def state
  @state
end

#zip_codeString

Postal code of the address.

Returns:

  • (String)


47
48
49
# File 'lib/new_store_api/models/address_model.rb', line 47

def zip_code
  @zip_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/new_store_api/models/address_model.rb', line 103

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  country_code = hash.key?('country_code') ? hash['country_code'] : nil
  address_line_1 =
    hash.key?('address_line_1') ? hash['address_line_1'] : SKIP
  address_line_2 =
    hash.key?('address_line_2') ? hash['address_line_2'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  company_name = hash.key?('company_name') ? hash['company_name'] : SKIP
  contact_phone = hash.key?('contact_phone') ? hash['contact_phone'] : SKIP
  full_name = hash.key?('full_name') ? hash['full_name'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP
  zip_code = hash.key?('zip_code') ? hash['zip_code'] : SKIP

  # Create object from extracted values.
  AddressModel.new(country_code,
                   address_line_1,
                   address_line_2,
                   city,
                   company_name,
                   contact_phone,
                   full_name,
                   state,
                   zip_code)
end

.namesObject

A mapping from model property names to API property names.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/new_store_api/models/address_model.rb', line 50

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['address_line_1'] = 'address_line_1'
  @_hash['address_line_2'] = 'address_line_2'
  @_hash['city'] = 'city'
  @_hash['company_name'] = 'company_name'
  @_hash['contact_phone'] = 'contact_phone'
  @_hash['country_code'] = 'country_code'
  @_hash['full_name'] = 'full_name'
  @_hash['state'] = 'state'
  @_hash['zip_code'] = 'zip_code'
  @_hash
end

.nullablesObject

An array for nullable fields



79
80
81
82
83
84
85
# File 'lib/new_store_api/models/address_model.rb', line 79

def self.nullables
  %w[
    company_name
    contact_phone
    state
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    address_line_1
    address_line_2
    city
    company_name
    contact_phone
    full_name
    state
    zip_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



141
142
143
144
145
146
147
148
# File 'lib/new_store_api/models/address_model.rb', line 141

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line_1: #{@address_line_1.inspect}, address_line_2:"\
  " #{@address_line_2.inspect}, city: #{@city.inspect}, company_name:"\
  " #{@company_name.inspect}, contact_phone: #{@contact_phone.inspect}, country_code:"\
  " #{@country_code.inspect}, full_name: #{@full_name.inspect}, state: #{@state.inspect},"\
  " zip_code: #{@zip_code.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



132
133
134
135
136
137
138
# File 'lib/new_store_api/models/address_model.rb', line 132

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line_1: #{@address_line_1}, address_line_2: #{@address_line_2},"\
  " city: #{@city}, company_name: #{@company_name}, contact_phone: #{@contact_phone},"\
  " country_code: #{@country_code}, full_name: #{@full_name}, state: #{@state}, zip_code:"\
  " #{@zip_code}>"
end