Sha256: 8c3206c3e8c8b7cd155001cd53d8333296e8c1395125c5e17d82c339b64079c1
Contents?: true
Size: 1.53 KB
Versions: 17
Compression:
Stored size: 1.53 KB
Contents
require 'rest_client' module Biro module CredDefense class Request < BaseRequest def production_url 'https://www.creddefense.com/index.php/api/v2' end def development_url 'https://test.creddefense.com/index.php/api/v2' end def required_params [:username, :password] end def find(document) params = { authentication: { token: token }, advancedsearch: { identifier_code: document } } begin response = RestClient.post(search_path, params.to_json, headers) Response.new(response) rescue => e Biro.log(:warn, "Unable to process CredDefense request") raise "Error at CredDefense request: #{e.message}" end end private def login_path url + '/login' end def search_path url + '/advancedsearch' end def token @token ||= get_token end def get_token auth = { authentication: { username: @username, password: @password } } response = JSON.parse(RestClient.post(login_path, auth.to_json, headers).body) raise AuthenticationError.new('Invalid authentication credentials') unless success?(response) response.dig('authentication', 'token') end def success?(response) response['result'] == 'success' end def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } end end end end
Version data entries
17 entries across 17 versions & 1 rubygems