Class: NewStoreApi::ShippingAddress

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

Overview

Shipping address of the customer used for risk assessment only.

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(city = SKIP, country = SKIP, house_number = SKIP, postal_code = SKIP, state = SKIP, street = SKIP) ⇒ ShippingAddress

Returns a new instance of ShippingAddress.



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

def initialize(city = SKIP, country = SKIP, house_number = SKIP,
               postal_code = SKIP, state = SKIP, street = SKIP)
  @city = city unless city == SKIP
  @country = country unless country == SKIP
  @house_number = house_number unless house_number == SKIP
  @postal_code = postal_code unless postal_code == SKIP
  @state = state unless state == SKIP
  @street = street unless street == SKIP
end

Instance Attribute Details

#cityString

City

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/shipping_address.rb', line 14

def city
  @city
end

#countryString

Two-letter country code

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/shipping_address.rb', line 18

def country
  @country
end

#house_numberString

House number

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/shipping_address.rb', line 22

def house_number
  @house_number
end

#postal_codeString

Zip code

Returns:

  • (String)


26
27
28
# File 'lib/new_store_api/models/shipping_address.rb', line 26

def postal_code
  @postal_code
end

#stateString

State or province

Returns:

  • (String)


30
31
32
# File 'lib/new_store_api/models/shipping_address.rb', line 30

def state
  @state
end

#streetString

Street name

Returns:

  • (String)


34
35
36
# File 'lib/new_store_api/models/shipping_address.rb', line 34

def street
  @street
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/new_store_api/models/shipping_address.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  city = hash.key?('city') ? hash['city'] : SKIP
  country = hash.key?('country') ? hash['country'] : SKIP
  house_number = hash.key?('house_number') ? hash['house_number'] : SKIP
  postal_code = hash.key?('postal_code') ? hash['postal_code'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP
  street = hash.key?('street') ? hash['street'] : SKIP

  # Create object from extracted values.
  ShippingAddress.new(city,
                      country,
                      house_number,
                      postal_code,
                      state,
                      street)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/new_store_api/models/shipping_address.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['city'] = 'city'
  @_hash['country'] = 'country'
  @_hash['house_number'] = 'house_number'
  @_hash['postal_code'] = 'postal_code'
  @_hash['state'] = 'state'
  @_hash['street'] = 'street'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/new_store_api/models/shipping_address.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



49
50
51
52
53
54
55
56
57
58
# File 'lib/new_store_api/models/shipping_address.rb', line 49

def self.optionals
  %w[
    city
    country
    house_number
    postal_code
    state
    street
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



104
105
106
107
108
109
# File 'lib/new_store_api/models/shipping_address.rb', line 104

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} city: #{@city.inspect}, country: #{@country.inspect}, house_number:"\
  " #{@house_number.inspect}, postal_code: #{@postal_code.inspect}, state: #{@state.inspect},"\
  " street: #{@street.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



97
98
99
100
101
# File 'lib/new_store_api/models/shipping_address.rb', line 97

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} city: #{@city}, country: #{@country}, house_number: #{@house_number},"\
  " postal_code: #{@postal_code}, state: #{@state}, street: #{@street}>"
end