Class: Cloudflair::Connection

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

Class Method Summary collapse

Class Method Details

.headersObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudflair/connection.rb', line 15

def self.headers # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  cloudflare_auth_config = Cloudflair.config.cloudflare.auth

  if !cloudflare_auth_config.key.nil? && !cloudflare_auth_config.email.nil?
    return({
      'X-Auth-Key'   => cloudflare_auth_config.key,
      'X-Auth-Email' => cloudflare_auth_config.email
    })
  end

  unless cloudflare_auth_config.user_service_key.nil?
    return({
      'Authorization' => "Bearer #{cloudflare_auth_config.user_service_key}"
    })
  end

  raise(
    CloudflairError,
    'Neither email & key nor user_service_key have been defined.'
  )
end

.newObject



10
11
12
13
# File 'lib/cloudflair/connection.rb', line 10

def self.new
  config = Cloudflair.config
  new_faraday_from config
end