Sha256: 2ae9df4c5ac4a352a73308dbce825a8f7bc3626915ed7029a26f7f6ed6116263
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true require 'creditsafe/client' require 'creditsafe/errors' require 'creditsafe/version' module Creditsafe class Authenticate def call(username, password) response = post('authenticate', username: username, password: password) if response.success? response.body[:token] elsif response.status == 401 raise UnauthorizedError, response.body else raise GenericError, response.body end end private def post(path, params = {}) connection.post(path, MultiJson.dump(params)) end def connection api_url = Client.new.api_url @connection ||= Faraday.new(url: api_url) do |conn| conn.headers.merge!( content_type: 'application/json', user_agent: "finpoint/#{Creditsafe::VERSION}" ) conn.response :json, parser_options: { symbolize_names: true } conn.response :logger if Creditsafe.configuration.debug conn.adapter Faraday.default_adapter end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
creditsafe_connect-0.1.7 | lib/creditsafe/authenticate.rb |
creditsafe_connect-0.1.6 | lib/creditsafe/authenticate.rb |