Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Added access_token support
Browse files Browse the repository at this point in the history
  • Loading branch information
seejohnrun committed Oct 5, 2011
1 parent 898c02f commit 9b68a22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/google_plus.rb
Expand Up @@ -9,7 +9,7 @@ module GooglePlus
autoload :Person, File.dirname(__FILE__) + '/google_plus/person'

class << self
attr_accessor :api_key
attr_accessor :api_key, :access_token
end

# Return whether or not the we have an API
Expand Down
11 changes: 9 additions & 2 deletions lib/google_plus/resource.rb
Expand Up @@ -11,12 +11,19 @@ module Resource

# Make a request to an external resource
def make_request(method, resource, params = {})
# Put together the common params
params[:key] ||= GooglePlus.api_key unless GooglePlus.api_key.nil?
params[:userIp] = params.delete(:user_ip) if params.has_key?(:user_ip)
params[:pp] = '0' # google documentation is incorrect, it says 'prettyPrint'
# Add the access token if we have it
headers = {}
if token = params[:access_token] || GooglePlus.access_token
headers[:Authorization] = "OAuth #{token}"
end
# And make the request
begin
RestClient.get "#{BASE_URI}#{resource}", :params => params
rescue RestClient::Forbidden, RestClient::BadRequest => e
RestClient.get "#{BASE_URI}#{resource}", headers.merge(:params => params)
rescue RestClient::Unauthorized, RestClient::Forbidden, RestClient::BadRequest => e
raise GooglePlus::RequestError.new(e)
rescue SocketError => e
raise GooglePlus::ConnectionError.new(e)
Expand Down

0 comments on commit 9b68a22

Please sign in to comment.