Class: FeatureFlagClient::Response
- Inherits:
-
Object
- Object
- FeatureFlagClient::Response
- Defined in:
- lib/feature_flag_client/client.rb
Overview
Api response wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #parsed ⇒ Object
Constructor Details
#initialize(raw_response) ⇒ Response
Returns a new instance of Response.
23 24 25 26 |
# File 'lib/feature_flag_client/client.rb', line 23 def initialize(raw_response) @body = raw_response.body @code = raw_response.code end |
Class Method Details
.from_raw(raw_response) ⇒ Object
19 20 21 |
# File 'lib/feature_flag_client/client.rb', line 19 def self.from_raw(raw_response) new(raw_response) end |
Instance Method Details
#error ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/feature_flag_client/client.rb', line 36 def error case @code when 401...505 parsed = JSON.parse(@body) parsed.key?('message') ? parsed['message'] : parsed['error'] end end |
#ok? ⇒ Boolean
32 33 34 |
# File 'lib/feature_flag_client/client.rb', line 32 def ok? @code >= 200 && @code < 400 end |
#parsed ⇒ Object
28 29 30 |
# File 'lib/feature_flag_client/client.rb', line 28 def parsed @parsed ||= parse_response end |