Class: Borneo::MethodProxy
- Inherits:
-
Object
- Object
- Borneo::MethodProxy
show all
- Defined in:
- lib/borneo/method_proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(service, name, components = []) ⇒ MethodProxy
Returns a new instance of MethodProxy.
9
10
11
12
13
|
# File 'lib/borneo/method_proxy.rb', line 9
def initialize(service, name, components=[])
@_service = service
@_components = components.clone
@_components << name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
63
64
65
|
# File 'lib/borneo/method_proxy.rb', line 63
def method_missing(name)
Borneo::MethodProxy.new(@_service, name, @_components)
end
|
Instance Attribute Details
#_service ⇒ Object
Returns the value of attribute _service.
7
8
9
|
# File 'lib/borneo/method_proxy.rb', line 7
def _service
@_service
end
|
Instance Method Details
#_authorization ⇒ Object
47
48
49
|
# File 'lib/borneo/method_proxy.rb', line 47
def _authorization
@_service._authorization
end
|
#_client ⇒ Object
43
44
45
|
# File 'lib/borneo/method_proxy.rb', line 43
def _client
@_service._client
end
|
#_method ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/borneo/method_proxy.rb', line 51
def _method
m = @_service._discovered_service
@_components.each do |c|
m = m.send(c)
end
m
end
|
#call(params = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/borneo/method_proxy.rb', line 19
def call(params = {})
unless mocking_enabled?
method_call = lambda do
_client.execute(
:api_method => _method,
:authorization => _authorization,
:parameters => params
)
end
response = method_call.call()
if response.status == Borneo::ResponseStatus::STALE_ACCESS_TOKEN
_client.authorization.fetch_access_token!
response = method_call.call()
end
data = response.data
else
data = mock_service.mock_response(@_components)
end
data
end
|
#mock_service ⇒ Object
59
60
61
|
# File 'lib/borneo/method_proxy.rb', line 59
def mock_service
Borneo::Client.stub_service(@_service.name, @_service.version)
end
|
#mocking_enabled? ⇒ Boolean
15
16
17
|
# File 'lib/borneo/method_proxy.rb', line 15
def mocking_enabled?
@_service.proxy.client.mocking_requests?
end
|