Class: Mailinator
- Inherits:
-
Object
- Object
- Mailinator
- Defined in:
- lib/mailinator.rb,
lib/mailinator/spec.rb
Defined Under Namespace
Modules: Spec
Constant Summary collapse
- BASE_URL =
'http://mailinator.com'
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #atom_url ⇒ Object
- #inbox_url ⇒ Object
-
#initialize(name = nil, opts = {}) ⇒ Mailinator
constructor
A new instance of Mailinator.
- #mailbox ⇒ Object
- #rss_url ⇒ Object
- #widget_url(width = '250', height = '250') ⇒ Object
Constructor Details
#initialize(name = nil, opts = {}) ⇒ Mailinator
Returns a new instance of Mailinator.
12 13 14 15 |
# File 'lib/mailinator.rb', line 12 def initialize(name = nil, opts = {}) @name = name @email = format_email(name) end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
10 11 12 |
# File 'lib/mailinator.rb', line 10 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/mailinator.rb', line 10 def name @name end |
Class Method Details
.domain ⇒ Object
64 65 66 |
# File 'lib/mailinator.rb', line 64 def self.domain @domain ||= "mailinator.com" end |
.domain=(domain) ⇒ Object
56 57 58 |
# File 'lib/mailinator.rb', line 56 def self.domain=(domain) @domain = domain end |
.mostly_random ⇒ Object
49 50 51 52 53 54 |
# File 'lib/mailinator.rb', line 49 def self.mostly_random now = Time.now sha = Digest::SHA1.hexdigest("#{now.to_i}#{now.usec}").to_s new(sha.slice(0, 25)) end |
.reset_domain! ⇒ Object
60 61 62 |
# File 'lib/mailinator.rb', line 60 def self.reset_domain! @domain = nil end |
Instance Method Details
#atom_url ⇒ Object
25 26 27 |
# File 'lib/mailinator.rb', line 25 def atom_url action_url('atom') end |
#inbox_url ⇒ Object
17 18 19 |
# File 'lib/mailinator.rb', line 17 def inbox_url action_url('maildir') end |
#mailbox ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mailinator.rb', line 33 def mailbox doc = Nokogiri::HTML(open(atom_url)) doc.css('feed entry').map do |entry| mail = Mail.new mail.subject = entry.at_css('title').text mail.body = entry.at_css('summary').text mail.to = @email mail.from = entry.at_css('author name').text mail end end |
#rss_url ⇒ Object
21 22 23 |
# File 'lib/mailinator.rb', line 21 def rss_url action_url('rss') end |
#widget_url(width = '250', height = '250') ⇒ Object
29 30 31 |
# File 'lib/mailinator.rb', line 29 def (width = '250', height = '250') URI.parse("#{BASE_URL}/widget/mailin8r.jsp?w=#{width}&h=#{height}&b=#{@name}").to_s end |