Class: Whatsapp::BusinessPhoneNumber::VerifyCode

Inherits:
Object
  • Object
show all
Extended by:
Transport, ResponseHandling
Includes:
ActiveModel::Validations
Defined in:
lib/ruby/whatsapp/business_phone_number/verify_code.rb

Overview

Confirms the verification code sent by RequestCode, the second 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/verify-code-api

Defined Under Namespace

Modules: Defaults

Constant Summary

Constants included from ResponseHandling

ResponseHandling::MAX_ERROR_BODY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:) ⇒ VerifyCode

Returns a new instance of VerifyCode.

Parameters:

  • code (String, Integer)

    The verification code received via SMS or voice call. Meta documents this as a plain string with no format rule, unlike Register's pin, so only presence is checked.

Raises:

  • (ActiveModel::ValidationError)

    if validation fails.



28
29
30
31
32
# File 'lib/ruby/whatsapp/business_phone_number/verify_code.rb', line 28

def initialize(code:)
  @code = code

  validate!
end

Instance Attribute Details

#codeString

Returns The verification code received via SMS or voice call.

Returns:

  • (String)

    The verification code received via SMS or voice call.



20
21
22
# File 'lib/ruby/whatsapp/business_phone_number/verify_code.rb', line 20

def code
  @code
end

Class Method Details

.call(code:, client: Client.new) ⇒ Response

Parameters:

Returns:

Raises:

  • (ActiveModel::ValidationError)

    if the code is blank.

  • (Error)

    if no phone number ID is configured, or the request fails.



52
53
54
55
56
57
58
59
# File 'lib/ruby/whatsapp/business_phone_number/verify_code.rb', line 52

def call(code:, client: Client.new)
  body = new(code:).serialize
  response = client.connection.post(edge_path(client, Defaults::EDGE), json: body)

  Response.deserialize(
    parse_json(handle_response!(response, error_class: Error, action: "verify code"))
  )
end

Instance Method Details

#inspectString

Redacts the code so it never leaks into logs or console output, same as Register#inspect redacts the pin.

Returns:

  • (String)


42
43
44
# File 'lib/ruby/whatsapp/business_phone_number/verify_code.rb', line 42

def inspect
  "#<#{self.class.name} code=[REDACTED]>"
end

#serializeHash

Returns The verify-code payload.

Returns:

  • (Hash)

    The verify-code payload.



35
36
37
# File 'lib/ruby/whatsapp/business_phone_number/verify_code.rb', line 35

def serialize
  { code: code.to_s }
end