Sha256: 23cd5ecd1cb3e4f1eb238a2b89cd44d5012fb10fecaf24b3353d679d5f476dbe
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true require 'credit_gateway/configuration' require 'credit_gateway/errors' require 'credit_gateway/version' module CreditGateway class Authenticate def call(client_id, client_secret) response = post( '/auth/connect/token', client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' ) if response.success? response.body[:access_token] elsif response.status == 400 raise InvalidRequestError, response.body else raise GenericError, response.body end end private def post(path, params = {}) connection.post(path, params) end def connection auth_url = CreditGateway.configuration.auth_url @connection ||= Faraday.new(url: auth_url) do |conn| conn.request :url_encoded conn.headers.merge!( user_agent: "finpoint/#{CreditGateway::VERSION}" ) conn.response :json, parser_options: { symbolize_names: true } conn.response :logger if CreditGateway.configuration.debug conn.adapter Faraday.default_adapter end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
credit_gateway-0.3.2 | lib/credit_gateway/authenticate.rb |
credit_gateway-0.3.1 | lib/credit_gateway/authenticate.rb |