Class: Clicksign::Client

Inherits:
Object
  • Object
show all
Includes:
RequestInstrumentation
Defined in:
lib/clicksign/client.rb

Constant Summary collapse

HEADERS =
{
  'Content-Type' => 'application/vnd.api+json',
  'Accept' => 'application/vnd.api+json',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url:, open_timeout: 2, read_timeout: 10, write_timeout: 10, max_retries: 0) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
# File 'lib/clicksign/client.rb', line 16

def initialize(api_key:, base_url:, open_timeout: 2, read_timeout: 10,
               write_timeout: 10, max_retries: 0)
  @api_key       = api_key
  @base_url      = base_url
  @open_timeout  = open_timeout
  @read_timeout  = read_timeout
  @write_timeout = write_timeout
  @max_retries   = max_retries
end

Instance Method Details

#delete(path, body: nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/clicksign/client.rb', line 45

def delete(path, body: nil)
  uri = build_uri(path)
  request = Net::HTTP::Delete.new(uri, headers)
  request.body = body.to_json if body
  execute_with_retry(request, uri)
end

#get(path, params: {}) ⇒ Object



26
27
28
29
# File 'lib/clicksign/client.rb', line 26

def get(path, params: {})
  uri = build_uri(path, params)
  execute_with_retry(Net::HTTP::Get.new(uri, headers), uri)
end

#patch(path, body:) ⇒ Object



38
39
40
41
42
43
# File 'lib/clicksign/client.rb', line 38

def patch(path, body:)
  uri = build_uri(path)
  request = Net::HTTP::Patch.new(uri, headers)
  request.body = body.to_json
  execute_with_retry(request, uri)
end

#post(path, body:) ⇒ Object



31
32
33
34
35
36
# File 'lib/clicksign/client.rb', line 31

def post(path, body:)
  uri = build_uri(path)
  request = Net::HTTP::Post.new(uri, headers)
  request.body = body.to_json
  execute_with_retry(request, uri)
end