google_plus 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +118 -0
- data/lib/google_plus.rb +4 -3
- data/lib/google_plus/activity.rb +39 -10
- data/lib/google_plus/comment.rb +15 -0
- data/lib/google_plus/cursor.rb +1 -1
- data/lib/google_plus/errors/connection_error.rb +4 -0
- data/lib/google_plus/person.rb +17 -1
- data/lib/google_plus/version.rb +1 -1
- metadata +8 -9
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# GooglePlus
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/seejohnrun/google_plus.png)](http://travis-ci.org/seejohnrun/google_plus)
|
4
|
+
|
5
|
+
This is a Ruby client library for the [Google+ API](http://developers.google.com/+/api/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install google_plus
|
10
|
+
|
11
|
+
## Authentication
|
12
|
+
|
13
|
+
To make calls to the Google+ API, you have to either authenticate via [OAuth](http://oauth.net/) or provide an API key (which you can get from the Google [APIs Console](https://code.google.com/apis/console#access). To set your API key and get started, use:
|
14
|
+
|
15
|
+
GooglePlus.api_key = 'your key'
|
16
|
+
|
17
|
+
That key will then be used on all of your requests.
|
18
|
+
|
19
|
+
If you want to change it for an individual request, you can use a param, like:
|
20
|
+
|
21
|
+
person = GooglePlus::Person.get(123, :key => 'other_key')
|
22
|
+
|
23
|
+
## People
|
24
|
+
|
25
|
+
Getting information about a person is easy, given that you have their Google+ ID:
|
26
|
+
|
27
|
+
person = GooglePlus::Person.get(123)
|
28
|
+
|
29
|
+
Accessing attributes of a `GooglePlus::Person` object is straightforward, and to keep things nice, all attributes are converted to snake case (so `person.displayName` becomes `person.display_name`).
|
30
|
+
|
31
|
+
person = GooglePlus::Person.get(123)
|
32
|
+
person.display_name
|
33
|
+
person.photos.each do |photo|
|
34
|
+
photo.value
|
35
|
+
end
|
36
|
+
|
37
|
+
You can read more about the fields available for a `Person` in the [Person documentation](http://developers.google.com/+/api/latest/people), or you can use the `attributes` method to get them back as a Hash.
|
38
|
+
|
39
|
+
## Activities
|
40
|
+
|
41
|
+
Exactly the same as people, you can get activities by ID:
|
42
|
+
|
43
|
+
activity = GooglePlus::Activity.get(123)
|
44
|
+
|
45
|
+
And once you have an activity, you can move back to its person using `#person`.
|
46
|
+
|
47
|
+
### People do Things
|
48
|
+
|
49
|
+
Lastly, you can get a list of activities for a person, which is returned as a `GooglePlus::Cursor`. You use it like:
|
50
|
+
|
51
|
+
person = GooglePlus::Person.new(123)
|
52
|
+
cursor = person.list_activities
|
53
|
+
while cursor.next_page
|
54
|
+
cursor.items.count # a batch of activities
|
55
|
+
end
|
56
|
+
|
57
|
+
Or if you just want one page, you can have it:
|
58
|
+
|
59
|
+
person = GooglePlus::Person.new(123)
|
60
|
+
activites = person.activities_list.items
|
61
|
+
|
62
|
+
You can also set the cursor size at any time using any of these variations:
|
63
|
+
|
64
|
+
# on the cursor
|
65
|
+
cursor = person.activities_list(:max_results => 10)
|
66
|
+
# or on the page
|
67
|
+
cursor.next_page(:max_results => 5)
|
68
|
+
|
69
|
+
### Plusoners and Resharers
|
70
|
+
|
71
|
+
You can call `plusoners` and `resharers` on a `GooglePlus::Activity` to get a cursor or people that plus one'd or reshared an activity.
|
72
|
+
|
73
|
+
## Comments
|
74
|
+
|
75
|
+
You can get comments for an acitivty, using its ID:
|
76
|
+
|
77
|
+
comment = GooglePlus::Comment.get(123)
|
78
|
+
|
79
|
+
Accessing attributes of a `GooglePlus::Comment` object is straightforward, (see: accessing attributes of a `GooglePlus::Person`). You can find the fields available in the [Comment documentation](https://developers.google.com/+/api/latest/comments/list).
|
80
|
+
|
81
|
+
Getting comments for an activity is done just like getting activities for a person:
|
82
|
+
|
83
|
+
activity = GooglePlus::Activity.get(123)
|
84
|
+
cursor = activity.list_comments
|
85
|
+
while cursor.next_page
|
86
|
+
cursor.items.count # a bunch of comments
|
87
|
+
end
|
88
|
+
|
89
|
+
## Searching
|
90
|
+
|
91
|
+
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:
|
92
|
+
|
93
|
+
search = GooglePlus::Person.search('john crepezzi')
|
94
|
+
while search.next_page
|
95
|
+
search.each do |p|
|
96
|
+
puts p.display_name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
## Setting options
|
101
|
+
|
102
|
+
On any of these calls, you can provide options like `user_ip` listed on [the docs](http://developers.google.com/+/api/).
|
103
|
+
|
104
|
+
## Dependencies
|
105
|
+
|
106
|
+
* rest_client
|
107
|
+
|
108
|
+
## License
|
109
|
+
|
110
|
+
(The MIT License)
|
111
|
+
|
112
|
+
Copyright © 2011 John Crepezzi
|
113
|
+
|
114
|
+
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:
|
115
|
+
|
116
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
117
|
+
|
118
|
+
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.
|
data/lib/google_plus.rb
CHANGED
@@ -2,6 +2,7 @@ require 'bundler/setup'
|
|
2
2
|
require File.dirname(__FILE__) + '/google_plus/resource'
|
3
3
|
require File.dirname(__FILE__) + '/google_plus/cursor'
|
4
4
|
|
5
|
+
# GooglePlus is a ruby library for accessing the
|
5
6
|
module GooglePlus
|
6
7
|
|
7
8
|
autoload :Activity, File.dirname(__FILE__) + '/google_plus/activity'
|
@@ -12,9 +13,9 @@ module GooglePlus
|
|
12
13
|
attr_accessor :api_key, :access_token
|
13
14
|
end
|
14
15
|
|
15
|
-
# Return whether or not
|
16
|
-
# For historic purposes - since this client existed before there
|
17
|
-
#
|
16
|
+
# Return whether or not there is a Google+ API
|
17
|
+
# For historic purposes - since this client existed before there was a GooglePlus API
|
18
|
+
# @return [Boolean] whether or not there is an API
|
18
19
|
def self.has_api?
|
19
20
|
true
|
20
21
|
end
|
data/lib/google_plus/activity.rb
CHANGED
@@ -8,11 +8,23 @@ module GooglePlus
|
|
8
8
|
extend GooglePlus::Resource
|
9
9
|
include GooglePlus::Entity
|
10
10
|
|
11
|
+
# Get an activity by ID
|
12
|
+
# @param [String] activity_id The id of the activity to look up
|
13
|
+
# @option params [Symbol] :key A different API key to use for this request
|
14
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
15
|
+
# @return [GooglePlus::Activity] an activity object for the activity, if it
|
16
|
+
# is found - otherwise, return nil
|
11
17
|
def self.get(activity_id, params = {})
|
12
18
|
data = make_request(:get, "activities/#{activity_id}", params)
|
13
19
|
Activity.new(JSON.parse(data)) if data
|
14
20
|
end
|
15
21
|
|
22
|
+
# Search for an activity
|
23
|
+
# @param [String] query The query string to search for
|
24
|
+
# @option params [Symbol] :key A different API key to use for this request
|
25
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
26
|
+
# @return [GooglePlus::Cursor] a cursor that will paginate through the results
|
27
|
+
# for the activity search
|
16
28
|
def self.search(query, params = {})
|
17
29
|
params[:query] = URI.escape(query)
|
18
30
|
params[:orderBy] = params.delete(:order_by) if params.has_key?(:order_by)
|
@@ -20,39 +32,56 @@ module GooglePlus
|
|
20
32
|
GooglePlus::Cursor.new(self, :get, resource, params)
|
21
33
|
end
|
22
34
|
|
23
|
-
|
35
|
+
# Get a list of activities from this person
|
36
|
+
# @param [String] user_id The ID of the user to look up activities for
|
37
|
+
# @option params [Symbol] :collection What collection to pull activities for
|
38
|
+
# defaults to :public
|
39
|
+
# @option params [Symbol] :key A different API key to use for this request
|
40
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
41
|
+
# @return [GooglePlus::Cursor] a cursor that will paginate through the results
|
42
|
+
# for the activity list
|
43
|
+
def self.for_person(user_id, params = {})
|
24
44
|
collection = params[:collection] || :public
|
25
45
|
resource = "people/#{user_id}/activities/#{collection}"
|
26
46
|
GooglePlus::Cursor.new(self, :get, resource, params)
|
27
47
|
end
|
28
48
|
|
29
|
-
#
|
49
|
+
# Get the list of comments for an activity
|
50
|
+
# @return [GooglePlus::Cursor] a cursor for paginating through the comments on this activity
|
30
51
|
def list_comments
|
31
52
|
GooglePlus::Comment.for_activity(id)
|
32
53
|
end
|
33
54
|
|
34
55
|
# get the actor of this activity
|
56
|
+
# @return [GooglePlus::Person] the actor for this activity
|
35
57
|
def person
|
36
58
|
@person ||= GooglePlus::Person.get(actor.id)
|
37
59
|
end
|
38
60
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
61
|
+
# List the people of a certain type of action on this activity
|
62
|
+
# @param [Symbol] collection The collection to look up (ie: :plusoners, :resharers)
|
63
|
+
# @return [GooglePlus::Cursor] a cursor for the list of people associated with this activity
|
64
|
+
def list_people(collection)
|
42
65
|
resource = "activities/#{id}/people/#{collection}"
|
43
|
-
GooglePlus::Cursor.new(GooglePlus::Person, :get, resource
|
66
|
+
GooglePlus::Cursor.new(GooglePlus::Person, :get, resource)
|
44
67
|
end
|
45
68
|
|
46
|
-
#
|
47
|
-
|
69
|
+
# List the people that plusone'd this activity
|
70
|
+
# @return [GooglePlus::Cursor] a cursor for the list of people that plusone'd this activity
|
71
|
+
def plusoners
|
48
72
|
list_people(:plusoners)
|
49
73
|
end
|
50
74
|
|
51
|
-
#
|
52
|
-
|
75
|
+
# List the people that reshared this activity
|
76
|
+
# @return [GooglePlus::Cursor] a cursor for the list of people that reshared this activity
|
77
|
+
def resharers
|
53
78
|
list_people(:resharers)
|
54
79
|
end
|
55
80
|
|
81
|
+
# Load a new instance from an attributes hash
|
82
|
+
# Useful if you have the underlying response data for an object - Generally, what you
|
83
|
+
# want is #get though
|
84
|
+
# @return [GooglePlus::Activity] An activity constructed from the attributes hash
|
56
85
|
def initialize(hash)
|
57
86
|
load_hash(hash)
|
58
87
|
end
|
data/lib/google_plus/comment.rb
CHANGED
@@ -8,16 +8,31 @@ module GooglePlus
|
|
8
8
|
extend GooglePlus::Resource
|
9
9
|
include GooglePlus::Entity
|
10
10
|
|
11
|
+
# Get a comment by id
|
12
|
+
# @param [String] comment_id The id of the comment to look up
|
13
|
+
# @option params [Symbol] :key A different API key to use for this request
|
14
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
15
|
+
# @return [GooglePlus::Comment] a comment object representing the comment we're looking up,
|
16
|
+
# if it is found - otherwise, return nil
|
11
17
|
def self.get(comment_id, params = {})
|
12
18
|
data = make_request(:get, "comments/#{comment_id}", params)
|
13
19
|
Comment.new(JSON.parse(data)) if data
|
14
20
|
end
|
15
21
|
|
22
|
+
# Get a cursor of comments for an activity
|
23
|
+
# @param [String] activity_id The id of the activity to look up comments for
|
24
|
+
# @option params [Symbol] :key A different API key to use for this request
|
25
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
26
|
+
# @return [GooglePlus::Cursor] a cursor for listing the comments for this activity
|
16
27
|
def self.for_activity(activity_id, params = {})
|
17
28
|
resource = "activities/#{activity_id}/comments"
|
18
29
|
GooglePlus::Cursor.new(self, :get, resource, params)
|
19
30
|
end
|
20
31
|
|
32
|
+
# Load a new instance from an attributes hash.
|
33
|
+
# Useful if you have the underlying response data for an object - Generally, what you
|
34
|
+
# want is #get though
|
35
|
+
# @return [GooglePlus::Comment] A comment constructed from the attributes hash
|
21
36
|
def initialize(hash)
|
22
37
|
load_hash(hash)
|
23
38
|
end
|
data/lib/google_plus/cursor.rb
CHANGED
@@ -2,10 +2,14 @@ module GooglePlus
|
|
2
2
|
|
3
3
|
class ConnectionError < Exception
|
4
4
|
|
5
|
+
# Initialize a new ConnectionError
|
6
|
+
# @param [Exception] e The exception that occurred
|
5
7
|
def initialize(e)
|
6
8
|
@exception = e
|
7
9
|
end
|
8
10
|
|
11
|
+
# Get the message for this error
|
12
|
+
# @return [String] a message representing this error
|
9
13
|
def message
|
10
14
|
@exception.message
|
11
15
|
end
|
data/lib/google_plus/person.rb
CHANGED
@@ -8,22 +8,38 @@ module GooglePlus
|
|
8
8
|
extend GooglePlus::Resource
|
9
9
|
include GooglePlus::Entity
|
10
10
|
|
11
|
+
# Get a person by id
|
12
|
+
# @param [String] user_id the id of the user to look up
|
13
|
+
# @option params [Symbol] :key A different API key to use for this request
|
14
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
15
|
+
# @return [GooglePlus::Person] a person object representing the person we're looking up,
|
16
|
+
# if it is found - otherwise, return nil
|
11
17
|
def self.get(user_id, params = {})
|
12
18
|
data = make_request(:get, "people/#{user_id}", params)
|
13
19
|
Person.new(JSON.parse(data)) if data
|
14
20
|
end
|
15
21
|
|
22
|
+
# Search for a person
|
23
|
+
# @param [String] query The query string to search for
|
24
|
+
# @option params [Symbol] :key A different API key to use for this request
|
25
|
+
# @option params [Symbol] :user_ip The IP of the user on who's behalf this request is made
|
26
|
+
# @return [GooglePlus::Cursor] a cursor for the people found in the search
|
16
27
|
def self.search(query, params = {})
|
17
28
|
params[:query] = URI.escape(query)
|
18
29
|
resource = 'people'
|
19
30
|
GooglePlus::Cursor.new(self, :get, resource, params)
|
20
31
|
end
|
21
32
|
|
22
|
-
#
|
33
|
+
# List the activities for this person
|
34
|
+
# @return [GooglePlus::Cursor] a cursor of activities for this person
|
23
35
|
def list_activities
|
24
36
|
GooglePlus::Activity.for_person(id)
|
25
37
|
end
|
26
38
|
|
39
|
+
# Load a new instance from an attributes hash
|
40
|
+
# Useful if you have the underlying response data for an object - Generally, what you
|
41
|
+
# want is #get though
|
42
|
+
# @return [GooglePlus::Person] A person constructed from the attributes hash
|
27
43
|
def initialize(hash)
|
28
44
|
load_hash(hash)
|
29
45
|
end
|
data/lib/google_plus/version.rb
CHANGED
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
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-10-06 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
|
-
requirement: &
|
16
|
+
requirement: &70229192765580 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ~>
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: 2.6.0
|
23
22
|
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70229192765580
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: rest-client
|
28
|
-
requirement: &
|
27
|
+
requirement: &70229192765020 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ~>
|
@@ -33,7 +32,7 @@ dependencies:
|
|
33
32
|
version: 1.6.1
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *70229192765020
|
37
36
|
description: Google+ Ruby Gem
|
38
37
|
email: john.crepezzi@gmail.com
|
39
38
|
executables: []
|
@@ -50,8 +49,8 @@ files:
|
|
50
49
|
- lib/google_plus/resource.rb
|
51
50
|
- lib/google_plus/version.rb
|
52
51
|
- lib/google_plus.rb
|
52
|
+
- README.md
|
53
53
|
- spec/spec_helper.rb
|
54
|
-
has_rdoc: true
|
55
54
|
homepage: http://github.com/seejohnrun/google_plus
|
56
55
|
licenses: []
|
57
56
|
post_install_message:
|
@@ -72,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
71
|
version: '0'
|
73
72
|
requirements: []
|
74
73
|
rubyforge_project: google_plus
|
75
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.8.10
|
76
75
|
signing_key:
|
77
76
|
specification_version: 3
|
78
77
|
summary: Ruby Gem for the Google+ API
|