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

- (Result) initialize(&block)

A new instance of Result



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

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

- (Object) errors

Returns the value of attribute errors



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

def errors
  @errors
end

- (Object) request

Returns the value of attribute request



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

def request
  @request
end

- (Object) response

Returns the value of attribute response



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

def response
  @response
end

- (Object) success

Returns the value of attribute success



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

def success
  @success
end

Instance Method Details

- (Object) populate(response_body)



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

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