Class: Reelagram::Mail::Fetchers::EmailFetcher
- Inherits:
-
Object
- Object
- Reelagram::Mail::Fetchers::EmailFetcher
- Defined in:
- lib/reelagram/mail/fetchers/base_fetcher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#save_path ⇒ Object
readonly
Returns the value of attribute save_path.
Instance Method Summary collapse
-
#fetch(include_attachments = false) ⇒ Array<String>
Fetch invoices and yied a saved pdf file for further processing.
-
#initialize(options = {}) ⇒ EmailFetcher
constructor
Available options:.
Constructor Details
#initialize(options = {}) ⇒ EmailFetcher
Available options:
-
:email - Gmail mailbox email
-
:password - Mailbox password
-
:label - Mailbox label
-
:after - Start date
-
:save_path - Temporary location for pdf files
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 18 def initialize( = {}) raise NotConfiguredError, "Configuration is required" unless Reelagram::Mail.configured? @email = Mail.configuration.email @password = Mail.configuration.password @label = [:label] || self.class::DEFAULT_LABEL @after = [:after] @save_path = [:save_path] || "/tmp" unless File.exists?(@save_path) FileUtils.mkdir_p(@save_path) end end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
8 9 10 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 8 def after @after end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
8 9 10 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 8 def email @email end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 8 def label @label end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 8 def password @password end |
#save_path ⇒ Object (readonly)
Returns the value of attribute save_path.
8 9 10 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 8 def save_path @save_path end |
Instance Method Details
#fetch(include_attachments = false) ⇒ Array<String>
Fetch invoices and yied a saved pdf file for further processing
Fetcher establishes connection to the google mail server with provided credentials and performs an iteration over emails with label defined by SEARCH_LABEL constant. Emails without any attachments are ignored. If attachment file already exists locally it will be overwritten.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/reelagram/mail/fetchers/base_fetcher.rb', line 41 def fetch( = false) results = emails.map do || STDOUT.puts "Processing email: #{()}" { from: .from, subject: .subject, body: .body.decoded, attachments: (, ) || [] } end # Close connection connection.logout # Return all fetched files results end |