Class: Gecko::Http::Result
- Inherits:
-
Object
- Object
- Gecko::Http::Result
- Defined in:
- lib/gecko/http.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_env ⇒ Object
Returns the value of attribute response_env.
Instance Method Summary collapse
- #error ⇒ Object
- #error? ⇒ Boolean
- #fetch(*keys) ⇒ Object
- #http_200? ⇒ Boolean
-
#initialize(response) ⇒ Result
constructor
A new instance of Result.
- #on_complete(&block) ⇒ Object
- #response_body ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Result
Returns a new instance of Result.
40 41 42 |
# File 'lib/gecko/http.rb', line 40 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
37 38 39 |
# File 'lib/gecko/http.rb', line 37 def response @response end |
#response_env ⇒ Object
Returns the value of attribute response_env.
38 39 40 |
# File 'lib/gecko/http.rb', line 38 def response_env @response_env end |
Instance Method Details
#error ⇒ Object
67 68 69 |
# File 'lib/gecko/http.rb', line 67 def error Error.new(self.fetch(:error), self.response.status) end |
#error? ⇒ Boolean
63 64 65 |
# File 'lib/gecko/http.rb', line 63 def error? self.fetch(:success) != true end |
#fetch(*keys) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/gecko/http.rb', line 71 def fetch(*keys) keys.inject(self.response_body) do |body_hash, key| break unless body_hash body_hash.fetch(key, nil) end end |
#http_200? ⇒ Boolean
59 60 61 |
# File 'lib/gecko/http.rb', line 59 def http_200? self.response.status == 200 end |
#on_complete(&block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/gecko/http.rb', line 44 def on_complete(&block) self.response.on_complete do |env| self.response_env = env block.call(self.success?, self) end end |
#response_body ⇒ Object
51 52 53 |
# File 'lib/gecko/http.rb', line 51 def response_body self.response.body end |
#success? ⇒ Boolean
55 56 57 |
# File 'lib/gecko/http.rb', line 55 def success? self.http_200? && !self.error? end |