class Trustdock::Client
Constants
- PRODUCTION_URL
- SANDBOX_URL
Attributes
last_response[R]
Public Class Methods
new(api_token, sandbox: false)
click to toggle source
# File lib/trustdock/client.rb, line 8 def initialize(api_token, sandbox: false) @api_token = api_token @sandbox = sandbox end
Public Instance Methods
create_verification(options = {})
click to toggle source
# File lib/trustdock/client.rb, line 19 def create_verification(options = {}) @last_response = request(:post, "/v2/verifications", options) Response::Verification.new JSON.parse(@last_response.body, symbolize_names: true) end
update_comparing_data(verification_id, options)
click to toggle source
# File lib/trustdock/client.rb, line 37 def update_comparing_data(verification_id, options) @last_response = request(:put, "/v2/verifications/#{verification_id}/comparing_data", options) nil end
update_document(verification_id, plan_id, options)
click to toggle source
# File lib/trustdock/client.rb, line 31 def update_document(verification_id, plan_id, options) @last_response = request(:put, "/v2/verifications/#{verification_id}/plans/#{plan_id}/documents", options) nil end
update_plan(verification_id, options)
click to toggle source
# File lib/trustdock/client.rb, line 25 def update_plan(verification_id, options) @last_response = request(:put, "/v2/verifications/#{verification_id}/plans", options) nil end
verification(id)
click to toggle source
# File lib/trustdock/client.rb, line 13 def verification(id) @last_response = request(:get, "/v2/verifications/#{id}") Response::Verification.new JSON.parse(@last_response.body, symbolize_names: true) end
Private Instance Methods
api_url()
click to toggle source
# File lib/trustdock/client.rb, line 74 def api_url @sandbox ? SANDBOX_URL : PRODUCTION_URL end
client()
click to toggle source
# File lib/trustdock/client.rb, line 65 def client @client ||= Faraday.new(api_url) do |conn| conn.headers["Content-Type"] = "application/json" conn.authorization :Bearer, @api_token conn.response :raise_error conn.adapter Faraday.default_adapter end end
request(method, path, options = nil)
click to toggle source
# File lib/trustdock/client.rb, line 45 def request(method, path, options = nil) client.send(method, path, (options) ? options.to_json : nil) rescue Faraday::Error => e @last_response = e.response case e.response[:status] when 401 raise UnauthorizedError when 404 raise NotFoundError when 422 raise UnprocessableEntityError when 500 raise InternalServerError when 503 raise ServiceUnavailableError end end