Class: CloudCheckr::API::Client

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

Constant Summary collapse

DEFAULT_URL =
"https://api2.cloudcheckr.com".freeze
DEFAULT_FORMAT =
:json

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &connection_builder) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
# File 'lib/cloud_checkr/api/client.rb', line 15

def initialize(options = {}, &connection_builder)
  @access_key         = options.fetch(:access_key,  API.access_key)
  @use_account        = options.fetch(:use_account, API.)
  @url                = options.fetch(:url,         DEFAULT_URL)
  @format             = options.fetch(:format,      :json)
  @connection_builder = connection_builder
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



13
14
15
# File 'lib/cloud_checkr/api/client.rb', line 13

def access_key
  @access_key
end

#formatObject (readonly)

Returns the value of attribute format.



13
14
15
# File 'lib/cloud_checkr/api/client.rb', line 13

def format
  @format
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/cloud_checkr/api/client.rb', line 13

def url
  @url
end

Instance Method Details

#apiObject



33
34
35
# File 'lib/cloud_checkr/api/client.rb', line 33

def api
  @api ||= build_connection
end

#default_paramsObject



37
38
39
40
41
42
# File 'lib/cloud_checkr/api/client.rb', line 37

def default_params
  {}.tap do |params|
    params[:access_key]  = @access_key  unless @access_key.nil?
    params[:use_account] = @use_account unless @use_account.nil?
  end
end

#get(controller_name, api_call, params = nil, headers = nil, &request_builder) ⇒ Object

API



25
26
27
# File 'lib/cloud_checkr/api/client.rb', line 25

def get(controller_name, api_call, params = nil, headers = nil, &request_builder)
  handle_response api.get(prepare_path(controller_name, api_call), prepare_params(params), headers, &request_builder)
end

#post(controller_name, api_call, params = nil, headers = nil, &request_builder) ⇒ Object



29
30
31
# File 'lib/cloud_checkr/api/client.rb', line 29

def post(controller_name, api_call, params = nil, headers = nil, &request_builder)
  handle_response api.post(prepare_path(controller_name, api_call), prepare_params(params), headers, &request_builder)
end