Sha256: 423f1d63fbba3e42a64ef338d4d4b460e2ddb451d3da68b6f7994a4651f10957

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'gplus/activity'
require 'gplus/person'

module Gplus
  class Client
    def initialize(options = {})
      @client_id = options[:client_id]
      @client_secret = options[:client_secret]
      @redirect_uri = options[:redirect_uri]
      @token = options[:token]

      @oauth_client = OAuth2::Client.new(
        @client_id,
        @client_secret,
        :site => 'https://www.googleapis.com/plus/',
        :authorize_url => 'https://accounts.google.com/o/oauth2/auth',
        :token_url => 'https://accounts.google.com/o/oauth2/token'
      )
    end

    def authorize_url(redirect_uri = @redirect_uri)
      @oauth_client.auth_code.authorize_url(:redirect_uri => redirect_uri, :scope => 'https://www.googleapis.com/auth/plus.me')
    end

    def authorize(auth_code, redirect_uri = @redirect_uri)
      @access_token = @oauth_client.auth_code.get_token(auth_code, :redirect_uri => redirect_uri)
    end

  private
    def access_token
      @access_token ||= OAuth2::AccessToken.new(@oauth_client, @token)
    end

    def get(path)
      response = access_token.get("v1/#{path}")
      MultiJson.decode(response.body)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gplus-0.2.2 lib/gplus/client.rb
gplus-0.2.1 lib/gplus/client.rb
gplus-0.2.0 lib/gplus/client.rb