Module: EasyCompliance::Client
- Defined in:
- lib/easy_compliance/client.rb
Overview
client for easycompliance.de/schnittstellen/api/
Defined Under Namespace
Classes: Error
Constant Summary collapse
- HEADERS =
{ 'Content-Type': 'application/x-www-form-urlencoded' }
Class Method Summary collapse
- .api_url ⇒ Object
-
.check_now(record:, value:) ⇒ EasyCompliance::Result
check if record is currently on a sanctions list.
-
.fetch_list ⇒ EasyCompliance::Result
get matches of last 24 hours.
- .post(**body) ⇒ EasyCompliance::Result
- .retry_interval ⇒ Object
- .retry_limit ⇒ Object
-
.submit(record:, value:) ⇒ EasyCompliance::Result
like ‘#check_now`, but also adds to list for future automatic checks.
Class Method Details
.api_url ⇒ Object
61 62 63 |
# File 'lib/easy_compliance/client.rb', line 61 def api_url EasyCompliance.api_url || raise(Error, 'must set api_url') end |
.check_now(record:, value:) ⇒ EasyCompliance::Result
check if record is currently on a sanctions list
13 14 15 16 |
# File 'lib/easy_compliance/client.rb', line 13 def check_now(record:, value:) ref = EasyCompliance::Ref.for_record(record) post(method: 1, ref: ref, name: value) end |
.fetch_list ⇒ EasyCompliance::Result
get matches of last 24 hours
27 28 29 |
# File 'lib/easy_compliance/client.rb', line 27 def fetch_list post(method: 3) end |
.post(**body) ⇒ EasyCompliance::Result
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/easy_compliance/client.rb', line 36 def post(**body) body[:api_key] = EasyCompliance.api_key or raise Error, 'must set api_key' res = Excon.post( api_url, body: URI.encode_www_form(body), headers: HEADERS, idempotent: true, retry_limit: retry_limit, retry_interval: retry_interval ) res.status < 300 or raise Error, "#{res.status}: #{res.body}" EasyCompliance::Result.new(status: res.status, body: res.body) rescue Excon::Error, OpenSSL::OpenSSLError => e raise Error, "Network error: #{e.class.name} - #{e.}" end |
.retry_interval ⇒ Object
57 58 59 |
# File 'lib/easy_compliance/client.rb', line 57 def retry_interval EasyCompliance.retry_interval || 5 end |
.retry_limit ⇒ Object
53 54 55 |
# File 'lib/easy_compliance/client.rb', line 53 def retry_limit EasyCompliance.retry_limit || 3 end |
.submit(record:, value:) ⇒ EasyCompliance::Result
like ‘#check_now`, but also adds to list for future automatic checks
20 21 22 23 |
# File 'lib/easy_compliance/client.rb', line 20 def submit(record:, value:) ref = EasyCompliance::Ref.for_record(record) post(method: 2, ref: ref, name: value) end |