Class: HttpMonkey::Client
- Inherits:
-
Object
- Object
- HttpMonkey::Client
show all
- Defined in:
- lib/http_monkey/client.rb
Defined Under Namespace
Classes: Environment, EnvironmentBuilder, Response
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
5
6
7
|
# File 'lib/http_monkey/client.rb', line 5
def initialize
@conf = Configuration.new
end
|
Instance Method Details
26
27
28
29
|
# File 'lib/http_monkey/client.rb', line 26
def configure(&block)
@conf.instance_eval(&block) if block_given?
self
end
|
#http_request(method, request) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/http_monkey/client.rb', line 31
def http_request(method, request)
client = self
env = Client::EnvironmentBuilder.new(self, method, request).to_env
begin
code, , body = @conf.middlewares.execute(Middlewares::HttpRequest, env)
body.close if body.respond_to?(:close) rescue => error
raise unless @conf.behaviours.error_behaviour
return @conf.behaviours.error_behaviour.call(client, request, error)
end
response = Client::Response.new(code, , body)
behaviour = @conf.behaviours.find(response.code)
behaviour.call(client, request, response)
end
|
#initialize_copy(source) ⇒ Object
9
10
11
12
|
# File 'lib/http_monkey/client.rb', line 9
def initialize_copy(source)
super
@conf = @conf.clone
end
|
#net_adapter ⇒ Object
18
19
20
|
# File 'lib/http_monkey/client.rb', line 18
def net_adapter
@conf.net_adapter
end
|
#storage ⇒ Object
22
23
24
|
# File 'lib/http_monkey/client.rb', line 22
def storage
@conf.storage
end
|