Class: Wonde::ResultIterator

Inherits:
Endpoints show all
Includes:
Enumerable
Defined in:
lib/resultiterator.rb

Instance Attribute Summary collapse

Attributes inherited from Endpoints

#endpoint, #uri, #version

Instance Method Summary collapse

Methods inherited from Endpoints

#all, #delete, #deleteRequest, #deleteUrl, #get, #getRequest, #getUrl, #post, #postRequest, #postUrl

Constructor Details

#initialize(myhashostruct, token) ⇒ ResultIterator

Returns a new instance of ResultIterator.



5
6
7
8
9
10
11
# File 'lib/resultiterator.rb', line 5

def initialize(myhashostruct, token)
  super
  p myhashostruct if ENV["debug_wonde"]
  self.token = token
  self.myarray = myhashostruct.data
  self.meta = myhashostruct.meta unless myhashostruct.meta.nil?
end

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



4
5
6
# File 'lib/resultiterator.rb', line 4

def meta
  @meta
end

#myarrayObject

Returns the value of attribute myarray.



4
5
6
# File 'lib/resultiterator.rb', line 4

def myarray
  @myarray
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/resultiterator.rb', line 4

def token
  @token
end

Instance Method Details

#<<(val) ⇒ Object



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

def <<(val)
  @myarray << val
end

#eachObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resultiterator.rb', line 21

def each
  original_length = @myarray.length - 1
  @myarray.each_with_index do |val,index|
    if index >= original_length and self.meta and self.meta.pagination.more
      resp = self.getUrl(self.meta.pagination.next).body
      nextResponse = JSON.parse(resp, object_class: OpenStruct)
      p nextResponse if ENV["debug_wonde"]
      self.meta  = nextResponse.meta unless nextResponse.meta.nil?
      nextResponse.data.each do |element|
        @myarray.push(element)
      end
      original_length += nextResponse.data.count
    end
    yield val
  end
end

#lengthObject



17
18
19
# File 'lib/resultiterator.rb', line 17

def length
  return self.count()
end