Class: MuffinMan::RequestHelpers::OutboundFulfillment::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/muffin_man/request_helpers/outbound_fulfillment/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

json_body, #json_body

Constructor Details

#initialize(attributes = {}) ⇒ Address

Initializes the object rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



14
15
16
17
18
19
20
21
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
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 14

def initialize(attributes = {})
  super
  return unless attributes.is_a?(Hash)

  attributes = attributes.with_indifferent_access

  self.name = attributes["name"] if attributes.key?("name")

  if attributes.key?("address_line1") || attributes.key?("line1")
    self.address_line1 = attributes["address_line1"] || attributes["line1"]
  end

  if attributes.key?("address_line2") || attributes.key?("line2")
    self.address_line2 = attributes["address_line2"] || attributes["line2"]
  end

  if attributes.key?("address_line3") || attributes.key?("line3")
    self.address_line3 = attributes["address_line3"] || attributes("line3")
  end

  self.city = attributes["city"] if attributes.key?("city")

  self.district_or_county = attributes["district_or_county"] if attributes.key?("district_or_county")

  if attributes.key?("state_or_region") || attributes.key?("state_or_province_code")
    self.state_or_region = attributes["state_or_region"] || attributes["state_or_province_code"]
  end

  self.postal_code = attributes["postal_code"] if attributes.key?("postal_code")

  self.country_code = attributes["country_code"] if attributes.key?("country_code")

  self.phone = attributes["phone"] if attributes.key?("phone")
end

Instance Attribute Details

#address_line1Object

Returns the value of attribute address_line1.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def address_line1
  @address_line1
end

#address_line2Object

Returns the value of attribute address_line2.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def address_line2
  @address_line2
end

#address_line3Object

Returns the value of attribute address_line3.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def address_line3
  @address_line3
end

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def country_code
  @country_code
end

#district_or_countyObject

Returns the value of attribute district_or_county.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def district_or_county
  @district_or_county
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def phone
  @phone
end

#postal_codeObject

Returns the value of attribute postal_code.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def postal_code
  @postal_code
end

#state_or_regionObject

Returns the value of attribute state_or_region.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 7

def state_or_region
  @state_or_region
end

Instance Method Details

#errorsObject

Show invalid properties with the reasons. return Array for invalid properties with the reasons



63
64
65
66
67
68
69
70
71
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 63

def errors
  errors = []
  errors.push('"name" cannot be nil.') if name.blank?
  errors.push('"address_line1" cannot be nil.') if address_line1.blank?
  errors.push('"state_or_region" cannot be nil.') if state_or_region.blank?
  errors.push('"country_code" cannot be nil.') if country_code.blank?

  errors
end

#to_camelizeObject

Format request object in sp-api request format

Returns:

  • hash for sp-api request format



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 75

def to_camelize
  {
    "name" => name,
    "addressLine1" => address_line1,
    "addressLine2" => address_line2,
    "addressLine3" => address_line3,
    "city" => city,
    "districtOrCounty" => district_or_county,
    "stateOrRegion" => state_or_region,
    "countryCode" => country_code,
    "postalCode" => postal_code,
    "phone" => phone
  }
end

#valid?Boolean

return true if the model is valid

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/address.rb', line 52

def valid?
  return false if name.blank?
  return false if address_line1.blank?
  return false if state_or_region.blank?
  return false if country_code.blank?

  true
end