Class: Dapi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dapi/client.rb,
lib/dapi/client/error.rb,
lib/dapi/client/version.rb

Defined Under Namespace

Classes: Error, OptimisticLockFailure

Constant Summary collapse

OPTIMISTIC_LOCKING_CHECK_WAIT =
1.0
OPTIMISTIC_LOCKING_RETRIES =
10
VERSION =
"0.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(url:, token:, http: HTTP) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
# File 'lib/dapi/client.rb', line 11

def initialize(url:, token:, http: HTTP)
  @url = url
  @http = http
  @token = token
end

Instance Method Details

#get_zone(zone_name) ⇒ Object



17
18
19
# File 'lib/dapi/client.rb', line 17

def get_zone(zone_name)
  unwrap { http.get(@url + "zone/" + zone_name) }
end

#upsert_record(zone_name, lvalue, type, rvalue, ttl) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dapi/client.rb', line 21

def upsert_record(zone_name, lvalue, type, rvalue, ttl)
  retries = OPTIMISTIC_LOCKING_RETRIES
  begin
    upsert_record!(zone_name, lvalue, type, rvalue, ttl)
  rescue Dapi::Client::OptimisticLockFailure
    if retries > 0
      retries -= 1
      sleep(0.1)
      retry
    else
      raise
    end
  end
end