# frozen_string_literal: true require 'credit_gateway/errors' require 'credit_gateway/client' module CreditGateway class BaseRepository def initialize(client: nil) @client = client || Client.new end private attr_reader :client def get(path, params: {}, identity: nil) headers = identity ? identity.to_headers : {} result = client.get(path.strip, headers: headers, params: params) raise APIKeyError, result.body[:error] if result.status == 401 result end def post(path, params: {}, identity: nil) headers = identity ? identity.to_headers : {} result = client.post(path.strip, headers: headers, params: params) raise APIKeyError, result.body[:error] if result.status == 401 result end def format_url(url, params) formatted = url.dup.strip params.each { |key, value| formatted.sub!(":#{key}", value) } formatted end end end