Class: ComplyanceSDK::ERP::Client
- Inherits:
-
Object
- Object
- ComplyanceSDK::ERP::Client
- Defined in:
- lib/complyance_sdk/erp/client.rb
Constant Summary collapse
- BASE_PATH =
'/documents/erp-exports'.freeze
- DEFAULT_URL =
'https://api.complyance.io'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #acknowledge_job(job_id, status: 'success', error: nil) ⇒ Object
- #get_config ⇒ Object
- #get_job(job_id) ⇒ Object
- #get_job_payload(job_id) ⇒ Object
-
#initialize(api_key:, environment: 'production', base_url: nil, timeout: 30_000) ⇒ Client
constructor
A new instance of Client.
- #list_jobs(limit: nil) ⇒ Object
- #test_connection(config_id) ⇒ Object
- #trigger_manual(document_id) ⇒ Object
Constructor Details
#initialize(api_key:, environment: 'production', base_url: nil, timeout: 30_000) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/complyance_sdk/erp/client.rb', line 13 def initialize(api_key:, environment: 'production', base_url: nil, timeout: 30_000) @api_key = api_key @environment = environment || 'production' @base_url = (base_url || DEFAULT_URL).gsub(%r{/+$}, '') @timeout = timeout > 0 ? timeout : 30_000 end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/complyance_sdk/erp/client.rb', line 11 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
11 12 13 |
# File 'lib/complyance_sdk/erp/client.rb', line 11 def base_url @base_url end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'lib/complyance_sdk/erp/client.rb', line 11 def environment @environment end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/complyance_sdk/erp/client.rb', line 11 def timeout @timeout end |
Class Method Details
.from_env ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/complyance_sdk/erp/client.rb', line 20 def self.from_env api_key = ENV['COMPLYANCE_API_KEY'] raise ArgumentError, 'COMPLYANCE_API_KEY environment variable is required' unless api_key new( api_key: api_key, environment: ENV.fetch('COMPLYANCE_ENVIRONMENT', 'production'), base_url: ENV['COMPLYANCE_BASE_URL'] ) end |
Instance Method Details
#acknowledge_job(job_id, status: 'success', error: nil) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/complyance_sdk/erp/client.rb', line 48 def acknowledge_job(job_id, status: 'success', error: nil) body = { status: status, environment: environment } body[:error] = error if error request('POST', "/jobs/#{job_id}/ack", body) end |
#get_config ⇒ Object
64 65 66 |
# File 'lib/complyance_sdk/erp/client.rb', line 64 def get_config request('GET', "/config?environment=#{environment}") end |
#get_job(job_id) ⇒ Object
38 39 40 41 |
# File 'lib/complyance_sdk/erp/client.rb', line 38 def get_job(job_id) response = request('GET', "/jobs/#{job_id}?environment=#{environment}") response.fetch('job', {}) end |
#get_job_payload(job_id) ⇒ Object
43 44 45 46 |
# File 'lib/complyance_sdk/erp/client.rb', line 43 def get_job_payload(job_id) response = request('GET', "/jobs/#{job_id}/payload?environment=#{environment}") response.fetch('payload', {}) end |
#list_jobs(limit: nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/complyance_sdk/erp/client.rb', line 31 def list_jobs(limit: nil) path = "/jobs?environment=#{environment}" path += "&limit=#{limit}" if limit response = request('GET', path) response.fetch('jobs', []) end |
#test_connection(config_id) ⇒ Object
68 69 70 71 72 |
# File 'lib/complyance_sdk/erp/client.rb', line 68 def test_connection(config_id) request('POST', "/config/#{config_id}/test", { environment: environment }) end |
#trigger_manual(document_id) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/complyance_sdk/erp/client.rb', line 57 def trigger_manual(document_id) request('POST', '/jobs/trigger-manual', { documentId: document_id, environment: environment }) end |