Class: Whatsapp::BusinessPhoneNumber::RequestCode
- Inherits:
-
Object
- Object
- Whatsapp::BusinessPhoneNumber::RequestCode
- Extended by:
- Transport, ResponseHandling
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/ruby/whatsapp/business_phone_number/request_code.rb
Overview
Requests a verification code (by SMS or voice call) for a business phone number —
the first step of the onboarding flow this module wraps end to end:
RequestCode -> VerifyCode -> Register.
Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-phone-number/phone-number-verification-request-code-api
Defined Under Namespace
Modules: CodeMethods, Defaults
Constant Summary
Constants included from ResponseHandling
ResponseHandling::MAX_ERROR_BODY
Instance Attribute Summary collapse
-
#code_method ⇒ String
One of CodeMethods::ALL.
-
#language ⇒ String
The locale for the verification message (e.g.
"en_US").
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code_method:, language:) ⇒ RequestCode
constructor
A new instance of RequestCode.
-
#serialize ⇒ Hash
The request-code payload.
Constructor Details
#initialize(code_method:, language:) ⇒ RequestCode
Returns a new instance of RequestCode.
54 55 56 57 58 59 |
# File 'lib/ruby/whatsapp/business_phone_number/request_code.rb', line 54 def initialize(code_method:, language:) @code_method = CodeMethods.normalize(code_method) @language = language validate! end |
Instance Attribute Details
#code_method ⇒ String
Returns One of Whatsapp::BusinessPhoneNumber::RequestCode::CodeMethods::ALL.
40 41 42 |
# File 'lib/ruby/whatsapp/business_phone_number/request_code.rb', line 40 def code_method @code_method end |
#language ⇒ String
Returns The locale for the verification message (e.g. "en_US").
44 45 46 |
# File 'lib/ruby/whatsapp/business_phone_number/request_code.rb', line 44 def language @language end |
Class Method Details
.call(code_method:, language:, client: Client.new) ⇒ Response
74 75 76 77 78 79 80 81 |
# File 'lib/ruby/whatsapp/business_phone_number/request_code.rb', line 74 def call(code_method:, language:, client: Client.new) body = new(code_method:, language:).serialize response = client.connection.post(edge_path(client, Defaults::EDGE), json: body) Response.deserialize( parse_json(handle_response!(response, error_class: Error, action: "request verification code")) ) end |
Instance Method Details
#serialize ⇒ Hash
Returns The request-code payload. Both fields are documented required, so neither is ever compacted away.
63 64 65 |
# File 'lib/ruby/whatsapp/business_phone_number/request_code.rb', line 63 def serialize { code_method:, language: } end |