Class: MailHogwarts::Mailer
- Inherits:
-
Object
- Object
- MailHogwarts::Mailer
- Defined in:
- lib/mailhogwarts/mailer.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #call ⇒ Object
- #count ⇒ Object
- #ids ⇒ Object
-
#initialize(args) ⇒ Mailer
constructor
A new instance of Mailer.
- #select(filters) ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(args) ⇒ Mailer
Returns a new instance of Mailer.
5 6 7 |
# File 'lib/mailhogwarts/mailer.rb', line 5 def initialize(args) @url = "#{@domain = args[:url]}#{@path = args[:path]}" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/mailhogwarts/mailer.rb', line 3 def body @body end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
3 4 5 |
# File 'lib/mailhogwarts/mailer.rb', line 3 def domain @domain end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
3 4 5 |
# File 'lib/mailhogwarts/mailer.rb', line 3 def @messages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/mailhogwarts/mailer.rb', line 3 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/mailhogwarts/mailer.rb', line 3 def url @url end |
Instance Method Details
#[](index) ⇒ Object
25 26 27 |
# File 'lib/mailhogwarts/mailer.rb', line 25 def [](index) @messages[index] end |
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mailhogwarts/mailer.rb', line 9 def call response = RestClient::Request.execute method: :get, url: @url, verify_ssl: false @body = JSON.parse(response.body) @messages = body['items'].map do || Message.new id: ['ID'], created_at: Time.parse(['Created']).to_i, from: ['Raw']['From'], to: ['Raw']['To'], subject: readable_subject(['Content']['Headers']['Subject'].join(' ')), body: readable_body(['Content']['Body']) end @messages.size end |
#count ⇒ Object
33 34 35 |
# File 'lib/mailhogwarts/mailer.rb', line 33 def count body['count'] end |
#ids ⇒ Object
29 30 31 |
# File 'lib/mailhogwarts/mailer.rb', line 29 def ids @ids = @messages.map(&:id) end |
#select(filters) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mailhogwarts/mailer.rb', line 41 def select(filters) = @messages = [] (%i[from to subject body] & filters.keys).each do |filter| .each do || << if .send(filter).include?(filters[filter]) end = = [] end end |
#total ⇒ Object
37 38 39 |
# File 'lib/mailhogwarts/mailer.rb', line 37 def total body['total'] end |