class Harvest::HTTP::Client

lower level class which create the Client for making api calls

Attributes

state[R]

Public Class Methods

new(state: {}) click to toggle source
# File lib/harvest/httpclient.rb, line 7
def initialize(state: {})
  @state = state
end

Public Instance Methods

allowed?(meth) click to toggle source
# File lib/harvest/httpclient.rb, line 23
def allowed?(meth)
  %i[
    domain
    headers
    client
  ].include?(meth)
end
client() click to toggle source
# File lib/harvest/httpclient.rb, line 49
def client
  RestClient::Resource.new(
    "#{@state[:domain].chomp('/')}/api/v2",
    headers: @state[:headers]
  )
end
headers(personal_token, account_id) click to toggle source
# File lib/harvest/httpclient.rb, line 35
def headers(personal_token, account_id)
  Client.new(
    state: @state.merge(
      {
        headers: {
          'User-Agent' => 'harvest-ruby API Client',
          'Authorization' => "Bearer #{personal_token}",
          'Harvest-Account-ID' => account_id
        }
      }
    )
  )
end
method_missing(meth, *args) click to toggle source
Calls superclass method
# File lib/harvest/httpclient.rb, line 13
def method_missing(meth, *args)
  if allowed?(meth)
    Client.new(
      state: @state.merge(meth => args.first)
    )
  else
    super
  end
end
respond_to_missing?(*) click to toggle source
Calls superclass method
# File lib/harvest/httpclient.rb, line 31
def respond_to_missing?(*)
  super
end