Class: LucidHttp::Response
- Inherits:
-
Object
- Object
- LucidHttp::Response
- Defined in:
- lib/lucid_http/response.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #body ⇒ Object
- #content_type ⇒ Object
- #error ⇒ Object
-
#initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {}) ⇒ Response
constructor
A new instance of Response.
- #status ⇒ Object
- #url ⇒ Object
- #verb ⇒ Object
Constructor Details
#initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {}) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/lucid_http/response.rb', line 6 def initialize(base_url:, path:, formatter:, follower:, verb: :get, form: {}) @base_url = base_url @path = path @formatter = LucidHttp::Formatter.for(formatter) @follower = LucidHttp::Follower.for(follower).client @verb = verb @form = form @response = @follower.send(@verb, url, params: form) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
3 4 5 |
# File 'lib/lucid_http/response.rb', line 3 def base_url @base_url end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/lucid_http/response.rb', line 4 def path @path end |
Instance Method Details
#body ⇒ Object
17 18 19 |
# File 'lib/lucid_http/response.rb', line 17 def body @formatter.call(@response.body.to_s) end |
#content_type ⇒ Object
25 26 27 |
# File 'lib/lucid_http/response.rb', line 25 def content_type @response.content_type.mime_type end |
#error ⇒ Object
33 34 35 |
# File 'lib/lucid_http/response.rb', line 33 def error body.split("\n").first || "No error found" end |
#status ⇒ Object
21 22 23 |
# File 'lib/lucid_http/response.rb', line 21 def status @response.status.to_s end |
#url ⇒ Object
29 30 31 |
# File 'lib/lucid_http/response.rb', line 29 def url "#{base_url}#{path}" end |
#verb ⇒ Object
37 38 39 |
# File 'lib/lucid_http/response.rb', line 37 def verb @verb.to_s.upcase end |