Add Universign timestamp API query
This commit is contained in:
parent
e16cb731c5
commit
dace9a53d3
6 changed files with 102 additions and 0 deletions
40
app/lib/universign/api.rb
Normal file
40
app/lib/universign/api.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
class Universign::API
|
||||
## Universign Timestamp POST API
|
||||
# Official documentation is at https://help.universign.com/hc/fr/articles/360000898965-Guide-d-intégration-horodatage
|
||||
|
||||
def self.ensure_properly_configured!
|
||||
if userpwd.blank?
|
||||
raise StandardError, 'Universign API is not properly configured'
|
||||
end
|
||||
end
|
||||
|
||||
def self.timestamp(data)
|
||||
ensure_properly_configured!
|
||||
|
||||
response = Typhoeus.post(
|
||||
UNIVERSIGN_API_URL,
|
||||
userpwd: userpwd,
|
||||
body: body(data)
|
||||
)
|
||||
|
||||
if response.success?
|
||||
response.body
|
||||
else
|
||||
raise StandardError, "Universign timestamp query failed: #{response.status_message}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.body(data)
|
||||
{
|
||||
'hashAlgo': 'SHA256',
|
||||
'withCert': 'true',
|
||||
'hashValue': data
|
||||
}
|
||||
end
|
||||
|
||||
def self.userpwd
|
||||
Rails.application.secrets.universign[:userpwd]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue