Class: UspsApi::SubscriptionsPackageTransactionDetailsSubscription

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

Overview

Subscription for the package transaction details event data the consumer is receiving.

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(listener_url:, secret:, admin_notification:, filter_properties:, subscription_id: SKIP, status: SKIP, status_reason: SKIP, creation_timestamp: SKIP, status_change_timestamp: SKIP, expiration_timestamp: SKIP, subscription_type: SKIP, additional_properties: nil) ⇒ SubscriptionsPackageTransactionDetailsSubscription

Returns a new instance of SubscriptionsPackageTransactionDetailsSubscription.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 106

def initialize(listener_url:, secret:, admin_notification:,
               filter_properties:, subscription_id: SKIP, status: SKIP,
               status_reason: SKIP, creation_timestamp: SKIP,
               status_change_timestamp: SKIP, expiration_timestamp: SKIP,
               subscription_type: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @subscription_id = subscription_id unless subscription_id == SKIP
  @listener_url = listener_url
  @secret = secret
  @status = status unless status == SKIP
  @status_reason = status_reason unless status_reason == SKIP
  @admin_notification = admin_notification
  @creation_timestamp = creation_timestamp unless creation_timestamp == SKIP
  @status_change_timestamp = status_change_timestamp unless status_change_timestamp == SKIP
  @expiration_timestamp = expiration_timestamp unless expiration_timestamp == SKIP
  @subscription_type = subscription_type unless subscription_type == SKIP
  @filter_properties = filter_properties
  @additional_properties = additional_properties
end

Instance Attribute Details

#admin_notificationArray[SubscriptionsAdjustmentsEmailNotification]

Customer can supply an email address to receive important updates on the status and events related to the subscription.



47
48
49
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 47

def admin_notification
  @admin_notification
end

#creation_timestampDateTime

When the subscription was originally created.

Returns:

  • (DateTime)


51
52
53
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 51

def creation_timestamp
  @creation_timestamp
end

#expiration_timestampDateTime

When the subscription expires.

Returns:

  • (DateTime)


59
60
61
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 59

def expiration_timestamp
  @expiration_timestamp
end

#filter_propertiesPackageTransactionDetailsSubscription

The filters that should be applied to the subscription. The structure of this property will change dependent on the type of subscription a client is signing up for.



69
70
71
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 69

def filter_properties
  @filter_properties
end

#listener_urlString

Customer URL in which subscription data will be sent. You can parse the data received on the server URL, and you can call back to the Package Transaction Details API for the full latest status of events.

Returns:

  • (String)


22
23
24
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 22

def listener_url
  @listener_url
end

#secretString

Customer supplied secret USPS will use to create a hash value. The hash will be provided in the Notification payload. USPS will use the SHA-256 algorithm to create the hash value.

Returns:

  • (String)


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

def secret
  @secret
end

#statusStatus5

Current status of the subscription. USPS will post notifications to the supplied listenerURL. If the listenerURL cannot be reached or is invalid, USPS will change the status of the subscription to SUSPENDED. The customer has the option of changing the status to DISABLED. It is recommended the customer change the status to DISABLED if they know their endpoint will not be active, i.e operational maintenance.

Returns:



37
38
39
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 37

def status
  @status
end

#status_change_timestampDateTime

Time when the status was last changed

Returns:

  • (DateTime)


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

def status_change_timestamp
  @status_change_timestamp
end

#status_reasonString

When status is suspended the Status Reason will return why it was suspended

Returns:

  • (String)


42
43
44
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 42

def status_reason
  @status_reason
end

#subscription_idString

Unique Identifier created for this Subscription.

Returns:

  • (String)


16
17
18
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 16

def subscription_id
  @subscription_id
end

#subscription_typeSubscriptionType2

The subscription type defines the data domain for this subscription.

Returns:



63
64
65
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 63

def subscription_type
  @subscription_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 129

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  listener_url = hash.key?('listenerURL') ? hash['listenerURL'] : nil
  secret = hash.key?('secret') ? hash['secret'] : nil
  # Parameter is an array, so we need to iterate through it
  admin_notification = nil
  unless hash['adminNotification'].nil?
    admin_notification = []
    hash['adminNotification'].each do |structure|
      admin_notification << (SubscriptionsAdjustmentsEmailNotification.from_hash(structure) if structure)
    end
  end

  admin_notification = nil unless hash.key?('adminNotification')
  if hash['filterProperties']
    filter_properties = PackageTransactionDetailsSubscription.from_hash(hash['filterProperties'])
  end
  subscription_id =
    hash.key?('subscriptionId') ? hash['subscriptionId'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  status_reason = hash.key?('statusReason') ? hash['statusReason'] : SKIP
  creation_timestamp = if hash.key?('creationTimestamp')
                         (DateTimeHelper.from_rfc3339(hash['creationTimestamp']) if hash['creationTimestamp'])
                       else
                         SKIP
                       end
  status_change_timestamp = if hash.key?('statusChangeTimestamp')
                              (DateTimeHelper.from_rfc3339(hash['statusChangeTimestamp']) if hash['statusChangeTimestamp'])
                            else
                              SKIP
                            end
  expiration_timestamp = if hash.key?('expirationTimestamp')
                           (DateTimeHelper.from_rfc3339(hash['expirationTimestamp']) if hash['expirationTimestamp'])
                         else
                           SKIP
                         end
  subscription_type =
    hash.key?('subscriptionType') ? hash['subscriptionType'] : 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.
  SubscriptionsPackageTransactionDetailsSubscription.new(listener_url: listener_url,
                                                         secret: secret,
                                                         admin_notification: admin_notification,
                                                         filter_properties: filter_properties,
                                                         subscription_id: subscription_id,
                                                         status: status,
                                                         status_reason: status_reason,
                                                         creation_timestamp: creation_timestamp,
                                                         status_change_timestamp: status_change_timestamp,
                                                         expiration_timestamp: expiration_timestamp,
                                                         subscription_type: subscription_type,
                                                         additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 72

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['subscription_id'] = 'subscriptionId'
  @_hash['listener_url'] = 'listenerURL'
  @_hash['secret'] = 'secret'
  @_hash['status'] = 'status'
  @_hash['status_reason'] = 'statusReason'
  @_hash['admin_notification'] = 'adminNotification'
  @_hash['creation_timestamp'] = 'creationTimestamp'
  @_hash['status_change_timestamp'] = 'statusChangeTimestamp'
  @_hash['expiration_timestamp'] = 'expirationTimestamp'
  @_hash['subscription_type'] = 'subscriptionType'
  @_hash['filter_properties'] = 'filterProperties'
  @_hash
end

.nullablesObject

An array for nullable fields



102
103
104
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 102

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    subscription_id
    status
    status_reason
    creation_timestamp
    status_change_timestamp
    expiration_timestamp
    subscription_type
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 216

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} subscription_id: #{@subscription_id.inspect}, listener_url:"\
  " #{@listener_url.inspect}, secret: #{@secret.inspect}, status: #{@status.inspect},"\
  " status_reason: #{@status_reason.inspect}, admin_notification:"\
  " #{@admin_notification.inspect}, creation_timestamp: #{@creation_timestamp.inspect},"\
  " status_change_timestamp: #{@status_change_timestamp.inspect}, expiration_timestamp:"\
  " #{@expiration_timestamp.inspect}, subscription_type: #{@subscription_type.inspect},"\
  " filter_properties: #{@filter_properties.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_creation_timestampObject



192
193
194
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 192

def to_custom_creation_timestamp
  DateTimeHelper.to_rfc3339(creation_timestamp)
end

#to_custom_expiration_timestampObject



200
201
202
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 200

def to_custom_expiration_timestamp
  DateTimeHelper.to_rfc3339(expiration_timestamp)
end

#to_custom_status_change_timestampObject



196
197
198
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 196

def to_custom_status_change_timestamp
  DateTimeHelper.to_rfc3339(status_change_timestamp)
end

#to_sObject

Provides a human-readable string representation of the object.



205
206
207
208
209
210
211
212
213
# File 'lib/usps_api/models/subscriptions_package_transaction_details_subscription.rb', line 205

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} subscription_id: #{@subscription_id}, listener_url: #{@listener_url},"\
  " secret: #{@secret}, status: #{@status}, status_reason: #{@status_reason},"\
  " admin_notification: #{@admin_notification}, creation_timestamp: #{@creation_timestamp},"\
  " status_change_timestamp: #{@status_change_timestamp}, expiration_timestamp:"\
  " #{@expiration_timestamp}, subscription_type: #{@subscription_type}, filter_properties:"\
  " #{@filter_properties}, additional_properties: #{@additional_properties}>"
end