gplus 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,9 +6,7 @@ GPlus is a complete implementation of the Google+ API, with help from OAuth2 and
6
6
 
7
7
  I'm aiming to produce something light-weight, well documented, and thoroughly tested.
8
8
 
9
- It currently has full support for People and Activities, and for authorized requests.
10
-
11
- Unauthorized requests for public resources is coming in version 0.3.0 (aiming for 2011/09/17)
9
+ It currently has full support for the People and Activities APIs, using either OAuth requests for private data or API key requests for public data.
12
10
 
13
11
  ## Installation
14
12
 
@@ -24,16 +22,24 @@ Next, [create an OAuth 2.0 client ID](http://code.google.com/apis/console#access
24
22
 
25
23
  You can then specify additional redirect URIs and allowed javascript origins.
26
24
 
27
- You'll need the Client ID and Client secret that are generated. Keep them secure!
25
+ ## Unauthorized requests (for public data)
26
+
27
+ Create an API client using your API key:
28
+
29
+ @client = Gplus::Client.new(
30
+ :api_key => 'YOUR_API_KEY'
31
+ )
32
+
33
+ You can now make requests for public data using the methods below for People and Activities.
28
34
 
29
35
  ## Authorized requests
30
36
 
31
- Create an instance of the client using the credentials from when you set up your application:
37
+ First, create an API client using your Client ID, Client Secret, and one of the redirect URIs you have allowed:
32
38
 
33
39
  @client = Gplus::Client.new(
34
40
  :client_id => 'YOUR_CLIENT_ID',
35
41
  :client_secret => 'YOUR_CLIENT_SECRET',
36
- :redirect_uri => 'http://example.com/oauth2callback'
42
+ :redirect_uri => 'http://example.com/oauth/callback'
37
43
  )
38
44
 
39
45
  Generate an authorization URL, and use it in a view:
@@ -45,14 +51,22 @@ Generate an authorization URL, and use it in a view:
45
51
 
46
52
  After the user authorizes your app, they will be redirected to your `redirect_uri`. Store `params[:code]`:
47
53
 
48
- def oauth_callback_handler
49
- current_user.update_attributes(:oauth_code => params[:code])
54
+ class OauthController < ApplicationController
55
+ def callback
56
+ current_user.update_attributes(:oauth_code => params[:code])
57
+ end
50
58
  end
51
59
 
52
60
  Finally, create an authorized client instance:
53
61
 
54
62
  client.authorize(current_user.oauth_code)
55
63
 
64
+ If you have an OAuth code stored, you can use it to initialize your API client:
65
+
66
+ @client = Gplus::Client.new(
67
+ :token => current_user.oauth_code,
68
+ )
69
+
56
70
  ## [People](http://developers.google.com/+/api/latest/people)
57
71
 
58
72
  Get a person's profile with `client.get_person`:
@@ -83,7 +97,7 @@ The activity will be returned as a nested hash:
83
97
 
84
98
  List a person's activities with `client.list_activities`:
85
99
 
86
- activities = client.list_activities(id)
100
+ activities = client.list_activities(person_id)
87
101
 
88
102
  The list will be returned as a nested hash. The actual activities are in the `:items` array:
89
103
 
@@ -5,7 +5,7 @@ module Gplus
5
5
  end
6
6
 
7
7
  def list_activities(person_id, results = 20, page = nil)
8
- get("people/#{person_id}/activities/public?maxResults=#{results}&pageToken=#{page}")
8
+ get("people/#{person_id}/activities/public", { :maxResults => results, :pageToken => page })
9
9
  end
10
10
  end
11
11
  end
data/lib/gplus/client.rb CHANGED
@@ -4,6 +4,7 @@ require 'gplus/person'
4
4
  module Gplus
5
5
  class Client
6
6
  def initialize(options = {})
7
+ @api_key = options[:api_key]
7
8
  @client_id = options[:client_id]
8
9
  @client_secret = options[:client_secret]
9
10
  @redirect_uri = options[:redirect_uri]
@@ -28,11 +29,17 @@ module Gplus
28
29
 
29
30
  private
30
31
  def access_token
31
- @access_token ||= OAuth2::AccessToken.new(@oauth_client, @token)
32
+ if @token
33
+ @access_token ||= OAuth2::AccessToken.new(@oauth_client, @token)
34
+ end
32
35
  end
33
36
 
34
- def get(path)
35
- response = access_token.get("v1/#{path}")
37
+ def get(path, params = {})
38
+ if access_token
39
+ response = access_token.get("v1/#{path}", params)
40
+ else
41
+ response = @oauth_client.request(:get, "v1/#{path}", { :params => params.merge(:key => @api_key) })
42
+ end
36
43
  MultiJson.decode(response.body)
37
44
  end
38
45
  end
data/lib/gplus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gplus
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.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-09-16 00:00:00.000000000Z
12
+ date: 2011-09-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &24698140 !ruby/object:Gem::Requirement
16
+ requirement: &17792180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24698140
24
+ version_requirements: *17792180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth2
27
- requirement: &24693860 !ruby/object:Gem::Requirement
27
+ requirement: &17784300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24693860
35
+ version_requirements: *17784300
36
36
  description: A complete implementation of the Google plus API for Ruby
37
37
  email:
38
38
  - nicholas@2suggestions.com.au