google_plus 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +11 -1
- data/lib/google_plus.rb +1 -1
- data/lib/google_plus/activity.rb +1 -0
- data/lib/google_plus/comment.rb +1 -0
- data/lib/google_plus/cursor.rb +11 -0
- data/lib/google_plus/entity.rb +14 -0
- data/lib/google_plus/errors/connection_error.rb +1 -0
- data/lib/google_plus/errors/request_error.rb +5 -0
- data/lib/google_plus/person.rb +1 -0
- data/lib/google_plus/resource.rb +2 -0
- data/lib/google_plus/version.rb +2 -1
- metadata +17 -6
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GooglePlus
|
1
|
+
# [GooglePlus](http://rubygems.org/gems/google_plus)
|
2
2
|
|
3
3
|
[](http://travis-ci.org/seejohnrun/google_plus)
|
4
4
|
|
@@ -8,6 +8,8 @@ This is a Ruby client library for the [Google+ API](http://developers.google.com
|
|
8
8
|
|
9
9
|
gem install google_plus
|
10
10
|
|
11
|
+
## [Documentation](http://rdoc.info/gems/google_plus/file/README.md)
|
12
|
+
|
11
13
|
## Authentication
|
12
14
|
|
13
15
|
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:
|
@@ -20,6 +22,14 @@ If you want to change it for an individual request, you can use a param, like:
|
|
20
22
|
|
21
23
|
person = GooglePlus::Person.get(123, :key => 'other_key')
|
22
24
|
|
25
|
+
If you want to use [OAuth](http://oauth.net/) for authorization, you can use a method such as [OmniAuth](https://github.com/intridea/omniauth)'s [GoogleOAuth2 Strategy](http://rubydoc.info/gems/oa-oauth/0.3.0/OmniAuth/Strategies/GoogleOAuth2) to get an `access_token`, and then set it using:
|
26
|
+
|
27
|
+
GooglePlus.access_token = 'token'
|
28
|
+
|
29
|
+
If you want to set it for an individual request (or series of requests), you can use a param like above:
|
30
|
+
|
31
|
+
person = GooglePlus::Person.get(123, :access_token => 'token')
|
32
|
+
|
23
33
|
## People
|
24
34
|
|
25
35
|
Getting information about a person is easy, given that you have their Google+ ID:
|
data/lib/google_plus.rb
CHANGED
@@ -2,7 +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
|
+
# GooglePlus is a ruby library for accessing the Google Plus API
|
6
6
|
module GooglePlus
|
7
7
|
|
8
8
|
autoload :Activity, File.dirname(__FILE__) + '/google_plus/activity'
|
data/lib/google_plus/activity.rb
CHANGED
data/lib/google_plus/comment.rb
CHANGED
data/lib/google_plus/cursor.rb
CHANGED
@@ -2,10 +2,14 @@ require 'json'
|
|
2
2
|
|
3
3
|
module GooglePlus
|
4
4
|
|
5
|
+
# A class for easily paginating through lists of Google Plus
|
6
|
+
# results. Automatically handles details like nextPageToken
|
5
7
|
class Cursor
|
6
8
|
|
7
9
|
extend GooglePlus::Resource
|
8
10
|
|
11
|
+
# Get the current page of results
|
12
|
+
# @return [Array] the current page of results, or nil if the page is blank
|
9
13
|
def items(params = {})
|
10
14
|
if instance_variable_defined?(:@items)
|
11
15
|
# TODO raise error if params are passed here, since they're meaningless
|
@@ -15,10 +19,17 @@ module GooglePlus
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
22
|
+
# Load the next page of results and load it as the current page
|
23
|
+
# @return [Array] the next page of results, or nil if the page is blank
|
18
24
|
def next_page(params = {})
|
19
25
|
@items = load_page(params)
|
20
26
|
end
|
21
27
|
|
28
|
+
# Create a new cursor
|
29
|
+
# @param [Class] klass - The class type to instantiate members of this cursor as
|
30
|
+
# @param [Symbol] method - The HTTP method if this request
|
31
|
+
# @param [String] resource - The path of this request relative to the API
|
32
|
+
# @param [Hash] params - a set of parameters to be merged into the request
|
22
33
|
def initialize(klass, method, resource, params = {})
|
23
34
|
@first_page_loaded = false
|
24
35
|
@resource_klass = klass
|
data/lib/google_plus/entity.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
module GooglePlus
|
2
2
|
|
3
|
+
# A mixin that allows retrieval of nested attributes
|
3
4
|
module Entity
|
4
5
|
|
6
|
+
def self.included(base)
|
7
|
+
base.instance_eval do
|
8
|
+
undef_method :id if method_defined? :id
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Access an attribute of the Entity
|
5
13
|
def method_missing(method, *arguments, &block)
|
6
14
|
method_s = method.to_s
|
7
15
|
if @attributes.has_key?(method_s)
|
@@ -16,6 +24,7 @@ module GooglePlus
|
|
16
24
|
end
|
17
25
|
end
|
18
26
|
|
27
|
+
# Determine if an attribute is set on the Entity
|
19
28
|
def respond_to?(method, include_private = false)
|
20
29
|
method_s = method.to_s
|
21
30
|
if @attributes.has_key?(method_s)
|
@@ -25,10 +34,12 @@ module GooglePlus
|
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
37
|
+
# The raw accessible attributes
|
28
38
|
attr_reader :attributes
|
29
39
|
|
30
40
|
private
|
31
41
|
|
42
|
+
# Load the data from the hash into the Entity
|
32
43
|
def load_hash(hash)
|
33
44
|
# underscore all of the attributes
|
34
45
|
@attributes = hash
|
@@ -40,10 +51,13 @@ module GooglePlus
|
|
40
51
|
|
41
52
|
end
|
42
53
|
|
54
|
+
# A convenience class for wrapping nestings of Entity objects so that
|
55
|
+
# they can be traversed as deeply as desired
|
43
56
|
class EntityHash
|
44
57
|
|
45
58
|
include Entity
|
46
59
|
|
60
|
+
# Initialize a new EntityHash with the given data
|
47
61
|
def initialize(hash = {})
|
48
62
|
load_hash(hash)
|
49
63
|
end
|
@@ -3,10 +3,15 @@ require File.dirname(__FILE__) + '/../entity'
|
|
3
3
|
|
4
4
|
module GooglePlus
|
5
5
|
|
6
|
+
# An error class for wrapping errors made during requests, and making its attributes
|
7
|
+
# available similar to any [GooglePlus::Entity]
|
6
8
|
class RequestError < Exception
|
7
9
|
|
8
10
|
include GooglePlus::Entity
|
9
11
|
|
12
|
+
# Instantiate a new GooglePlus::RequestError and allow it to be accessed
|
13
|
+
# as an entity
|
14
|
+
# @param [Exception] e The original exception
|
10
15
|
def initialize(e)
|
11
16
|
load_hash JSON.parse(e.response.body)
|
12
17
|
end
|
data/lib/google_plus/person.rb
CHANGED
data/lib/google_plus/resource.rb
CHANGED
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.4
|
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
|
+
date: 2011-10-12 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70353324637400 !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: *
|
24
|
+
version_requirements: *70353324637400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70353324636220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 1.6.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70353324636220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: json
|
38
|
+
requirement: &70353324635840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70353324635840
|
36
47
|
description: Google+ Ruby Gem
|
37
48
|
email: john.crepezzi@gmail.com
|
38
49
|
executables: []
|