Sha256: 628da4a976a1cbecf4cab31548709ac65bebf87a8f0ca1994dc11485523d0aa9

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

require "rexpense/request"
require "rexpense/response"

module Rexpense
  class Client
    attr_reader :http

    def initialize(token)
      @http = Http.new(token)
    end

    def authenticated?
      http.get("/organizations") { |response| response.code == 200 }
    rescue RequestError => e
      raise e unless [401, 403].include?(e.code)
      false
    end

    # Define available endpoints

    def activities
      Rexpense::Resources::Activity.new(http)
    end

    def advancement_devolutions
      Rexpense::Resources::AdvancementDevolution.new(http)
    end

    def pre_expenses
      Rexpense::Resources::PreExpense.new(http)
    end

    %w(organization expense advancement reimbursement tag webhook membership comment).each do |endpoint|
      define_method(endpoint + 's') do
        Object.const_get("Rexpense::Resources::#{endpoint.capitalize}").new(http)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rexpense-2.1.0 lib/rexpense/client.rb
rexpense-2.0.0 lib/rexpense/client.rb