Class: Gplus::Client
- Inherits:
-
Object
- Object
- Gplus::Client
- Includes:
- Activity, Comment, Person
- Defined in:
- lib/gplus/client.rb
Overview
The main Gplus class, containing methods for initializing a Google+ client and requesting authorization
Constant Summary
- DEFAULT_ENDPOINT =
The default Google+ API endpoint that all requests are sent to.
'https://www.googleapis.com/plus'- DEFAULT_API_VERSION =
The default version of the Google+ API to send requests to.
'v1'
Instance Attribute Summary (collapse)
-
- (Object) api_version
Returns the value of attribute api_version.
-
- (Object) endpoint
Returns the value of attribute endpoint.
Instance Method Summary (collapse)
-
- (Object) access_token
Retrieve or create an OAuth2::AccessToken, using the :token and :refresh_token specified when the API client instance was initialized.
-
- (Boolean) access_token_refreshed?
Return true if the user's access token has been refreshed.
-
- (Object) authorize(token, refresh_token, token_expires_at)
Authorize a Gplus::Client instance to access the user's private data, after initialization.
-
- (String) authorize_url(options = {})
Generate an authorization URL where a user can authorize your application to access their Google+ data.
-
- (OAuth2::AccessToken) get_token(auth_code, params = {}, opts = {})
Retrieve an OAuth access token using the short-lived authentication code given to you after a user authorizes your application.
-
- (Gplus::Client) initialize(options = {})
constructor
Create a Google+ API client.
Methods included from Person
#get_person, #list_people_by_activity, #search_people
Methods included from Comment
Methods included from Activity
#get_activity, #list_activities, #search_activities
Constructor Details
- (Gplus::Client) initialize(options = {})
Create a Google+ API client. Read the README to find learn about the different ways of initializing a client.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gplus/client.rb', line 26 def initialize( = {}) self.endpoint = DEFAULT_ENDPOINT self.api_version = DEFAULT_API_VERSION @api_key = [:api_key] @token = [:token] @refresh_token = [:refresh_token] @token_expires_at = [:token_expires_at] @client_id = [:client_id] @client_secret = [:client_secret] @redirect_uri = [:redirect_uri] @oauth_client = OAuth2::Client.new( @client_id, @client_secret, :site => self.endpoint, :authorize_url => 'https://accounts.google.com/o/oauth2/auth', :token_url => 'https://accounts.google.com/o/oauth2/token' ) end |
Instance Attribute Details
- (Object) api_version
Returns the value of attribute api_version
13 14 15 |
# File 'lib/gplus/client.rb', line 13 def api_version @api_version end |
- (Object) endpoint
Returns the value of attribute endpoint
13 14 15 |
# File 'lib/gplus/client.rb', line 13 def endpoint @endpoint end |
Instance Method Details
- (Object) access_token
Retrieve or create an OAuth2::AccessToken, using the :token and :refresh_token specified when the API client instance was initialized
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gplus/client.rb', line 89 def access_token if @token @access_token ||= OAuth2::AccessToken.new(@oauth_client, @token, :refresh_token => @refresh_token, :expires_at => @token_expires_at) if @access_token.expired? @access_token = @access_token.refresh! @access_token_refreshed = true end @access_token end end |
- (Boolean) access_token_refreshed?
Return true if the user's access token has been refreshed. If so, you should store the new token's :token and :expires_at.
101 102 103 |
# File 'lib/gplus/client.rb', line 101 def access_token_refreshed? @access_token_refreshed end |
- (Object) authorize(token, refresh_token, token_expires_at)
Authorize a Gplus::Client instance to access the user's private data, after initialization
79 80 81 82 83 84 |
# File 'lib/gplus/client.rb', line 79 def (token, refresh_token, token_expires_at) @token = token @refresh_token = refresh_token @token_expires_at = token_expires_at access_token end |
- (String) authorize_url(options = {})
Generate an authorization URL where a user can authorize your application to access their Google+ data.
54 55 56 57 58 |
# File 'lib/gplus/client.rb', line 54 def ( = {}) defaults = { :scope => 'https://www.googleapis.com/auth/plus.me', :redirect_uri => @redirect_uri } = defaults.merge() @oauth_client.auth_code.() end |
- (OAuth2::AccessToken) get_token(auth_code, params = {}, opts = {})
Retrieve an OAuth access token using the short-lived authentication code given to you after a user authorizes your application. Note that if you specified an over-ride redirect_uri when you called #authorize_url, you must use the same redirect_uri when calling #get_token.
67 68 69 70 71 |
# File 'lib/gplus/client.rb', line 67 def get_token(auth_code, params = {}, opts = {}) defaults = { :redirect_uri => @redirect_uri } params = defaults.merge(params) @access_token = @oauth_client.auth_code.get_token(auth_code, params, opts) end |