grizzly-weibo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -9,7 +9,7 @@ Grizzly as a name was already taken on ruby gems. Awww. However grizzly-weibo wa
9
9
  add the following to your gem file.
10
10
 
11
11
  ```ruby
12
- gem "grizzly-weibo"
12
+ gem "grizzly-weibo", :require => "grizzly"
13
13
  ```
14
14
 
15
15
  ### Usage
@@ -94,3 +94,12 @@ while friends.next_page? #Loops untill end of collection
94
94
  end
95
95
  end
96
96
  ```
97
+
98
+ ### License
99
+ Copyright (c) 2012 Stewart Matheson
100
+
101
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
102
+
103
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
104
+
105
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -5,24 +5,36 @@ module Grizzly
5
5
 
6
6
  def initialize(domain_object, url, options, items_per_page = ITEMS_PER_PAGE)
7
7
  @domain_object, @url, @options, @items_per_page = domain_object, url, options, items_per_page
8
- @current_page = 1
9
- fetch_current_page
8
+ @current_page = 0
9
+ @fetched_current_page = false
10
10
  end
11
11
 
12
12
  #Each will return the first page of results
13
13
  def each(&block)
14
+ fetch_current_page if !@fetched_current_page
14
15
  @items.each { |i| block.call i }
15
16
  end
16
17
 
17
18
  #Next page will return the result set
18
19
  def next_page(&block)
20
+ fetch_current_page if !@fetched_current_page
19
21
  @items.each { |i| block.call i }
20
- @current_page += 1
21
- fetch_current_page
22
+ @fetched_current_page = false
22
23
  end
23
24
 
24
25
  def next_page?
25
- (@current_page * @items_per_page) < @total_items
26
+ total_item_count = total_items
27
+ (@current_page * @items_per_page) < total_item_count
28
+ end
29
+
30
+ def total_items
31
+ fetch_current_page if @total_items.nil?
32
+ @total_items
33
+ end
34
+
35
+ def [](index)
36
+ fetch_current_page if !@fetched_current_page
37
+ @items[index]
26
38
  end
27
39
 
28
40
  private
@@ -33,6 +45,7 @@ module Grizzly
33
45
  end
34
46
 
35
47
  def fetch_current_page
48
+ @current_page += 1
36
49
  options = @options.merge({ :page => @current_page, :count => @items_per_page })
37
50
  response = page_request(@url, options)
38
51
  @total_items = response["total_number"]
@@ -41,6 +54,7 @@ module Grizzly
41
54
  response[@domain_object::API_COLLECTION_NAME].each do |domain_object|
42
55
  @items << @domain_object.new(domain_object)
43
56
  end
57
+ @fetched_current_page = true
44
58
  end
45
59
 
46
60
  end
@@ -1,3 +1,3 @@
1
1
  module Grizzly
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grizzly-weibo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000Z
12
+ date: 2012-04-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 891757663377480348
128
+ hash: -3374283458900658404
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements: