Class: GooglePlus::Cursor
- Inherits:
-
Object
- Object
- GooglePlus::Cursor
- Extended by:
- Resource
- Defined in:
- lib/google_plus/cursor.rb
Overview
A class for easily paginating through lists of Google Plus results. Automatically handles details like nextPageToken
Constant Summary
Constants included from Resource
Instance Method Summary collapse
-
#each {|an| ... } ⇒ Object
Go through each item.
-
#initialize(klass, method, resource, params = {}) ⇒ Cursor
constructor
Create a new cursor.
-
#items(params = {}) ⇒ Array
Get the current page of results.
-
#next_page(params = {}) ⇒ Array
Load the next page of results and load it as the current page.
Methods included from Resource
Constructor Details
#initialize(klass, method, resource, params = {}) ⇒ Cursor
Create a new cursor
44 45 46 47 48 49 50 |
# File 'lib/google_plus/cursor.rb', line 44 def initialize(klass, method, resource, params = {}) @first_page_loaded = false @resource_klass = klass @method = method @resource = resource @base_params = params end |
Instance Method Details
#each {|an| ... } ⇒ Object
Go through each item
12 13 14 15 16 17 18 19 20 |
# File 'lib/google_plus/cursor.rb', line 12 def each while items = next_page break if items.empty? items.each do |item| yield item end end self end |
#items(params = {}) ⇒ Array
Get the current page of results
24 25 26 27 28 29 30 31 |
# File 'lib/google_plus/cursor.rb', line 24 def items(params = {}) if instance_variable_defined?(:@items) # TODO raise error if params are passed here, since they're meaningless @items else @items = load_page(params) end end |
#next_page(params = {}) ⇒ Array
Load the next page of results and load it as the current page
35 36 37 |
# File 'lib/google_plus/cursor.rb', line 35 def next_page(params = {}) @items = load_page(params) end |