Class: FakeServer::RemoteAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_server/remote_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ RemoteAPI

Returns a new instance of RemoteAPI.



5
6
7
8
# File 'lib/fake_server/remote_api.rb', line 5

def initialize(host)
  @host = host
  @host = "http://#{host}" unless host[/\Ahttp/]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/fake_server/remote_api.rb', line 10

def host
  @host
end

Instance Method Details

#request(method, relative_url) ⇒ Object



12
13
14
15
16
# File 'lib/fake_server/remote_api.rb', line 12

def request(method, relative_url)
  response = HTTParty.public_send(method.downcase, "#{host}#{relative_url}")
  response.headers.delete 'transfer-encoding'
  [response.code, response.headers, [response.body]]
end