Class: Freno::Client::Result
- Inherits:
-
Object
- Object
- Freno::Client::Result
- Defined in:
- lib/freno/client/result.rb
Constant Summary collapse
- FRENO_STATUS_CODE_MEANINGS =
{ 200 => :ok, 404 => :not_found, 417 => :expectation_failed, 429 => :too_many_requests, 500 => :internal_server_error }.freeze
- ADDITIONAL_STATUS_CODE_MEANINGS =
these are included to add resiliency to freno-client
{ 408 => :request_timeout }.freeze
- CODE_MEANINGS =
FRENO_STATUS_CODE_MEANINGS.merge(ADDITIONAL_STATUS_CODE_MEANINGS).freeze
- MEANING_CODES =
CODE_MEANINGS.invert.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#meaning ⇒ Object
readonly
Returns the value of attribute meaning.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #body ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(code, body = nil) ⇒ Result
constructor
A new instance of Result.
- #ok? ⇒ Boolean
- #unkown? ⇒ Boolean
Constructor Details
#initialize(code, body = nil) ⇒ Result
Returns a new instance of Result.
35 36 37 38 39 |
# File 'lib/freno/client/result.rb', line 35 def initialize(code, body = nil) @code = code @meaning = CODE_MEANINGS[code] || :unknown @raw_body = body end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
33 34 35 |
# File 'lib/freno/client/result.rb', line 33 def code @code end |
#meaning ⇒ Object (readonly)
Returns the value of attribute meaning.
33 34 35 |
# File 'lib/freno/client/result.rb', line 33 def meaning @meaning end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
33 34 35 |
# File 'lib/freno/client/result.rb', line 33 def raw_body @raw_body end |
Class Method Details
.from_faraday_response(response) ⇒ Object
25 26 27 |
# File 'lib/freno/client/result.rb', line 25 def self.from_faraday_response(response) new(response.status, response.body) end |
.from_meaning(meaning) ⇒ Object
29 30 31 |
# File 'lib/freno/client/result.rb', line 29 def self.from_meaning(meaning) new(MEANING_CODES[meaning] || 0) end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 60 61 |
# File 'lib/freno/client/result.rb', line 57 def ==(other) return meaning == other if other.is_a? Symbol code == other end |
#body ⇒ Object
53 54 55 |
# File 'lib/freno/client/result.rb', line 53 def body @body ||= JSON.parse(raw_body) if raw_body end |
#failed? ⇒ Boolean
45 46 47 |
# File 'lib/freno/client/result.rb', line 45 def failed? !ok? end |
#ok? ⇒ Boolean
41 42 43 |
# File 'lib/freno/client/result.rb', line 41 def ok? meaning == :ok end |
#unkown? ⇒ Boolean
49 50 51 |
# File 'lib/freno/client/result.rb', line 49 def unkown? meaning == :unkown end |