Class: Gmail::Client::XOAuth2
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
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(username, token) ⇒ XOAuth2
constructor
A new instance of XOAuth2.
- #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, token) ⇒ XOAuth2
Returns a new instance of XOAuth2.
8 9 10 11 12 |
# File 'lib/gmail/client/xoauth2.rb', line 8 def initialize(username, token) @token = token super(username, {}) end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/gmail/client/xoauth2.rb', line 6 def token @token end |
Instance Method Details
#login(raise_errors = false) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/gmail/client/xoauth2.rb', line 14 def login(raise_errors = false) @imap and @logged_in = (login = @imap.authenticate('XOAUTH2', username, token)) && 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
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gmail/client/xoauth2.rb', line 24 def smtp_settings [:smtp, { :address => GMAIL_SMTP_HOST, :port => GMAIL_SMTP_PORT, :domain => mail_domain, :user_name => username, :password => token, :authentication => :xoauth2, :enable_starttls_auto => true }] end |