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 user
action_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.
90 91 92 93 94 95 96 |
# File 'lib/sendly/numbers_resource.rb', line 90 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.
88 89 90 |
# File 'lib/sendly/numbers_resource.rb', line 88 def action @action end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
88 89 90 |
# File 'lib/sendly/numbers_resource.rb', line 88 def number @number end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
88 89 90 |
# File 'lib/sendly/numbers_resource.rb', line 88 def raw @raw end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
88 89 90 |
# File 'lib/sendly/numbers_resource.rb', line 88 def requirements @requirements end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
88 89 90 |
# File 'lib/sendly/numbers_resource.rb', line 88 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.
129 130 131 |
# File 'lib/sendly/numbers_resource.rb', line 129 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.
138 139 140 |
# File 'lib/sendly/numbers_resource.rb', line 138 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.
120 121 122 |
# File 'lib/sendly/numbers_resource.rb', line 120 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.
111 112 113 |
# File 'lib/sendly/numbers_resource.rb', line 111 def action_url action && (action["url"] || action[:url]) end |
#documents_required? ⇒ Boolean
102 103 104 |
# File 'lib/sendly/numbers_resource.rb', line 102 def documents_required? status == "documents_required" end |
#payment_required? ⇒ Boolean
106 107 108 |
# File 'lib/sendly/numbers_resource.rb', line 106 def payment_required? status == "payment_required" end |
#provisioning? ⇒ Boolean
98 99 100 |
# File 'lib/sendly/numbers_resource.rb', line 98 def provisioning? status == "provisioning" end |
#to_h ⇒ Object
142 143 144 145 146 147 |
# File 'lib/sendly/numbers_resource.rb', line 142 def to_h { status: status, number: number&.to_h, requirements: requirements, action: action }.compact end |