# 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: {}) result = client.get(path.strip, params: params) raise APIKeyError, result.body[:error] if result.status == 401 result end def post(path, params: {}) result = client.post(path.strip, 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