Class: Asdawqw::Location

Inherits:
BaseModel show all
Defined in:
lib/asdawqw/models/location.rb

Overview

Location Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(postal_code = nil, country = nil, region = nil, city = nil, street = nil, zip_code9 = nil) ⇒ Location

Returns a new instance of Location.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/asdawqw/models/location.rb', line 45

def initialize(postal_code = nil,
               country = nil,
               region = nil,
               city = nil,
               street = nil,
               zip_code9 = nil)
  @postal_code = postal_code
  @country = country
  @region = region
  @city = city
  @street = street
  @zip_code9 = zip_code9
end

Instance Attribute Details

#cityString

City of property

Returns:



23
24
25
# File 'lib/asdawqw/models/location.rb', line 23

def city
  @city
end

#countryString

Country of property. Require 2 letter ISO code

Returns:



15
16
17
# File 'lib/asdawqw/models/location.rb', line 15

def country
  @country
end

#postal_codeString

Postal code of property (Zip code)

Returns:



11
12
13
# File 'lib/asdawqw/models/location.rb', line 11

def postal_code
  @postal_code
end

#regionString

State (Region) of PM. Required for US properties.

Returns:



19
20
21
# File 'lib/asdawqw/models/location.rb', line 19

def region
  @region
end

#streetString

Street of property

Returns:



27
28
29
# File 'lib/asdawqw/models/location.rb', line 27

def street
  @street
end

#zip_code9String

Set only for US properties (format should be zip5-xxxx)

Returns:



31
32
33
# File 'lib/asdawqw/models/location.rb', line 31

def zip_code9
  @zip_code9
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/asdawqw/models/location.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  postal_code = hash['postalCode']
  country = hash['country']
  region = hash['region']
  city = hash['city']
  street = hash['street']
  zip_code9 = hash['zipCode9']

  # Create object from extracted values.
  Location.new(postal_code,
               country,
               region,
               city,
               street,
               zip_code9)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
43
# File 'lib/asdawqw/models/location.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['postal_code'] = 'postalCode'
  @_hash['country'] = 'country'
  @_hash['region'] = 'region'
  @_hash['city'] = 'city'
  @_hash['street'] = 'street'
  @_hash['zip_code9'] = 'zipCode9'
  @_hash
end