Class: UspsApi::Manifest

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/manifest.rb

Overview

Manifest Model.

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(containers:, mailing_date: SKIP, additional_properties: nil) ⇒ Manifest

Returns a new instance of Manifest.



48
49
50
51
52
53
54
55
# File 'lib/usps_api/models/manifest.rb', line 48

def initialize(containers:, mailing_date: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @mailing_date = mailing_date unless mailing_date == SKIP
  @containers = containers
  @additional_properties = additional_properties
end

Instance Attribute Details

#containersArray[String]

The mailing date for when the container will be shipped, when included in the request all packages nested to the container will be updated to align with the associated mailingDate. The mailing date may be today plus 0 to 7 days in advance. If it is not provided it will be set as today.

Returns:

  • (Array[String])


26
27
28
# File 'lib/usps_api/models/manifest.rb', line 26

def containers
  @containers
end

#mailing_dateObject

The mailing date for when the container will be shipped, when included in the request all packages nested to the container will be updated to align with the associated mailingDate. The mailing date may be today plus 0 to 7 days in advance. If it is not provided it will be set as today.

Returns:

  • (Object)


18
19
20
# File 'lib/usps_api/models/manifest.rb', line 18

def mailing_date
  @mailing_date
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  containers = hash.key?('containers') ? hash['containers'] : nil
  mailing_date = hash.key?('mailingDate') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ManifestMailingDate), hash['mailingDate']
  ) : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Manifest.new(containers: containers,
               mailing_date: mailing_date,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
# File 'lib/usps_api/models/manifest.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['mailing_date'] = 'mailingDate'
  @_hash['containers'] = 'containers'
  @_hash
end

.nullablesObject

An array for nullable fields



44
45
46
# File 'lib/usps_api/models/manifest.rb', line 44

def self.nullables
  []
end

.optionalsObject

An array for optional fields



37
38
39
40
41
# File 'lib/usps_api/models/manifest.rb', line 37

def self.optionals
  %w[
    mailing_date
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Manifest | Hash)

    value against the validation is performed.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/usps_api/models/manifest.rb', line 88

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.containers,
                                 ->(val) { val.instance_of? String })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['containers'],
                        ->(val) { val.instance_of? String })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



108
109
110
111
112
# File 'lib/usps_api/models/manifest.rb', line 108

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} mailing_date: #{@mailing_date.inspect}, containers: #{@containers.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



101
102
103
104
105
# File 'lib/usps_api/models/manifest.rb', line 101

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} mailing_date: #{@mailing_date}, containers: #{@containers},"\
  " additional_properties: #{@additional_properties}>"
end

#to_union_type_mailing_dateObject



80
81
82
83
84
# File 'lib/usps_api/models/manifest.rb', line 80

def to_union_type_mailing_date
  UnionTypeLookUp.get(:ManifestMailingDate)
                 .validate(mailing_date)
                 .serialize(mailing_date)
end