class Borneo::MethodProxy

Attributes

_service[RW]

Public Class Methods

new(service, name, components=[]) click to toggle source
# File lib/borneo/method_proxy.rb, line 9
def initialize(service, name, components=[])
  @_service = service
  @_components = components.clone
  @_components << name
end

Public Instance Methods

_authorization() click to toggle source
# File lib/borneo/method_proxy.rb, line 47
def _authorization
  @_service._authorization
end
_client() click to toggle source
# File lib/borneo/method_proxy.rb, line 43
def _client
  @_service._client
end
_method() click to toggle source
# 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 = {}) click to toggle source
# 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
method_missing(name) click to toggle source
# File lib/borneo/method_proxy.rb, line 63
def method_missing(name)
  Borneo::MethodProxy.new(@_service, name, @_components)
end
mock_service() click to toggle source
# File lib/borneo/method_proxy.rb, line 59
def mock_service
  Borneo::Client.stub_service(@_service.name, @_service.version)
end
mocking_enabled?() click to toggle source
# File lib/borneo/method_proxy.rb, line 15
def mocking_enabled?
  @_service.proxy.client.mocking_requests?
end