Class: Sonar::Request::RequestIterator

Inherits:
Object
  • Object
show all
Includes:
Sonar::Request
Defined in:
lib/sonar/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sonar::Request

#extract_params, #get, #post, #put, #request

Constructor Details

#initialize(url, connection, params = {}) ⇒ RequestIterator

Returns a new instance of RequestIterator


43
44
45
46
47
# File 'lib/sonar/request.rb', line 43

def initialize(url, connection, params = {})
  self.url = url
  self.connection = connection
  self.params = params
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection


41
42
43
# File 'lib/sonar/request.rb', line 41

def connection
  @connection
end

#paramsObject

Returns the value of attribute params


41
42
43
# File 'lib/sonar/request.rb', line 41

def params
  @params
end

#urlObject

Returns the value of attribute url


41
42
43
# File 'lib/sonar/request.rb', line 41

def url
  @url
end

Instance Method Details

#eachObject


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sonar/request.rb', line 49

def each
  more = true
  records_rcvd = 0
  while more && records_rcvd < params[:limit]
    # TODO: refactor to not pass around the connection
    params[:connection] = connection
    resp = get(url, params)
    params[:iterator_id] = resp.iterator_id
    records_rcvd += resp['collection'].size
    more = resp['more']
    yield resp
  end
end