Sha256: 16951ae47c523203fd2114b544edad0ba968554f8d13f86487dcd373bc8c6941

Contents?: true

Size: 807 Bytes

Versions: 5

Compression:

Stored size: 807 Bytes

Contents

# frozen_string_literal: true

require 'truelayer/errors'
require 'truelayer/client'

module Truelayer
  class BaseRepository
    def initialize(access_token:, client: nil)
      @client = client || Client.new(access_token)
    end

    private

    attr_reader :client

    def get(path, params: {})
      result = client.get(path.strip, params: params)

      raise UnauthorizedError, result.body[:error] if result.status == 401

      result
    end

    def post(path, params: {})
      result = client.post(path.strip, params: params)

      raise UnauthorizedError, 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
truelayer-0.1.4 lib/truelayer/base_repository.rb
truelayer-0.1.3 lib/truelayer/base_repository.rb
truelayer-0.1.2 lib/truelayer/base_repository.rb
truelayer-0.1.1 lib/truelayer/base_repository.rb
truelayer-0.1.0 lib/truelayer/base_repository.rb