Class: Getairmail::Email
- Inherits:
-
Object
- Object
- Getairmail::Email
- Defined in:
- lib/getairmail.rb
Instance Attribute Summary collapse
-
#email_address ⇒ Object
readonly
Returns the value of attribute email_address.
-
#emails ⇒ Object
readonly
Returns the value of attribute emails.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(mail) ⇒ Boolean
Deletes the email you pass it.
-
#delete_all ⇒ Boolean
Deletes all emails.
-
#initialize(url = nil) ⇒ Email
constructor
Creates a new Email object with a random email and URL.
-
#load_from_server ⇒ Array
Gets the emails from the web interface.
Constructor Details
#initialize(url = nil) ⇒ Email
Creates a new Email object with a random email and URL
16 17 18 19 20 21 22 |
# File 'lib/getairmail.rb', line 16 def initialize(url = nil) url ||= Net::HTTP.get(URI.parse('http://getairmail.com/random')).match(/href="([^"]+)"/)[1] @url = url puts "********GETAIRMAIL URL = #{@url} *************" # TODO For logging purpose need to delete it. @email_address = Nokogiri::HTML.parse(open(@url)).css('#tempemail').first.attributes['value'].value load_from_server end |
Instance Attribute Details
#email_address ⇒ Object (readonly)
Returns the value of attribute email_address.
11 12 13 |
# File 'lib/getairmail.rb', line 11 def email_address @email_address end |
#emails ⇒ Object (readonly)
Returns the value of attribute emails.
11 12 13 |
# File 'lib/getairmail.rb', line 11 def emails @emails end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/getairmail.rb', line 11 def url @url end |
Class Method Details
.get_mail(url) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/getairmail.rb', line 64 def self.get_mail(url) inbox_emails = self.new(url).load_from_server if inbox_emails.blank? wait_secs(12) #Wait for email inbox_emails = self.new(url).load_from_server end return inbox_emails end |
.get_second_email(url) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/getairmail.rb', line 73 def self.get_second_email(url) inbox_emails = self.new(url).load_from_server if(inbox_emails.blank? or inbox_emails.count!=2) wait_secs(12) #Wait for email inbox_emails = self.new(url).load_from_server end return inbox_emails end |
Instance Method Details
#delete(mail) ⇒ Boolean
Deletes the email you pass it
27 28 29 30 31 32 33 34 35 |
# File 'lib/getairmail.rb', line 27 def delete(mail) resp = Net::HTTP.new('getairmail.com').request(Net::HTTP::Delete.new("/d/#{mail.}")) if resp.code == "200" @emails.delete_if{|email| email. == mail. } true else false end end |
#delete_all ⇒ Boolean
Deletes all emails
39 40 41 42 43 44 45 46 47 |
# File 'lib/getairmail.rb', line 39 def delete_all count = 0 # For some reason it fails periodically, so I do it a few times while @emails.any? and count < 3 @emails.each{|email| delete(email) } count += 1 end @emails.empty? end |
#load_from_server ⇒ Array
Gets the emails from the web interface
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/getairmail.rb', line 51 def load_from_server = JSON.parse(Nokogiri::HTML.parse(open(@url)).css('head script')[1].text.match(/messages = ({.+})/)[1])['m'] @emails = .map do || Mail.new do from ['f'] ['u'] to @email_address subject ['s'] body open("http://getairmail.com/html/#{['u']}").read end end end |