Class: Idcf::Dns::Client

Inherits:
Object
  • Object
show all
Includes:
Idcf::Dns::ClientExtensions::Record, Idcf::Dns::ClientExtensions::Zone
Defined in:
lib/idcf/dns/client.rb

Overview

Client for IDCF DNS service

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Idcf::Dns::ClientExtensions::Zone

#create_zone, #delete_zone, #get_token, #get_zone, #list_zones, #update_zone, #verify_zone, #zone, #zones

Methods included from Idcf::Dns::ClientExtensions::Record

#create_record, #delete_record, #get_record, #list_records, #record, #records, #update_record

Constructor Details

#initialize(api_key:, secret_key:, host: "dns.idcfcloud.com", endpoint: "/api/v1", verify_ssl: true) ⇒ Client

The constructor of Dns::Client uses keyword arguments.

Parameters:

  • api_key (String)

    API key for IDCF Cloud

  • secret_key (String)

    Secret key for IDCF Cloud



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/idcf/dns/client.rb', line 17

def initialize(
  api_key:,
  secret_key:,
  host: "dns.idcfcloud.com",
  endpoint: "/api/v1",
  verify_ssl: true
)

  @api_key    = api_key
  @secret_key = secret_key
  @host       = host
  @endpoint   = endpoint
  @verify_ssl = verify_ssl
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/idcf/dns/client.rb', line 11

def api_key
  @api_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



11
12
13
# File 'lib/idcf/dns/client.rb', line 11

def endpoint
  @endpoint
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/idcf/dns/client.rb', line 11

def host
  @host
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



11
12
13
# File 'lib/idcf/dns/client.rb', line 11

def secret_key
  @secret_key
end

Instance Method Details

#connectionObject



33
34
35
36
37
38
39
40
# File 'lib/idcf/dns/client.rb', line 33

def connection
  @connection ||=
    Faraday.new(url: url_prefix, ssl: ssl_options) do |connection|
      connection.request :json
      connection.response :json
      connection.adapter Faraday.default_adapter
    end
end

#delete(resource, parameters = {}, headers = {}) ⇒ Response

Send DELETE request.

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



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

def delete(resource, parameters = {}, headers = {})
  send(:delete, resource, parameters, headers)
end

#delete!(resource, parameters = {}, headers = {}) ⇒ Response

Send DELETE request with handling error

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



58
59
60
# File 'lib/idcf/dns/client.rb', line 58

def delete!(resource, parameters = {}, headers = {})
  send!(:delete, resource, parameters, headers)
end

#get(resource, parameters = {}, headers = {}) ⇒ Response

Send GET request

Parameters:

  • resource (String)

    Resource name

  • parameters (Hash) (defaults to: {})

    Parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



68
69
70
# File 'lib/idcf/dns/client.rb', line 68

def get(resource, parameters = {}, headers = {})
  send(:get, resource, parameters, headers)
end

#get!(resource, parameters = {}, headers = {}) ⇒ Response

Send GET request with handling error

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



78
79
80
# File 'lib/idcf/dns/client.rb', line 78

def get!(resource, parameters = {}, headers = {})
  send!(:get, resource, parameters, headers)
end

#post(resource, parameters = {}, headers = {}) ⇒ Response

Send POST request

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



88
89
90
# File 'lib/idcf/dns/client.rb', line 88

def post(resource, parameters = {}, headers = {})
  send(:post, resource, parameters, headers)
end

#post!(resource, parameters = {}, headers = {}) ⇒ Response

Send POST request with handling error

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



98
99
100
# File 'lib/idcf/dns/client.rb', line 98

def post!(resource, parameters = {}, headers = {})
  send!(:post, resource, parameters, headers)
end

#put(resource, parameters = {}, headers = {}) ⇒ Response

Send PUT request

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



108
109
110
# File 'lib/idcf/dns/client.rb', line 108

def put(resource, parameters = {}, headers = {})
  send(:put, resource, parameters, headers)
end

#put!(resource, parameters = {}, headers = {}) ⇒ Response

Send PUT request with handling error

Parameters:

  • resource (String)

    resource name

  • parameters (Hash) (defaults to: {})

    request parameters

  • headers (Hash) (defaults to: {})

    HTTP request headers

Returns:



118
119
120
# File 'lib/idcf/dns/client.rb', line 118

def put!(resource, parameters = {}, headers = {})
  send!(:put, resource, parameters, headers)
end