Class: Harvest::HTTP::Client
- Inherits:
-
Object
- Object
- Harvest::HTTP::Client
show all
- Defined in:
- lib/harvest/httpclient.rb
Overview
lower level class which create the Client for making api calls
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
#method_missing(meth, *args) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# 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
|
Instance Attribute Details
#state ⇒ Object
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
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
|
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/harvest/httpclient.rb', line 35
def (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
|