Class: MailFetcher::GmailClient
- Inherits:
-
Object
- Object
- MailFetcher::GmailClient
- Includes:
- RetryHelper
- Defined in:
- lib/mail_fetcher/gmail_client.rb
Constant Summary collapse
- HOST =
'imap.gmail.com'
- PORT =
993
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #find(recipient, subject = '', wait = MailFetcher::Client.max_wait_time) ⇒ Object
-
#initialize(account, client_id, client_secret, refresh_token) ⇒ GmailClient
constructor
A new instance of GmailClient.
Methods included from RetryHelper
Constructor Details
#initialize(account, client_id, client_secret, refresh_token) ⇒ GmailClient
Returns a new instance of GmailClient.
16 17 18 19 20 21 |
# File 'lib/mail_fetcher/gmail_client.rb', line 16 def initialize(account, client_id, client_secret, refresh_token) @account = account @client_id = client_id @client_secret = client_secret @refresh_token = refresh_token end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/mail_fetcher/gmail_client.rb', line 14 def logger @logger end |
Instance Method Details
#find(recipient, subject = '', wait = MailFetcher::Client.max_wait_time) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mail_fetcher/gmail_client.rb', line 23 def find(recipient, subject='', wait=MailFetcher::Client.max_wait_time) @connection ||= authenticated_connection = eventually(:tries => wait, :delay => 1) do begin @connection.examine('INBOX') search_filter = ['TO', recipient, 'SUBJECT', subject] results = @connection.search(search_filter) logger.debug("Inbox contains #{results.length} messages matching search criteria") if logger results.first rescue => e logger.error("Error while trying trying to find a message in INBOX (#{e.})") if logger nil end end ? GmailMessage.new(@connection, ) : nil end |