Class: Talkbird::Result::Success
- Inherits:
-
Object
- Object
- Talkbird::Result::Success
- Defined in:
- lib/talkbird/result/success.rb
Overview
Success monad (sort of).
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(result, body = nil) ⇒ Success
constructor
A new instance of Success.
- #parse_body(body) ⇒ Object
- #status_code ⇒ Object
Constructor Details
#initialize(result, body = nil) ⇒ Success
Returns a new instance of Success.
10 11 12 13 |
# File 'lib/talkbird/result/success.rb', line 10 def initialize(result, body = nil) @result = result @body = parse_body(body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/talkbird/result/success.rb', line 8 def body @body end |
Instance Method Details
#parse_body(body) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/talkbird/result/success.rb', line 19 def parse_body(body) if body.nil? MultiJson.load(@result.body.to_s) elsif body.is_a?(String) MultiJson.load(body) else body end end |
#status_code ⇒ Object
15 16 17 |
# File 'lib/talkbird/result/success.rb', line 15 def status_code @result.code end |