Class: Courier::Profiles::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/profiles/types/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatted:, street_address:, locality:, region:, postal_code:, country:, additional_properties: nil) ⇒ Profiles::Address

Parameters:

  • formatted (String)
  • street_address (String)
  • locality (String)
  • region (String)
  • postal_code (String)
  • country (String)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/trycourier/profiles/types/address.rb', line 18

def initialize(formatted:, street_address:, locality:, region:, postal_code:, country:,
               additional_properties: nil)
  # @type [String]
  @formatted = formatted
  # @type [String]
  @street_address = street_address
  # @type [String]
  @locality = locality
  # @type [String]
  @region = region
  # @type [String]
  @postal_code = postal_code
  # @type [String]
  @country = country
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def additional_properties
  @additional_properties
end

#countryObject (readonly)

Returns the value of attribute country.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def country
  @country
end

#formattedObject (readonly)

Returns the value of attribute formatted.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def formatted
  @formatted
end

#localityObject (readonly)

Returns the value of attribute locality.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def locality
  @locality
end

#postal_codeObject (readonly)

Returns the value of attribute postal_code.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def postal_code
  @postal_code
end

#regionObject (readonly)

Returns the value of attribute region.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def region
  @region
end

#street_addressObject (readonly)

Returns the value of attribute street_address.



8
9
10
# File 'lib/trycourier/profiles/types/address.rb', line 8

def street_address
  @street_address
end

Class Method Details

.from_json(json_object:) ⇒ Profiles::Address

Deserialize a JSON object to an instance of Address

Parameters:

  • json_object (JSON)

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/trycourier/profiles/types/address.rb', line 40

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  formatted = struct.formatted
  street_address = struct.street_address
  locality = struct.locality
  region = struct.region
  postal_code = struct.postal_code
  country = struct.country
  new(formatted: formatted, street_address: street_address, locality: locality, region: region,
      postal_code: postal_code, country: country, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


71
72
73
74
75
76
77
78
# File 'lib/trycourier/profiles/types/address.rb', line 71

def self.validate_raw(obj:)
  obj.formatted.is_a?(String) != false || raise("Passed value for field obj.formatted is not the expected type, validation failed.")
  obj.street_address.is_a?(String) != false || raise("Passed value for field obj.street_address is not the expected type, validation failed.")
  obj.locality.is_a?(String) != false || raise("Passed value for field obj.locality is not the expected type, validation failed.")
  obj.region.is_a?(String) != false || raise("Passed value for field obj.region is not the expected type, validation failed.")
  obj.postal_code.is_a?(String) != false || raise("Passed value for field obj.postal_code is not the expected type, validation failed.")
  obj.country.is_a?(String) != false || raise("Passed value for field obj.country is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of Address to a JSON object

Returns:

  • (JSON)


56
57
58
59
60
61
62
63
64
65
# File 'lib/trycourier/profiles/types/address.rb', line 56

def to_json(*_args)
  {
    "formatted": @formatted,
    "street_address": @street_address,
    "locality": @locality,
    "region": @region,
    "postal_code": @postal_code,
    "country": @country
  }.to_json
end