Class: ParcelApi::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/parcel_api/notification.rb

Overview

Creates a PCD (collection point) subscription with provided delivery email address and tracking reference. Customers will receive an email when the parcel reaches the collection point and then subsequent reminders.

Constant Summary collapse

PARCELNOTIFICATION_URL =
'/parcelnotifications/v1/subscription/pcd'

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ Notification

Creates a new ParcelApi::Notification instance.



12
13
14
# File 'lib/parcel_api/notification.rb', line 12

def initialize(connection=nil)
  @connection ||= connection || ParcelApi::Client.connection
end

Instance Method Details

#create(notification_options)

Create a new parcel notification

Parameters:

  • notification_options (Hash)

Returns:

  • Object of notification details



20
21
22
23
# File 'lib/parcel_api/notification.rb', line 20

def create(notification_options)
  response = @connection.post PARCELNOTIFICATION_URL, body: notification_options.to_json.to_ascii, headers: { 'Content-Type' => 'application/json' }
  RecursiveOpenStruct.new(response.parsed, recurse_over_arrays: true)
end