Class: UspsApi::LabelsCommitment

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

Overview

The commitment and scheduled delivery date of the package.

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(name: SKIP, schedule_delivery_date: SKIP, expected_delivery_date: SKIP, is_priority_mail_next_day: SKIP, additional_properties: nil) ⇒ LabelsCommitment

Returns a new instance of LabelsCommitment.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/usps_api/models/labels_commitment.rb', line 59

def initialize(name: SKIP, schedule_delivery_date: SKIP,
               expected_delivery_date: SKIP,
               is_priority_mail_next_day: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @name = name unless name == SKIP
  @schedule_delivery_date = schedule_delivery_date unless schedule_delivery_date == SKIP
  @expected_delivery_date = expected_delivery_date unless expected_delivery_date == SKIP
  unless is_priority_mail_next_day == SKIP
    @is_priority_mail_next_day =
      is_priority_mail_next_day
  end
  @additional_properties = additional_properties
end

Instance Attribute Details

#expected_delivery_dateString

Date in the YYYY-MM-DD format.

Returns:

  • (String)


28
29
30
# File 'lib/usps_api/models/labels_commitment.rb', line 28

def expected_delivery_date
  @expected_delivery_date
end

#is_priority_mail_next_dayTrueClass | FalseClass

Indicates if the commitment is for Priority Mail Next Day service.

Returns:

  • (TrueClass | FalseClass)


32
33
34
# File 'lib/usps_api/models/labels_commitment.rb', line 32

def is_priority_mail_next_day
  @is_priority_mail_next_day
end

#nameString

Commitment name such as 1-day, 2-day, 3-day, Military, DPO.

Returns:

  • (String)


14
15
16
# File 'lib/usps_api/models/labels_commitment.rb', line 14

def name
  @name
end

#schedule_delivery_dateString

Date in the ‘YYYY-MM-DD` format. Date USPS expects that the package or mailpiece will be delivered based on the origin, destination, and drop-off time and date in the request. Actual delivery date may vary based on when the package or mailpiece is entered or other conditions. Note: This field has been deprecated in favor of `expectedDeliveryDate` and will be removed in a future release. Please transition to using `expectedDeliveryDate`.

Returns:

  • (String)


24
25
26
# File 'lib/usps_api/models/labels_commitment.rb', line 24

def schedule_delivery_date
  @schedule_delivery_date
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
95
96
97
98
99
100
101
# File 'lib/usps_api/models/labels_commitment.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : SKIP
  schedule_delivery_date =
    hash.key?('scheduleDeliveryDate') ? hash['scheduleDeliveryDate'] : SKIP
  expected_delivery_date =
    hash.key?('expectedDeliveryDate') ? hash['expectedDeliveryDate'] : SKIP
  is_priority_mail_next_day =
    hash.key?('isPriorityMailNextDay') ? hash['isPriorityMailNextDay'] : 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.
  LabelsCommitment.new(name: name,
                       schedule_delivery_date: schedule_delivery_date,
                       expected_delivery_date: expected_delivery_date,
                       is_priority_mail_next_day: is_priority_mail_next_day,
                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



35
36
37
38
39
40
41
42
# File 'lib/usps_api/models/labels_commitment.rb', line 35

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['schedule_delivery_date'] = 'scheduleDeliveryDate'
  @_hash['expected_delivery_date'] = 'expectedDeliveryDate'
  @_hash['is_priority_mail_next_day'] = 'isPriorityMailNextDay'
  @_hash
end

.nullablesObject

An array for nullable fields



55
56
57
# File 'lib/usps_api/models/labels_commitment.rb', line 55

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
50
51
52
# File 'lib/usps_api/models/labels_commitment.rb', line 45

def self.optionals
  %w[
    name
    schedule_delivery_date
    expected_delivery_date
    is_priority_mail_next_day
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



105
106
107
108
109
110
111
# File 'lib/usps_api/models/labels_commitment.rb', line 105

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



122
123
124
125
126
127
128
# File 'lib/usps_api/models/labels_commitment.rb', line 122

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

#to_sObject

Provides a human-readable string representation of the object.



114
115
116
117
118
119
# File 'lib/usps_api/models/labels_commitment.rb', line 114

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