Class: UspsApi::TrackingSubscriptionBasedOnAMid

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

Overview

Filter by MID

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(mid:, tracking_event_types: SKIP, additional_properties: nil) ⇒ TrackingSubscriptionBasedOnAMid

Returns a new instance of TrackingSubscriptionBasedOnAMid.



65
66
67
68
69
70
71
72
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 65

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

  @mid = mid
  @tracking_event_types = tracking_event_types unless tracking_event_types == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#midString

Specify the Mailer ID that should be included in the subscription. Once a subscription is created this field cannot be changed through a future edit, instead the subscription should be deleted and a new subscription should be created.

Returns:

  • (String)


17
18
19
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 17

def mid
  @mid
end

#tracking_event_typesArray[TrackingEventType]

Specify what tracking events should be include in the subscription: </p> ALL - All Below Updates </p> PACKAGE_DELIVERED - Receive a message when package has been delivered to the recipient’s

address or when it's been delivered to a

delivery partner (if applicable). </p> AVAILABLE_FOR_PICKUP - Receive a message when your package is ready to be picked up at your

local Post Office location. </p>

DELIVERY_EXCEPTION_UPDATES - Receive a message when there are other delivery updates, alerts

about potential delays (including

weather-related delays), or

actions needed (e.g., Schedule Redelivery)

related to your package. (Exceptions?)</p> PACKAGE_IN_TRANSIT_UPDATES - Receive a message when your package is in-transit with the current

expected delivery date, if available.

(InTransit?)</p> PACKAGE_DELAYED - Package has been delayed</p> DEFAULT - Includes PACKAGE_DELIVERED, AVAILABLE_FOR_PICKUP, DELIVERY_EXCEPTION_UPDATES, and PACKAGE_IN_TRANSIT_UPDATES

Returns:



43
44
45
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 43

def tracking_event_types
  @tracking_event_types
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mid = hash.key?('MID') ? hash['MID'] : nil
  tracking_event_types =
    hash.key?('trackingEventTypes') ? hash['trackingEventTypes'] : 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.
  TrackingSubscriptionBasedOnAMid.new(mid: mid,
                                      tracking_event_types: tracking_event_types,
                                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['mid'] = 'MID'
  @_hash['tracking_event_types'] = 'trackingEventTypes'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 61

def self.nullables
  []
end

.optionalsObject

An array for optional fields



54
55
56
57
58
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 54

def self.optionals
  %w[
    tracking_event_types
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 98

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

  return false unless value.instance_of? Hash

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



118
119
120
121
122
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 118

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

#to_sObject

Provides a human-readable string representation of the object.



111
112
113
114
115
# File 'lib/usps_api/models/tracking_subscription_based_on_a_mid.rb', line 111

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