Class: Cloudflarer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudflarer/client.rb

Constant Summary collapse

API_VERSION =
'v4'.freeze
HOST =
'api.cloudflare.com'.freeze
PATH =
"/client/#{API_VERSION}".freeze
URL =
"https://#{HOST}#{PATH}".freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, email: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cloudflarer/client.rb', line 12

def initialize(api_key: nil, email: nil)
  api_key ||= ENV['CLOUDFLARE_API_KEY']
  raise ArgumentError, "API Key is required." unless api_key
  email ||= ENV['CLOUDFLARE_EMAIL']
  raise ArgumentError, "Email is required" unless email
  headers = { 
    'X-Auth-Key' => api_key,
    'X-Auth-Email' => email,
    'Content-Type': 'application/json'
  }
  @connection = Faraday.new(URL, headers: headers)
end