Skip to content

Instantly share code, notes, and snippets.

@julianalucena
Forked from nataliaconde/api.rb
Last active June 26, 2021 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianalucena/1e9365bcbd978f96910d5b1841dff3ce to your computer and use it in GitHub Desktop.
Save julianalucena/1e9365bcbd978f96910d5b1841dff3ce to your computer and use it in GitHub Desktop.
require 'faraday'
require 'json'
module Incognia
class Api
include Singleton
API_HOST = 'https://api.us.incognia.com/api/'.freeze
def register_login(installation_id:, account_id:)
transactions_endpoint = 'v2/authentication/transactions'
params = {
installation_id: installation_id,
account_id: account_id,
type: 'login'
}
response = Faraday.post(
"#{API_HOST}#{transactions_endpoint}",
params.to_json,
headers
)
if response.status == 200
parsed_body = JSON.parse(response.body)
parsed_body['risk_assessment']
else
# Error handling
end
end
private
def headers
{
'Content-Type': 'application/json',
# Read more about how to generate a fresh token at our
# Authenticating in Incognia APIs section.
Authorization: "Bearer #{fresh_token}"
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment