Skip to content

Instantly share code, notes, and snippets.

@nataliaconde
Last active June 28, 2021 11:55
Show Gist options
  • Save nataliaconde/d37a5f8ef2a62341227a3cd27f036d19 to your computer and use it in GitHub Desktop.
Save nataliaconde/d37a5f8ef2a62341227a3cd27f036d19 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