Class: RubePost::Grabber
- Inherits:
-
Object
- Object
- RubePost::Grabber
- Defined in:
- lib/rube_post.rb
Constant Summary collapse
- URL =
"https://portal.epost.de"
- SHOW_URL =
"#{URL}/mail/mailbox/view?msgStart=&messages="
Instance Method Summary collapse
- #email_content(id) ⇒ Object
- #emails_in_inbox ⇒ Object
-
#initialize(username, password) ⇒ Grabber
constructor
A new instance of Grabber.
- #move_to_trash(id) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Grabber
Returns a new instance of Grabber.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rube_post.rb', line 38 def initialize(username, password) @agent = Mechanize.new page = @agent.get("#{URL}/login") login_form = page.forms.first login_form.field_with('username').value = username.sub(/@.*/,'') login_form.field_with('password').value = password @inbox = login_form.submit @account = .action.match(/(\d{10,})/)[1] @agent end |
Instance Method Details
#email_content(id) ⇒ Object
61 62 63 64 |
# File 'lib/rube_post.rb', line 61 def email_content(id) body = @agent.get("#{SHOW_URL}#{full_id(id).gsub('/','%2F')}").send(:html_body) Nokogiri::HTML(body).css('#e-post-body').first.text.strip end |
#emails_in_inbox ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rube_post.rb', line 49 def emails_in_inbox doc = Nokogiri::HTML(@inbox.send(:html_body)) mails = doc.css('#messageList > tr')[1..-1] || raise('could not open inbox <-> login failed ?') mails.map do |mail| { :id => mail.attr('id').split('/').last, :sender => self.class.extract_sender(mail), :subject => mail.css('td.subject').text.strip } end end |
#move_to_trash(id) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/rube_post.rb', line 66 def move_to_trash(id) form = checkbox = form.checkboxes.detect{|c| c.value == full_id(id) } checkbox.check = form..detect{|b| b.name == 'cmd[delete-message]'} page = @agent.submit(form, ) checkbox.uncheck # revert checking or something might o wrong later... page end |