Class: Bastille::Response
- Inherits:
-
Object
- Object
- Bastille::Response
- Defined in:
- lib/bastille/client.rb
Constant Summary collapse
- SUCCESS_CODES =
200..299
Instance Method Summary collapse
- #body ⇒ Object
- #body=(body) ⇒ Object
- #error_message ⇒ Object
-
#initialize(response, key = nil) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(response, key = nil) ⇒ Response
Returns a new instance of Response.
104 105 106 107 |
# File 'lib/bastille/client.rb', line 104 def initialize(response, key = nil) @response = response @key = key end |
Instance Method Details
#body ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/bastille/client.rb', line 109 def body contents = @response.body if @key && success? && !@response.body.empty? cipher = Gibberish::AES.new(@key) contents = Base64.decode64(@response.body) contents = cipher.decrypt(contents) end @body ||= MultiJson.load(contents) unless contents.empty? end |
#body=(body) ⇒ Object
119 120 121 |
# File 'lib/bastille/client.rb', line 119 def body=(body) @body = body end |
#error_message ⇒ Object
127 128 129 |
# File 'lib/bastille/client.rb', line 127 def body.fetch('error') end |
#success? ⇒ Boolean
123 124 125 |
# File 'lib/bastille/client.rb', line 123 def success? SUCCESS_CODES.include?(@response.code.to_i) end |