Sha256: daf43dc52849754bbf01e97ef3614d2bf86e26507bf797ff39664cddf2cefe6a

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

require 'gmail_xoauth'

module Gmail
  module Client
    class XOAuth2 < Base
      attr_reader :token

      def initialize(username, token)
        @token = token

        super(username, {})
      end

      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
          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

      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
    end # XOAuth

    register :xoauth2, XOAuth2
  end # Client
end # Gmail

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gmail-0.7.1 lib/gmail/client/xoauth2.rb
gmail-0.7.0 lib/gmail/client/xoauth2.rb
gmail-0.5.0 lib/gmail/client/xoauth2.rb