Class: Gmail::Client::XOAuth2

Inherits:
Base
  • Object
show all
Defined in:
lib/gmail/client/xoauth2.rb

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

Attributes inherited from Base

#options, #username

Instance Method Summary collapse

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

#tokenObject (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 (raise_errors = false)
  @imap and @logged_in = ( = @imap.authenticate('XOAUTH2', username, token)) && .name == 'OK'
rescue Net::IMAP::NoResponseError => e
  if raise_errors
    message = "Couldn't login to given Gmail account: #{username}"
    message += " (#{e.response.data.text.strip})"
    raise(AuthorizationError.new(e.response), message, e.backtrace)
  end
end

#smtp_settingsObject



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