Class: WhatsAppCloudApi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/whats_app_cloud_api/configuration.rb

Overview

All configuration including auth info and base URI for the API access are configured in this class.

Constant Summary collapse

ENVIRONMENTS =

All the environments the SDK can run in.

{
  Environment::PRODUCTION => {
    Server::DEFAULT => 'https://graph.facebook.com/{Version}'
  }
}.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: Faraday.default_adapter, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, environment: Environment::PRODUCTION, version: 'v13.0', access_token: '') ⇒ Configuration

Returns a new instance of Configuration.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/whats_app_cloud_api/configuration.rb', line 33

def initialize(connection: nil, adapter: Faraday.default_adapter,
               timeout: 60, max_retries: 0, retry_interval: 1,
               backoff_factor: 2,
               retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
               retry_methods: %i[get put],
               environment: Environment::PRODUCTION, version: 'v13.0',
               access_token: '')
  # The Faraday connection object passed by the SDK user for making requests
  @connection = connection

  # The Faraday adapter object passed by the SDK user for performing http requests
  @adapter = adapter

  # The value to use for connection timeout
  @timeout = timeout

  # The number of times to retry an endpoint call if it fails
  @max_retries = max_retries

  # Pause in seconds between retries
  @retry_interval = retry_interval

  # The amount to multiply each successive retry's interval amount
  # by in order to provide backoff
  @backoff_factor = backoff_factor

  # A list of HTTP statuses to retry
  @retry_statuses = retry_statuses

  # A list of HTTP methods to retry
  @retry_methods = retry_methods

  # Current API environment
  @environment = String(environment)

  # version value
  @version = version

  # The OAuth 2.0 Access Token to use for API requests.
  @access_token = access_token

  # The Http Client to use for making requests.
  @http_client = create_http_client
end

Class Attribute Details

.environmentsObject (readonly)

Returns the value of attribute environments.



30
31
32
# File 'lib/whats_app_cloud_api/configuration.rb', line 30

def environments
  @environments
end

Instance Attribute Details

#access_tokenObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def access_token
  @access_token
end

#adapterObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def adapter
  @adapter
end

#backoff_factorObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def backoff_factor
  @backoff_factor
end

#connectionObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def connection
  @connection
end

#environmentObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def environment
  @environment
end

#http_clientObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def http_client
  @http_client
end

#max_retriesObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def max_retries
  @max_retries
end

#retry_intervalObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def retry_interval
  @retry_interval
end

#retry_methodsObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def retry_methods
  @retry_methods
end

#retry_statusesObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def retry_statuses
  @retry_statuses
end

#timeoutObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def timeout
  @timeout
end

#versionObject (readonly)

The attribute readers for properties.



25
26
27
# File 'lib/whats_app_cloud_api/configuration.rb', line 25

def version
  @version
end

Instance Method Details

#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, environment: nil, version: nil, access_token: nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/whats_app_cloud_api/configuration.rb', line 78

def clone_with(connection: nil, adapter: nil, timeout: nil,
               max_retries: nil, retry_interval: nil, backoff_factor: nil,
               retry_statuses: nil, retry_methods: nil, environment: nil,
               version: nil, access_token: nil)
  connection ||= self.connection
  adapter ||= self.adapter
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  retry_statuses ||= self.retry_statuses
  retry_methods ||= self.retry_methods
  environment ||= self.environment
  version ||= self.version
  access_token ||= self.access_token

  Configuration.new(connection: connection, adapter: adapter,
                    timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    retry_statuses: retry_statuses,
                    retry_methods: retry_methods, environment: environment,
                    version: version, access_token: access_token)
end

#create_http_clientObject



103
104
105
106
107
108
109
110
# File 'lib/whats_app_cloud_api/configuration.rb', line 103

def create_http_client
  FaradayClient.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    retry_statuses: retry_statuses,
                    retry_methods: retry_methods, connection: connection,
                    adapter: adapter)
end

#get_base_uri(server = Server::DEFAULT) ⇒ String

Generates the appropriate base URI for the environment and the server. required.

Parameters:

  • The (Configuration::Server)

    server enum for which the base URI is

Returns:

  • (String)

    The base URI.



123
124
125
126
127
128
129
130
# File 'lib/whats_app_cloud_api/configuration.rb', line 123

def get_base_uri(server = Server::DEFAULT)
  parameters = {
    'Version' => { 'value' => version, 'encode' => false }
  }
  APIHelper.append_url_with_template_parameters(
    ENVIRONMENTS[environment][server], parameters
  )
end