Class: Contacts::Google

Inherits:
OAuthConsumer show all
Defined in:
lib/contacts/google.rb

Constant Summary collapse

CONSUMER_OPTIONS =
Util.frozen_hash(
  :site => "https://www.google.com",
  :request_token_path => "/accounts/OAuthGetRequestToken",
  :access_token_path => "/accounts/OAuthGetAccessToken",
  :authorize_path => "/accounts/OAuthAuthorizeToken"
)
REQUEST_TOKEN_PARAMS =
{'scope' => "https://www.google.com/m8/feeds/"}

Instance Attribute Summary

Attributes inherited from OAuthConsumer

#access_token, #request_token

Attributes inherited from Consumer

#error

Instance Method Summary collapse

Methods inherited from OAuthConsumer

#authentication_url, #authorize, #initialize_serialized, #serializable_data

Methods inherited from Consumer

#authorize, configuration, configuration_attribute, configure, deserialize, #serialize

Constructor Details

#initialize(options = {}) ⇒ Google

Returns a new instance of Google.



15
16
17
# File 'lib/contacts/google.rb', line 15

def initialize(options={})
  super(CONSUMER_OPTIONS, REQUEST_TOKEN_PARAMS)
end

Instance Method Details

#contacts(options = {}) ⇒ Object

retrieve the contacts for the user’s account

The options it takes are:

- limit - the max number of results to return
  ("max-results"). Defaults to 200
- offset - the index to start returning results for pagination ("start-index")
- projection - defaults to thin
    http://code.google.com/apis/contacts/docs/3.0/reference.html#Projections


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/contacts/google.rb', line 28

def contacts(options={})
  return nil if @access_token.nil?
  params = {:limit => 200}.update(options)
  google_params = translate_parameters(params)
  query = params_to_query(google_params)
  projection = options[:projection] || "thin"
  begin
    response = @access_token.get("https://www.google.com/m8/feeds/contacts/default/#{projection}?#{query}")
  rescue OAuth::Unauthorized => error
    # Token probably expired.
    @error = error.message
    return nil
  end
  parse_contacts(response.body)
end