Class: Glare::Client

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

Constant Summary collapse

BASE_HOST =
'https://api.cloudflare.com'
BASE_PATH =
'/client/v4'.freeze

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
# File 'lib/glare/client.rb', line 11

def initialize
  @http = Faraday::Connection.new(BASE_HOST) do |builder|
    builder.request  :json
    builder.response :logger, Logger.new(STDERR) if ENV['CF_DEBUG']
    builder.response :json, :content_type => /\bjson$/

    builder.adapter  :net_http
  end
end

Instance Method Details

#delete(query, params = nil) ⇒ Object



48
49
50
# File 'lib/glare/client.rb', line 48

def delete(query, params=nil)
  ApiResponse.new(@http.delete(BASE_HOST + BASE_PATH + query, params, @headers)).valid!
end

#from_global_api_key(email, auth_key) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/glare/client.rb', line 21

def from_global_api_key(email, auth_key)
  @headers = {
    'X-Auth-Email' => email,
    'X-Auth-Key' => auth_key
  }
  self
end

#from_scoped_api_token(api_token) ⇒ Object



29
30
31
32
33
34
# File 'lib/glare/client.rb', line 29

def from_scoped_api_token(api_token)
  @headers = {
    'Authorization' => "Bearer #{api_token}"
  }
  self
end

#get(query, params) ⇒ Object



36
37
38
# File 'lib/glare/client.rb', line 36

def get(query, params)
  ApiResponse.new(@http.get(BASE_HOST + BASE_PATH + query, params, @headers)).valid!
end

#post(query, data) ⇒ Object



40
41
42
# File 'lib/glare/client.rb', line 40

def post(query, data)
  ApiResponse.new(@http.post(BASE_HOST + BASE_PATH + query, data, @headers)).valid!
end

#put(query, data) ⇒ Object



44
45
46
# File 'lib/glare/client.rb', line 44

def put(query, data)
  ApiResponse.new(@http.put(BASE_HOST + BASE_PATH + query, data, @headers)).valid!
end