lib/gplus/client.rb in gplus-0.2.2 vs lib/gplus/client.rb in gplus-0.3.0
- old
+ new
@@ -2,10 +2,11 @@
require 'gplus/person'
module Gplus
class Client
def initialize(options = {})
+ @api_key = options[:api_key]
@client_id = options[:client_id]
@client_secret = options[:client_secret]
@redirect_uri = options[:redirect_uri]
@token = options[:token]
@@ -26,14 +27,20 @@
@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)
+ if @token
+ @access_token ||= OAuth2::AccessToken.new(@oauth_client, @token)
+ end
end
- def get(path)
- response = access_token.get("v1/#{path}")
+ def get(path, params = {})
+ if access_token
+ response = access_token.get("v1/#{path}", params)
+ else
+ response = @oauth_client.request(:get, "v1/#{path}", { :params => params.merge(:key => @api_key) })
+ end
MultiJson.decode(response.body)
end
end
end