Class: FeatureFlagClient::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/feature_flag_client/client.rb

Overview

Api response wrapper

Class Method Summary collapse

Instance Method Summary collapse

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

#errorObject



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

Returns:

  • (Boolean)


32
33
34
# File 'lib/feature_flag_client/client.rb', line 32

def ok?
  @code >= 200 && @code < 400
end

#parsedObject



28
29
30
# File 'lib/feature_flag_client/client.rb', line 28

def parsed
  @parsed ||= parse_response
end