class SignHost::ApiClient
Attributes
configuration[R]
Public Class Methods
new(configuration)
click to toggle source
# File lib/sign_host/api_client.rb, line 7 def initialize(configuration) @configuration = configuration end
Public Instance Methods
get_receipt(transaction_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 57 def get_receipt(transaction_id) RestClient.get(receipt_url(transaction_id), auth_headers){ |response, request, result, &block | case response.code when 200 file = Tempfile.new(['receipt', '.pdf']) file.write response.body file.path else response.return!(request, result, &block) end } end
get_signed_document(file_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 44 def get_signed_document(file_id) RestClient.get(signed_document_url(file_id), auth_headers){ |response, request, result, &block | case response.code when 200 file = Tempfile.new(['signed-document', '.pdf']) file.write response.body file.path else response.return!(request, result, &block) end } end
get_transaction(transaction_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 33 def get_transaction(transaction_id) RestClient.get(transaction_url(transaction_id), auth_headers.merge(content_type: 'application/json', accept: 'application/json')){ |response, request, result, &block | case response.code when 200 JSON.parse(response.body) else response.return!(request, result, &block) end } end
post_transaction(payload)
click to toggle source
# File lib/sign_host/api_client.rb, line 11 def post_transaction(payload) RestClient.post(new_transaction_url, payload.to_json, auth_headers.merge(content_type: 'application/json', accept: 'application/json')){ |response, request, result, &block| case response.code when 200 JSON.parse(response.body) else response.return!(request, result, &block) end } end
put_file(file_id, file)
click to toggle source
# File lib/sign_host/api_client.rb, line 22 def put_file(file_id, file) RestClient.put(upload_file_url(file_id), file, auth_headers.merge(multipart: true, content_type: 'application/pdf')) { |response, request, result, &block | case response.code when 200 true else response.return!(request, result, &block) end } end
Private Instance Methods
api_url()
click to toggle source
# File lib/sign_host/api_client.rb, line 92 def api_url "https://api.signhost.com/api/" end
auth_headers()
click to toggle source
# File lib/sign_host/api_client.rb, line 96 def auth_headers { authorization: "APIKey #{configuration.api_key}", application: "APPKey #{configuration.application_key}" } end
new_transaction_url()
click to toggle source
# File lib/sign_host/api_client.rb, line 72 def new_transaction_url api_url + "transaction" end
receipt_url(transaction_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 88 def receipt_url(transaction_id) api_url + "file/receipt/#{transaction_id}" end
signed_document_url(file_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 84 def signed_document_url(file_id) api_url + "file/document/#{file_id}" end
transaction_url(transaction_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 80 def transaction_url(transaction_id) api_url + "transaction/" + transaction_id end
upload_file_url(file_id)
click to toggle source
# File lib/sign_host/api_client.rb, line 76 def upload_file_url(file_id) api_url + "file/" + file_id end