Class: Stella::Data::HTTP::Request
- Inherits:
-
Storable
- Object
- Storable
- Stella::Data::HTTP::Request
show all
- Includes:
- Gibbler::Complex, Stella::Data::Helpers
- Defined in:
- lib/stella/data/http/request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#file, #random, #rsequential, #sequential
Constructor Details
#initialize(method, uri_str, version = "1.1", &definition) ⇒ Request
Returns a new instance of Request.
31
32
33
34
35
36
37
38
39
|
# File 'lib/stella/data/http/request.rb', line 31
def initialize (method, uri_str, version="1.1", &definition)
@uri = uri_str
@http_method, @http_version = method, version
@headers, @params, @response_handler = {}, {}, {}
@wait = 0
@desc = "Request"
@body = Stella::Data::HTTP::Body.new
instance_eval &definition unless definition.nil?
end
|
Instance Attribute Details
#response_handler ⇒ Object
A hash containing blocks to be executed depending on the HTTP response status. The hash keys are numeric HTTP Status Codes.
200 => { ... }
304 => { ... }
500 => { ... }
15
16
17
|
# File 'lib/stella/data/http/request.rb', line 15
def response_handler
@response_handler
end
|
Instance Method Details
#body(*args) ⇒ Object
content
can be literal content or a file path
81
82
83
84
|
# File 'lib/stella/data/http/request.rb', line 81
def body(*args)
return @body if args.empty?
@body = args.first
end
|
#content_type(*args) ⇒ Object
46
47
48
49
|
# File 'lib/stella/data/http/request.rb', line 46
def content_type(*args)
@content_type = args.first unless args.empty?
@content_type
end
|
#cookies ⇒ Object
98
99
100
101
|
# File 'lib/stella/data/http/request.rb', line 98
def cookies
return [] if !.is_a?(Hash) || [:Cookie].empty?
[:Cookie]
end
|
#desc(*args) ⇒ Object
41
42
43
44
|
# File 'lib/stella/data/http/request.rb', line 41
def desc(*args)
@desc = args.first unless args.empty?
@desc
end
|
#has_body? ⇒ Boolean
27
28
29
|
# File 'lib/stella/data/http/request.rb', line 27
def has_body?
!@body.nil?
end
|
57
58
59
60
|
# File 'lib/stella/data/http/request.rb', line 57
def (*args)
@headers.merge! args.first unless args.empty?
@headers
end
|
#inspect ⇒ Object
86
87
88
89
90
91
|
# File 'lib/stella/data/http/request.rb', line 86
def inspect
str = "%s %s HTTP/%s" % [http_method, uri.to_s, http_version]
str
end
|
#params(*args) ⇒ Object
Also known as:
param
63
64
65
66
|
# File 'lib/stella/data/http/request.rb', line 63
def params(*args)
@params.merge! args.first unless args.empty?
@params
end
|
#response(*args, &definition) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/stella/data/http/request.rb', line 69
def response(*args, &definition)
if definition.nil?
@response_handler
else
args << /.+/ if args.empty?
args.each do |status|
@response_handler[status] = definition
end
end
end
|
#to_s ⇒ Object
93
94
95
96
|
# File 'lib/stella/data/http/request.rb', line 93
def to_s
str = "%s %s HTTP/%s" % [http_method, uri.to_s, http_version]
str
end
|
#wait(*args) ⇒ Object
Also known as:
sleep
51
52
53
54
|
# File 'lib/stella/data/http/request.rb', line 51
def wait(*args)
@wait = args.first unless args.empty?
@wait
end
|