google_plus 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -56,12 +56,12 @@ And once you have an activity, you can move back to its person using `#person`.
56
56
 
57
57
  ### People do Things
58
58
 
59
- Lastly, you can get a list of activities for a person, which is returned as a `GooglePlus::Cursor`. You use it like:
59
+ Lastly, you can get a list of activities for a person, which is returned as a `GooglePlus::Cursor`. You use it like (which auto-paginates):
60
60
 
61
61
  person = GooglePlus::Person.new(123)
62
62
  cursor = person.list_activities
63
- while cursor.next_page
64
- cursor.items.count # a batch of activities
63
+ cursor.each do |item|
64
+ item # an item
65
65
  end
66
66
 
67
67
  Or if you just want one page, you can have it:
@@ -74,7 +74,7 @@ You can also set the cursor size at any time using any of these variations:
74
74
  # on the cursor
75
75
  cursor = person.activities_list(:max_results => 10)
76
76
  # or on the page
77
- cursor.next_page(:max_results => 5)
77
+ items = cursor.next_page(:max_results => 5)
78
78
 
79
79
  ### Plusoners and Resharers
80
80
 
@@ -92,8 +92,8 @@ Getting comments for an activity is done just like getting activities for a pers
92
92
 
93
93
  activity = GooglePlus::Activity.get(123)
94
94
  cursor = activity.list_comments
95
- while cursor.next_page
96
- cursor.items.count # a bunch of comments
95
+ cursor.each do |item|
96
+ # a comment
97
97
  end
98
98
 
99
99
  ## Searching
@@ -101,10 +101,8 @@ Getting comments for an activity is done just like getting activities for a pers
101
101
  You can search for [people](https://developers.google.com/+/api/latest/people/search) or [activities](https://developers.google.com/+/api/latest/activities/search) using the respective `search` methods, which also yield `GooglePlus::Cursor` objects. Here's an example:
102
102
 
103
103
  search = GooglePlus::Person.search('john crepezzi')
104
- while search.next_page
105
- search.each do |p|
106
- puts p.display_name
107
- end
104
+ search.each do |p|
105
+ puts p.display_name
108
106
  end
109
107
 
110
108
  ## Setting options
data/lib/google_plus.rb CHANGED
@@ -1,13 +1,18 @@
1
- require 'bundler/setup'
2
- require File.dirname(__FILE__) + '/google_plus/resource'
3
- require File.dirname(__FILE__) + '/google_plus/cursor'
1
+ require 'restclient'
2
+ require 'json'
4
3
 
5
4
  # GooglePlus is a ruby library for accessing the Google Plus API
6
5
  module GooglePlus
7
6
 
8
- autoload :Activity, File.dirname(__FILE__) + '/google_plus/activity'
9
- autoload :Comment, File.dirname(__FILE__) + '/google_plus/comment'
10
- autoload :Person, File.dirname(__FILE__) + '/google_plus/person'
7
+ autoload :Activity, 'google_plus/activity'
8
+ autoload :Comment, 'google_plus/comment'
9
+ autoload :Cursor, 'google_plus/cursor'
10
+ autoload :Entity, 'google_plus/entity'
11
+ autoload :Person, 'google_plus/person'
12
+ autoload :Resource, 'google_plus/resource'
13
+
14
+ autoload :ConnectionError, 'google_plus/errors/connection_error'
15
+ autoload :RequestError, 'google_plus/errors/request_error'
11
16
 
12
17
  class << self
13
18
  attr_accessor :api_key, :access_token
@@ -1,6 +1,3 @@
1
- require 'json'
2
- require File.dirname(__FILE__) + '/entity'
3
-
4
1
  module GooglePlus
5
2
 
6
3
  # An Acitity in Google Plus
@@ -1,6 +1,3 @@
1
- require 'json'
2
- require File.dirname(__FILE__) + '/entity'
3
-
4
1
  module GooglePlus
5
2
 
6
3
  # A Comment in Google Plus
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module GooglePlus
4
2
 
5
3
  # A class for easily paginating through lists of Google Plus
@@ -8,6 +6,19 @@ module GooglePlus
8
6
 
9
7
  extend GooglePlus::Resource
10
8
 
9
+ # Go through each item
10
+ # @yieldparam [GooglePlus::Entity] an individual item
11
+ # @yieldreturn [GooglePlus::Cursor] self
12
+ def each
13
+ while items = next_page
14
+ break if items.empty?
15
+ items.each do |item|
16
+ yield item
17
+ end
18
+ end
19
+ self
20
+ end
21
+
11
22
  # Get the current page of results
12
23
  # @return [Array] the current page of results, or nil if the page is blank
13
24
  def items(params = {})
@@ -53,7 +64,8 @@ module GooglePlus
53
64
  data = JSON::parse(json)
54
65
  @next_page_token = data['nextPageToken']
55
66
  if items = data['items']
56
- return data['items'].map { |d| @resource_klass.send(:new, d) }
67
+ return nil if items.empty?
68
+ return items.map { |d| @resource_klass.send(:new, d) }
57
69
  end
58
70
  end
59
71
  end
@@ -1,6 +1,3 @@
1
- require 'json'
2
- require File.dirname(__FILE__) + '/../entity'
3
-
4
1
  module GooglePlus
5
2
 
6
3
  # An error class for wrapping errors made during requests, and making its attributes
@@ -1,6 +1,3 @@
1
- require 'json'
2
- require File.dirname(__FILE__) + '/entity'
3
-
4
1
  module GooglePlus
5
2
 
6
3
  # A Person in Google Plus
@@ -1,7 +1,3 @@
1
- require 'restclient'
2
- require File.dirname(__FILE__) + '/errors/request_error'
3
- require File.dirname(__FILE__) + '/errors/connection_error'
4
-
5
1
  module GooglePlus
6
2
 
7
3
  # A modular extension for classes that make requests to the
@@ -1,6 +1,6 @@
1
1
  module GooglePlus
2
2
 
3
3
  # The current version of the library
4
- VERSION = '0.1.4'
4
+ VERSION = '0.2.0'
5
5
 
6
6
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/../lib/google_plus'
1
+ require 'bundler/setup'
2
+ require 'google_plus'
2
3
 
3
4
  unless TEST_API_KEY = ENV['API_KEY']
4
5
  puts 'please provide an API_KEY environment variable'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-12 00:00:00.000000000Z
12
+ date: 2012-01-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70353324637400 !ruby/object:Gem::Requirement
16
+ requirement: &70322067896220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70353324637400
24
+ version_requirements: *70322067896220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70353324636220 !ruby/object:Gem::Requirement
27
+ requirement: &70322067895680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70353324636220
35
+ version_requirements: *70322067895680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70353324635840 !ruby/object:Gem::Requirement
38
+ requirement: &70322067895300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70353324635840
46
+ version_requirements: *70322067895300
47
47
  description: Google+ Ruby Gem
48
48
  email: john.crepezzi@gmail.com
49
49
  executables: []
@@ -74,12 +74,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  - - ! '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
+ segments:
78
+ - 0
79
+ hash: -526203007372864254
77
80
  required_rubygems_version: !ruby/object:Gem::Requirement
78
81
  none: false
79
82
  requirements:
80
83
  - - ! '>='
81
84
  - !ruby/object:Gem::Version
82
85
  version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -526203007372864254
83
89
  requirements: []
84
90
  rubyforge_project: google_plus
85
91
  rubygems_version: 1.8.10