Class: WhatsAppCloudApi::RegistrationController

Inherits:
BaseController show all
Defined in:
lib/whats_app_cloud_api/controllers/registration_controller.rb

Overview

RegistrationController

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #get_user_agent, #validate_parameters, #validate_response

Constructor Details

#initialize(config, http_call_back: nil) ⇒ RegistrationController

Returns a new instance of RegistrationController.


9
10
11
# File 'lib/whats_app_cloud_api/controllers/registration_controller.rb', line 9

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#deregister_phone(content_type, phone_number_id) ⇒ SuccessResponse

Used to deregister a phone number. Deregister phone removes a previously registered phone. You can always re-register your phone using by repeating the registration process. Business Solution Providers (BSPs) must authenticate themselves with an access token with the whatsapp_business_management permission.

Parameters:

  • content_type (ContentTypeEnum)

    Required parameter: Example:

  • phone_number_id (String)

    Required parameter: Example:

Returns:


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/whats_app_cloud_api/controllers/registration_controller.rb', line 60

def deregister_phone(content_type,
                     phone_number_id)
  # Prepare query url.

  _query_builder = config.get_base_uri
  _query_builder << '/{Phone-Number-ID}/deregister'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.

  _headers = {
    'accept' => 'application/json',
    'Content-Type' => content_type
  }

  # Prepare and execute HttpRequest.

  _request = config.http_client.post(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)
  validate_response(_response)

  # Return appropriate response type.

  decoded = APIHelper.json_deserialize(_response.raw_body)
  SuccessResponse.from_hash(decoded)
end

#register_phone(phone_number_id, body) ⇒ SuccessResponse

Used to register a phone number or to migrate WhatsApp Business Accounts from a current On-Premises deployment to the new Cloud-Based API. Business Solution Providers (BSPs) must authenticate themselves with an access token with the whatsapp_business_management permission.

Parameters:

  • phone_number_id (String)

    Required parameter: Example:

  • body (RegisterPhoneRequest)

    Required parameter: Example:

Returns:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/whats_app_cloud_api/controllers/registration_controller.rb', line 20

def register_phone(phone_number_id,
                   body)
  # Prepare query url.

  _query_builder = config.get_base_uri
  _query_builder << '/{Phone-Number-ID}/register'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.

  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.

  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)
  validate_response(_response)

  # Return appropriate response type.

  decoded = APIHelper.json_deserialize(_response.raw_body)
  SuccessResponse.from_hash(decoded)
end