Class: Gmail::Client::XOAuth
Constant Summary
Constants inherited from Base
Base::GMAIL_IMAP_HOST, Base::GMAIL_IMAP_PORT, Base::GMAIL_SMTP_HOST, Base::GMAIL_SMTP_PORT
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Attributes inherited from Base
Instance Method Summary collapse
- #access_token ⇒ Object
-
#initialize(username, options = {}) ⇒ XOAuth
constructor
A new instance of XOAuth.
- #login(raise_errors = false) ⇒ Object
- #smtp_settings ⇒ Object
Methods inherited from Base
#compose, #connect, #connect!, #connection, #deliver, #deliver!, #disconnect, #fill_username, #find, #inbox, #inspect, #labels, #logged_in?, #login!, #logout, #mail_domain, #mailbox, #mailboxes
Constructor Details
#initialize(username, options = {}) ⇒ XOAuth
Returns a new instance of XOAuth.
11 12 13 14 15 16 17 18 |
# File 'lib/gmail/client/xoauth.rb', line 11 def initialize(username, = {}) @token = .delete(:token) @secret = .delete(:secret) @consumer_key = .delete(:consumer_key) @consumer_secret = .delete(:consumer_secret) super(username, ) end |
Instance Attribute Details
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
8 9 10 |
# File 'lib/gmail/client/xoauth.rb', line 8 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
9 10 11 |
# File 'lib/gmail/client/xoauth.rb', line 9 def consumer_secret @consumer_secret end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
7 8 9 |
# File 'lib/gmail/client/xoauth.rb', line 7 def secret @secret end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/gmail/client/xoauth.rb', line 6 def token @token end |
Instance Method Details
#access_token ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gmail/client/xoauth.rb', line 34 def access_token = { :site => "https://www.google.com", :request_token_path => "/accounts/OAuthGetRequestToken", :authorize_path => "/accounts/OAuthAuthorizeToken", :access_token_path => "/accounts/OAuthGetAccessToken" } consumer = OAuth::Consumer.new(consumer_key, consumer_secret, ) @access_token ||= OAuth::AccessToken.new(consumer, token, secret) @access_token end |
#login(raise_errors = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gmail/client/xoauth.rb', line 20 def login(raise_errors = false) @imap and @logged_in = (login = @imap.authenticate('XOAUTH', username, :consumer_key => consumer_key, :consumer_secret => consumer_secret, :token => token, :token_secret => secret)) && login.name == 'OK' rescue Net::IMAP::NoResponseError => e if raise_errors = "Couldn't login to given Gmail account: #{username}" += " (#{e.response.data.text.strip})" raise(AuthorizationError.new(e.response), , e.backtrace) end end |
#smtp_settings ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gmail/client/xoauth.rb', line 46 def smtp_settings [:smtp, { :address => GMAIL_SMTP_HOST, :port => GMAIL_SMTP_PORT, :domain => mail_domain, :user_name => username, :password => { :consumer_key => consumer_key, :consumer_secret => consumer_secret, :token => token, :token_secret => secret, :access_token => access_token }, :authentication => :xoauth, :enable_starttls_auto => true }] end |