# frozen_string_literal: true require 'excon' require_relative 'endpoints' require_relative 'response' module WellsFargo class API include Endpoints attr_reader :url, :credentials def initialize(url, credentials) @url = url @credentials = credentials end def execute(method, path, params) raw_response = connection.request(method: method, path: path, **params) Response.new(raw_response) end private def connection @connection ||= Excon.new( url, client_cert: credentials[:client_cert], client_key: credentials[:client_key], ssl_verify_peer: false, headers: default_headers ) end def default_headers { 'Authorization' => "Basic #{auth_token}", 'gateway-company-id' => credentials[:gateway_company_id] } end def auth_token Base64.strict_encode64( "#{credentials[:consumer_key]}:#{credentials[:consumer_secret]}" ) end end end