Class: Harvest::HTTP::Client
- Inherits:
-
Object
- Object
- Harvest::HTTP::Client
- Defined in:
- lib/harvest/httpclient.rb
Overview
lower level class which create the Client for making api calls
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #allowed?(meth) ⇒ Boolean
- #client ⇒ Object
- #headers(personal_token, account_id) ⇒ Object
-
#initialize(state: {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(meth, *args) ⇒ Object
- #respond_to_missing? ⇒ Boolean
Constructor Details
#initialize(state: {}) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/harvest/httpclient.rb', line 7 def initialize(state: {}) @state = state end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/harvest/httpclient.rb', line 11 def state @state end |
Instance Method Details
#allowed?(meth) ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/harvest/httpclient.rb', line 23 def allowed?(meth) %i[ domain headers client ].include?(meth) end |
#client ⇒ Object
49 50 51 52 53 54 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
#respond_to_missing? ⇒ Boolean
31 32 33 |
# File 'lib/harvest/httpclient.rb', line 31 def respond_to_missing?(*) super end |