Class: Api::Esignatures

Inherits:
BaseService show all
Includes:
Singleton
Defined in:
app/services/api/esignatures.rb

Overview

Service object: esignatures.

Instance Attribute Summary collapse

Attributes inherited from BaseService

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger

Constructor Details

#initializeEsignatures

Returns a new instance of Esignatures.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/api/esignatures.rb', line 9

def initialize
  # SSL verification is gated behind an explicit credentials flag so the
  # default is secure (verify:true) and the unsafe path is opt-in. The
  # legacy contract-vendor endpoint had intermittent cert-chain issues
  # historically; if that surfaces again in production, set
  # esignatures.skip_ssl_verify=true in encrypted credentials. Otherwise
  # we get full TLS verification.
  skip_verify = Heatwave::Configuration.fetch(:esignatures, :skip_ssl_verify) == true
  @client = Faraday.new(
    ssl: { verify: !skip_verify },
    request: { open_timeout: 5, timeout: 30 }
  ) do |f|
    f.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'app/services/api/esignatures.rb', line 7

def client
  @client
end

Class Method Details

.clientObject



25
26
27
# File 'app/services/api/esignatures.rb', line 25

def self.client
  instance.client
end

.contract_status(contract_id) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'app/services/api/esignatures.rb', line 54

def self.contract_status(contract_id)
  res = retrieve_contract(contract_id)
  contract = JSON.parse(res.body).deep_symbolize_keys[:data]
  if contract.present?
    contract[:status]
  else
    'not found'
  end
end

.hostnameObject



29
30
31
# File 'app/services/api/esignatures.rb', line 29

def self.hostname
  Heatwave::Configuration.fetch(:esignatures, :hostname)
end

.new_contract(options) ⇒ Object



41
42
43
44
# File 'app/services/api/esignatures.rb', line 41

def self.new_contract(options)
  client.post("#{hostname}/contracts?token=#{token}", options.to_json,
              'Content-Type' => 'application/json')
end

.retrieve_contract(contract_id) ⇒ Object



46
47
48
# File 'app/services/api/esignatures.rb', line 46

def self.retrieve_contract(contract_id)
  client.get("#{hostname}/contracts/#{contract_id}?token=#{token}")
end

.templatesObject



37
38
39
# File 'app/services/api/esignatures.rb', line 37

def self.templates
  client.get("#{hostname}/templates/?token=#{token}")
end

.tokenObject



33
34
35
# File 'app/services/api/esignatures.rb', line 33

def self.token
  Heatwave::Configuration.fetch(:esignatures, :token)
end

.withdraw_contract(contract_id) ⇒ Object



50
51
52
# File 'app/services/api/esignatures.rb', line 50

def self.withdraw_contract(contract_id)
  client.post("#{hostname}/contracts/#{contract_id}/withdraw/?token=#{token}")
end