Class: Amiando::Result

Inherits:
Object
  • Object
show all
Includes:
Autorun
Defined in:
lib/amiando/result.rb

Overview

This object is intended to be used when an api will return value that is not a resource object (a User, an Event, etc), but due to the delayed nature of doing requests in parallel, can’t be initialized from the beginning.

After the object is populated, you can ask the result with the result method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Autorun

included

Constructor Details

#initialize(&block) ⇒ Result

Returns a new instance of Result.



18
19
20
21
22
23
24
# File 'lib/amiando/result.rb', line 18

def initialize(&block)
  @populator = block
  @populator ||= Proc.new do |response_body, result|
    result.errors = response_body['errors']
    response_body['success']
  end
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



13
14
15
# File 'lib/amiando/result.rb', line 13

def errors
  @errors
end

#requestObject

Returns the value of attribute request.



13
14
15
# File 'lib/amiando/result.rb', line 13

def request
  @request
end

#responseObject

Returns the value of attribute response.



13
14
15
# File 'lib/amiando/result.rb', line 13

def response
  @response
end

#resultObject (readonly)

Returns the value of attribute result.



14
15
16
# File 'lib/amiando/result.rb', line 14

def result
  @result
end

#successObject (readonly)

Returns the value of attribute success.



14
15
16
# File 'lib/amiando/result.rb', line 14

def success
  @success
end

Instance Method Details

#populate(response_body) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/amiando/result.rb', line 26

def populate(response_body)
  if @populator.arity == 1
    @result = @populator.call(response_body)
  elsif @populator.arity == 2
    @result = @populator.call(response_body, self)
  end
  @success = response_body['success']
end