Class: AfTalk::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/aftalk/connection.rb

Constant Summary collapse

URL =
"https://api.africastalking.com".freeze
SANDBOX_URL =
"https://api.sandbox.africastalking.com".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.buildObject



9
10
11
# File 'lib/aftalk/connection.rb', line 9

def self.build
  @_connection ||= new.build
end

.clearObject



13
14
15
# File 'lib/aftalk/connection.rb', line 13

def self.clear
  @_connection = nil
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aftalk/connection.rb', line 17

def build
  Faraday.new(
    url: api_url,
    headers: { apiKey: AfTalk::Configuration.api_key,
               accept: "application/json" },
  ) do |connection|
    connection.request :url_encoded
    connection.response :json,
                        content_type: /\bjson$/,
                        parser_options: { symbolize_names: true }
    connection.adapter Faraday.default_adapter
  end
end