Permalink
Browse files

more complete handling of paging

  • Loading branch information...
1 parent 769c02a commit 9aa709b8628f7f02b223c8eec88b2557041757a4 @theganyo committed Jan 2, 2013
Showing with 22 additions and 10 deletions.
  1. +17 −6 lib/usergrid/core/collection.rb
  2. +1 −1 lib/usergrid/version.rb
  3. +4 −3 spec/usergrid/core/collection_spec.rb
@@ -3,7 +3,6 @@ class Collection < Entity
include Enumerable
attr_accessor :iterator_follows_cursor
- attr_reader :query_params
def initialize(url, api_url, options={}, response=nil)
super url, api_url, options, response
@@ -55,16 +54,16 @@ def create_entity(data)
# options: 'reversed', 'start', 'cursor', 'limit', 'permission'
def update_query(updates, query=nil, options={})
options = options.symbolize_keys
- @query_params = query ? options.merge({ql: query}) : options
- self.put(updates, {params: @query_params })
+ query_params = query ? options.merge({ql: query}) : options
+ self.put(updates, {params: query_params })
self
end
# options: 'reversed', 'start', 'cursor', 'limit', 'permission'
def query(query=nil, options={})
options = options.symbolize_keys
- @query_params = query ? options.merge({ql: query}) : options
- self.get({params: @query_params })
+ query_params = query ? options.merge({ql: query}) : options
+ self.get({params: query_params })
self
end
@@ -81,7 +80,19 @@ def cursor
end
def next_page
- query(nil, @query_params.merge({cursor: cursor}))
+ query(nil, query_params.merge({cursor: cursor}))
+ end
+
+ protected
+
+ def query_params
+ params = {}
+ if response.data['params']
+ response.data['params'].each do |k,v|
+ params[k] = v[0]
+ end
+ end
+ params
end
end
end
View
@@ -1,3 +1,3 @@
module Usergrid
- VERSION = '0.0.7'
+ VERSION = '0.0.8'
end
@@ -8,6 +8,7 @@
@entity_data = (1..25).collect do |i|
{ name: "name_#{i}", value: "value_#{i+1}" }
end
+ (1..3).each {|i| @entity_data[i]['three'] = 3}
@collection.create_entities @entity_data
end
@@ -63,10 +64,10 @@
end
it "should be able to page forward by cursor" do
- @collection.query nil, limit: 2
+ @collection.query 'select * where three = 3', limit: 2
@collection.next_page
- @collection.size.should eq 2
- @collection[0].name.should eq @entity_data[2][:name]
+ @collection.size.should eq 1
+ @collection[0].name.should eq @entity_data[3][:name]
end
it "should be able to update based on a query" do

0 comments on commit 9aa709b

Please sign in to comment.