Class: Sendly::NumberPurchase
- Inherits:
-
Object
- Object
- Sendly::NumberPurchase
- Defined in:
- lib/sendly/numbers_resource.rb
Overview
The result of a buy request. The API responds 202 with one of three statuses:
"provisioning": the purchase succeeded and the number is being provisioned.numbercarries the new PhoneNumber.-
"documents_required"/"payment_required": the purchase is paused pending a hosted Sendly step.actioncarries the hand-off object, which holds TWO distinct identifiers:actionCode— a 32-hex action identifier (read via #action_identifier). Use THIS to poll the action and to re-callbuy(pass it as theaction_code:argument).code— a short user code (read via #action_code). DISPLAY ONLY: show it to the human to type on the hosted page to prove terminal access. Never pass it back asaction_code:. Hand the useraction_url+ #action_code, wait for completion, then re-callbuywith the same body plusaction_code:set to #action_identifier.requirementsdescribes what's missing (a JSON array).
The raw parsed response is preserved verbatim on #raw so callers can
read any field the server adds.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#action_code ⇒ String?
The short user code shown to the human to type on the hosted page to prove terminal access.
-
#action_expires_at ⇒ Integer, ...
Expiry of the action, as an epoch-milliseconds number (the server sends a number, not an ISO-8601 string).
-
#action_identifier ⇒ String?
The 32-hex action identifier.
-
#action_url ⇒ String?
The hosted Sendly page URL the user must visit.
- #documents_required? ⇒ Boolean
-
#initialize(data) ⇒ NumberPurchase
constructor
A new instance of NumberPurchase.
- #payment_required? ⇒ Boolean
- #provisioning? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(data) ⇒ NumberPurchase
Returns a new instance of NumberPurchase.
108 109 110 111 112 113 114 |
# File 'lib/sendly/numbers_resource.rb', line 108 def initialize(data) @raw = data @status = data["status"] @number = data["number"] ? PhoneNumber.new(data["number"]) : nil @requirements = data["requirements"] @action = data["action"] end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def action @action end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def number @number end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def raw @raw end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def requirements @requirements end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def status @status end |
Instance Method Details
#action_code ⇒ String?
The short user code shown to the human to type on the hosted page to prove terminal access. DISPLAY ONLY — to re-buy/poll, use #action_identifier, not this.
147 148 149 |
# File 'lib/sendly/numbers_resource.rb', line 147 def action_code action && (action["code"] || action[:code]) end |
#action_expires_at ⇒ Integer, ...
Expiry of the action, as an epoch-milliseconds number (the server sends
a number, not an ISO-8601 string). Older payloads may carry it under
expires_at; both are accepted.
156 157 158 |
# File 'lib/sendly/numbers_resource.rb', line 156 def action_expires_at action && (action["expiresAt"] || action["expires_at"] || action[:expiresAt] || action[:expires_at]) end |
#action_identifier ⇒ String?
The 32-hex action identifier. Use THIS to poll the action's status and
to re-call buy (pass it as the action_code: argument). NOT for
display.
138 139 140 |
# File 'lib/sendly/numbers_resource.rb', line 138 def action_identifier action && (action["actionCode"] || action["action_code"] || action[:actionCode] || action[:action_code]) end |
#action_url ⇒ String?
Returns The hosted Sendly page URL the user must visit.
129 130 131 |
# File 'lib/sendly/numbers_resource.rb', line 129 def action_url action && (action["url"] || action[:url]) end |
#documents_required? ⇒ Boolean
120 121 122 |
# File 'lib/sendly/numbers_resource.rb', line 120 def documents_required? status == "documents_required" end |
#payment_required? ⇒ Boolean
124 125 126 |
# File 'lib/sendly/numbers_resource.rb', line 124 def payment_required? status == "payment_required" end |
#provisioning? ⇒ Boolean
116 117 118 |
# File 'lib/sendly/numbers_resource.rb', line 116 def provisioning? status == "provisioning" end |
#to_h ⇒ Object
160 161 162 163 164 165 |
# File 'lib/sendly/numbers_resource.rb', line 160 def to_h { status: status, number: number&.to_h, requirements: requirements, action: action }.compact end |