Class: Wrappi::Request
- Inherits:
-
Object
show all
- Defined in:
- lib/wrappi/request.rb,
lib/wrappi/request/get.rb,
lib/wrappi/request/template.rb,
lib/wrappi/request/with_body.rb
Defined Under Namespace
Classes: Get, Template, WithBody
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(endpoint) ⇒ Request
Returns a new instance of Request.
4
5
6
|
# File 'lib/wrappi/request.rb', line 4
def initialize(endpoint)
@endpoint = endpoint
end
|
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
3
4
5
|
# File 'lib/wrappi/request.rb', line 3
def endpoint
@endpoint
end
|
Instance Method Details
#call ⇒ Object
Also known as:
http
23
24
25
|
# File 'lib/wrappi/request.rb', line 23
def call
@call ||= strategy.call
end
|
#strategy ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/wrappi/request.rb', line 12
def strategy
@strategy ||= case verb
when :get
Get.new(endpoint)
when :post, :delete, :put
WithBody.new(endpoint)
else
raise 'Verb strategy not defined'
end
end
|
#to_h ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/wrappi/request.rb', line 28
def to_h
@to_h ||= {
raw_body: http.raw_body,
code: http.code,
uri: http.uri
}
end
|
#verb ⇒ Object
8
9
10
|
# File 'lib/wrappi/request.rb', line 8
def verb
endpoint.verb
end
|