Module: GooglePlus::Resource

Included in:
Activity, Comment, Cursor, Person
Defined in:
lib/google_plus/resource.rb

Overview

A modular extension for classes that make requests to the Google Plus API

Constant Summary collapse

BASE_URI =

Base resource URI - includes trailing slash

'https://www.googleapis.com/plus/v1/'

Instance Method Summary collapse

Instance Method Details

#make_request(method, resource, params = {}) ⇒ Object

Make a request to an external resource



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/google_plus/resource.rb', line 11

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}", 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)
  rescue RestClient::ResourceNotFound
    nil
  end
end