Class: Talkbird::Result::Success

Inherits:
Object
  • Object
show all
Defined in:
lib/talkbird/result/success.rb

Overview

Success monad (sort of).

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (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_codeObject



15
16
17
# File 'lib/talkbird/result/success.rb', line 15

def status_code
  @result.code
end