Class: Gmail::Client::XOAuth

Inherits:
Base
  • Object
show all
Defined in:
lib/gmail/client/xoauth.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!, #fill_username, #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, options={})
  @token           = options.delete(:token)
  @secret          = options.delete(:secret)
  @consumer_key    = options.delete(:consumer_key)
  @consumer_secret = options.delete(:consumer_secret)
 
  super(username, options)
end

Instance Attribute Details

#consumer_keyObject (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_secretObject (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

#secretObject (readonly)

Returns the value of attribute secret.



7
8
9
# File 'lib/gmail/client/xoauth.rb', line 7

def secret
  @secret
end

#tokenObject (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

#login(raise_errors = false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gmail/client/xoauth.rb', line 20

def (raise_errors=false)
  @imap and @logged_in = ( = @imap.authenticate('XOAUTH', username,
    :consumer_key    => consumer_key,
    :consumer_secret => consumer_secret,
    :token           => token,
    :token_secret    => secret
  )) && .name == 'OK'
rescue
  raise_errors and raise AuthorizationError, "Couldn't login to given GMail account: #{username}"        
end

#smtp_settingsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gmail/client/xoauth.rb', line 31

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
     },
     :authentication => :xoauth,
     :enable_starttls_auto => true
   }]
end