Sha256: cf405d377218d200b0b1107f0076ee93692c82dce1854ef698badb19e1bbac96

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wells_fargo-api-0.1.0 lib/wells_fargo/api.rb