Class: Contacts::GoogleOAuth

Inherits:
Google
  • Object
show all
Defined in:
lib/contacts/google_oauth.rb

Constant Summary

Constants inherited from Google

Contacts::Google::AuthSubPath, Contacts::Google::ClientLogin, Contacts::Google::DOMAIN, Contacts::Google::FeedsPath, Contacts::Google::GroupsPath

Instance Attribute Summary

Attributes inherited from Google

#headers, #projection, #token, #user

Instance Method Summary collapse

Methods inherited from Google

#all_contacts, authentication_url, authentication_url_options, client_login, client_login_options, #contacts, #get_groups, #groups, #response_body, response_body, session_token, #updated_at, #updated_at_string

Constructor Details

#initialize(consumer_key, consumer_secret, user_id = 'default') ⇒ GoogleOAuth

Returns a new instance of GoogleOAuth.



49
50
51
52
53
54
# File 'lib/contacts/google_oauth.rb', line 49

def initialize(consumer_key, consumer_secret, user_id = 'default')
  @consumer = ::GoogleOAuth::Consumer.new(consumer_key, consumer_secret)
  @request_token = @consumer.get_request_token :scope => "https://www.google.com/m8/feeds/"
  @projection = 'thin'
  @user = user_id.to_s
end

Instance Method Details

#access_tokenObject



76
77
78
79
80
81
82
# File 'lib/contacts/google_oauth.rb', line 76

def access_token
  return @access_token if @access_token
  begin
    @access_token = @request_token.get_access_token
  rescue Net::HTTPServerException
  end
end

#authentication_url(params = {}) ⇒ Object

Available parameters:

  • hd: Google Apps domain that should be requested (default nil)

  • oauth_callback: The URL that the user should be redirected to when he successfully authorized us.



72
73
74
# File 'lib/contacts/google_oauth.rb', line 72

def authentication_url(params={})
  @request_token.authorize_url params
end

#get(params = {}) ⇒ Object



84
85
86
87
88
89
# File 'lib/contacts/google_oauth.rb', line 84

def get(params={})
  path = FeedsPath + CGI.escape(@user)
  google_params = translate_parameters(params)
  query = self.class.query_string(google_params)
  access_token.get("#{path}/#{@projection}?#{query}")
end

#marshal_dumpObject



63
64
65
66
67
# File 'lib/contacts/google_oauth.rb', line 63

def marshal_dump
  {:consumer => @consumer,
   :request_token => @request_token,
   :user => @user}
end

#marshal_load(data) ⇒ Object



56
57
58
59
60
61
# File 'lib/contacts/google_oauth.rb', line 56

def marshal_load(data)
  @consumer = data[:consumer]
  @request_token = data[:request_token]
  @projection = 'thin'
  @user = data[:user]
end