Skip to content

Commit

Permalink
Add get-fingerprint-data api support
Browse files Browse the repository at this point in the history
  • Loading branch information
imran-arshad committed Jun 5, 2017
1 parent 36bb15b commit d5203a0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/bayonet_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def feedback_historical(params)
request('/feedback-historical', serialized)
end

def get_fingerprint_data(params)
serialized = json_from_params(params)
request('/get-fingerprint-data', serialized)
end

def validate_params(params)
params.class == Hash
end
Expand All @@ -55,7 +60,7 @@ def request(route, json_params)
end

def request_json_string(route, request_json_args)
fq_hostname = fully_qualified_api_host_name
fq_hostname = fully_qualified_api_host_name(route)
url = "#{fq_hostname}#{route}"

headers = {'User-Agent' => 'OfficialBayonetRubySDK',
Expand All @@ -71,8 +76,11 @@ def request_json_string(route, request_json_args)
end
end

def fully_qualified_api_host_name
def fully_qualified_api_host_name(route)
default_domain = 'api.bayonet.io'
if route == '/get-fingerprint-data'
default_domain = 'fingerprinting.bayonet.io'
end
api_version_namespace = 'v' + @version
"https://#{default_domain}/#{api_version_namespace}"
end
Expand Down
5 changes: 4 additions & 1 deletion lib/bayonet_client/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BayonetClient

class BayonetError < Exception
attr_accessor :request_body, :request_headers, :http_response_code, :http_response_json,
:reason_code, :reason_message
:reason_code, :reason_message, :status

def initialize(request_body, request_headers,
http_response_code, http_response_json)
Expand All @@ -22,6 +22,9 @@ def initialize(request_body, request_headers,
else
self.reason_message = http_response_json
end
if http_response_json.class == HTTParty::Response && http_response_json.key?('status')
self.status = http_response_json['status']
end
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/bayonet_client/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module BayonetClient
class BayonetResponse
attr_accessor :feedback_api_trans_code, :rules_triggered,
:risk_level, :payload, :reason_code,
:reason_message, :request_body
:reason_message, :request_body, :bayonet_fingerprint,
:raw

def initialize(parsed_response)

Expand All @@ -30,6 +31,10 @@ def initialize(parsed_response)
if parsed_response.key?('request_body')
self.request_body = parsed_response['request_body']
end
if parsed_response.key?('bayonet_fingerprint')
self.bayonet_fingerprint = parsed_response['bayonet_fingerprint']
end
self.raw = parsed_response
end
end
end
17 changes: 17 additions & 0 deletions spec/bayonet_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def keys_to_symbols(hash)
@params_feedback = keys_to_symbols load_fixture('params_feedback')
@params_feedback_historical = keys_to_symbols load_fixture('params_feedback_historical')
@params_chargeback_feedback = keys_to_symbols load_fixture('params_chargeback_feedback')
@params_get_fingerprint_data = keys_to_symbols load_fixture('params_get_fingerprint_data')

end

Expand Down Expand Up @@ -134,4 +135,20 @@ def keys_to_symbols(hash)
end
end

describe 'GetFingerprintDataEndpoint' do
it 'should return error on invalid api key' do
expect{
@invalid_client.get_fingerprint_data(@params_get_fingerprint_data)
}.to raise_error(BayonetClient::BayonetError)
end

it 'should return error on invalid bayonet fingerprint token' do
begin
@invalid_client.get_fingerprint_data(@params_get_fingerprint_data)
rescue BayonetClient::BayonetError => e
expect(e.status).to eq('Error: Invalid value for bayonet_fingerprint_token')
end
end
end

end
4 changes: 4 additions & 0 deletions spec/fixtures/api_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ params_feedback_historical: {
country: MEX,
zip_code: 111111
}
}

params_get_fingerprint_data: {
bayonet_fingerprint_token: xxx
}

0 comments on commit d5203a0

Please sign in to comment.