Module: SimpleApiClient

Defined in:
lib/simple_api_client.rb,
lib/simple_api_client/version.rb,
lib/simple_api_client/testing_server.rb

Defined Under Namespace

Classes: TestingServer

Constant Summary collapse

ARGUMENT_ERROR_MESSAGE_HOST_MISSING =
'First argument must be a URI object or a URI string that provides a host. (i.e //myhost or http://myhost). Note: Scheme defaults to http if not provided.'
ARGUMENT_ERROR_MESSAGE_RESPOND_TO_CALL_NEEDED =
'Second argument must be a class that response_to?(:call).'
VERSION =
"0.0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callerObject (readonly)

Returns the value of attribute caller.



14
15
16
# File 'lib/simple_api_client.rb', line 14

def caller
  @caller
end

Instance Method Details

#initialize(uri, api_caller) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/simple_api_client.rb', line 16

def initialize uri, api_caller
  @uri = URI(uri)
  raise ArgumentError.new(ARGUMENT_ERROR_MESSAGE_HOST_MISSING) if @uri.host.nil?
  raise ArgumentError.new(ARGUMENT_ERROR_MESSAGE_RESPOND_TO_CALL_NEEDED) unless api_caller.respond_to?(:call)
  @caller = api_caller
end

#schemeObject



23
24
25
# File 'lib/simple_api_client.rb', line 23

def scheme
  @uri.scheme || 'http'
end

#uri(relative_path) ⇒ Object



27
28
29
# File 'lib/simple_api_client.rb', line 27

def uri relative_path
  URI("#{scheme}://#{host}:#{port}#{relative_path}")
end