Class: Twi::Delivery

Inherits:
Resource show all
Defined in:
lib/twi/delivery.rb

Overview

The representation of a direct message delivery notification.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twi::Resource

Class Method Details

.params_for(id:, status:, code: nil) ⇒ Hash

Returns the shape of the payload send by Twilio to the callback URL.

Returns:

  • (Hash)

    the shape of the payload send by Twilio to the callback URL.



28
29
30
# File 'lib/twi/delivery.rb', line 28

def self.params_for(id:, status:, code: nil)
  { SmsSid: id, MessageStatus: status, ErrorCode: code }
end

.unsubscribed?(code) ⇒ Boolean

Returns whether the delivery failed because the recipient unsubscribed.

Returns:

  • (Boolean)

    whether the delivery failed because the recipient unsubscribed.



25
# File 'lib/twi/delivery.rb', line 25

def self.unsubscribed?(code) = code.eql? '21610'

.url_for(code) ⇒ String

Returns documentation URL for given error code.

Returns:

  • (String)

    documentation URL for given error code.



20
21
22
# File 'lib/twi/delivery.rb', line 20

def self.url_for(code)
  "https://www.twilio.com/docs/api/errors/#{code}"
end

Instance Method Details

#codeString?

Returns error code.

Returns:

  • (String, nil)

    error code



13
# File 'lib/twi/delivery.rb', line 13

def code = @params['ErrorCode']

#idString

Returns unique identifier.

Returns:

  • (String)

    unique identifier



6
# File 'lib/twi/delivery.rb', line 6

def id = @params['SmsSid']

#senderString

Returns phone number that delivered the message, as every other resource here reads one: ten digits, whatever prefix Twilio wrote it with.

Returns:

  • (String)

    phone number that delivered the message, as every other resource here reads one: ten digits, whatever prefix Twilio wrote it with.



17
# File 'lib/twi/delivery.rb', line 17

def sender = remove_prefix_from @params['From']

#statusString

delivery_unknown, delivered, undelivered, failed # TODO: make an enum

Returns:

  • (String)

    delivery status, one of accepted, scheduled, queued, sending, sent,



10
# File 'lib/twi/delivery.rb', line 10

def status = @params['MessageStatus']