maildrop 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 816d3fba6364b09f26b1b72acb80e5bfb3a81e7b
4
+ data.tar.gz: f6b0e3f5c9994326b9545f7449f76012789f08dd
5
+ SHA512:
6
+ metadata.gz: 0d6e6db3cd2840ee0079df70754a2cea00ffd5af41208df9c4c6bfa6f75a8e6ef0969de5862f376b597993e706b1ecccececee2c452cb22af999b19d9b353cf5
7
+ data.tar.gz: 32c5df24b504b8f8b564328ee65669d77170b30c1172049ccfda648ea778b5eed2ffb8e5616f7080d8be72f945b5bb8815c73cd548243d46d801de7ab238d88b
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+ require 'securerandom'
4
+
5
+ require_relative 'maildrop/http'
6
+ require_relative 'maildrop/mailbox'
7
+ require_relative 'maildrop/models/email.rb'
8
+ require_relative 'maildrop/models/mailbox.rb'
9
+
10
+ module Maildrop
11
+ end
@@ -0,0 +1,41 @@
1
+ module Maildrop
2
+ class HTTP
3
+ class NotFound < StandardError; end
4
+ class RequestError < StandardError; end
5
+
6
+ def get(url)
7
+ handle_response(request(url))
8
+ end
9
+
10
+ private
11
+
12
+ def request(url)
13
+ uri = generate_url(url)
14
+ perform_request(uri)
15
+ end
16
+
17
+ def perform_request(uri)
18
+ http = Net::HTTP.new(uri.host, uri.port)
19
+ http.get(uri.request_uri)
20
+ end
21
+
22
+ def generate_url(url)
23
+ URI("#{base_url}/#{url}")
24
+ end
25
+
26
+ def base_url
27
+ 'http://maildrop.cc/inbox'
28
+ end
29
+
30
+ def handle_response(response)
31
+ case response.code.to_i
32
+ when 200
33
+ response.body
34
+ when 404
35
+ raise NotFound
36
+ else
37
+ raise RequestError, status: response.message, code: response.code
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module Maildrop
2
+ class Mailbox
3
+ class << self
4
+ def get(name)
5
+ build_model(name)
6
+ end
7
+
8
+ def random_get
9
+ name = SecureRandom.hex(12)
10
+ build_model(name)
11
+ end
12
+
13
+ private
14
+
15
+ def build_model(name)
16
+ data = download_mailbox(name)
17
+ Maildrop::Models::Mailbox.new(name, data)
18
+ end
19
+
20
+ def download_mailbox(name)
21
+ http = Maildrop::HTTP.new
22
+ http.get(name)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ module Maildrop::Models
2
+ class Email
3
+ attr_reader :id, :sender, :subject, :date, :mailbox_name
4
+
5
+ def initialize(mailbox_name, data)
6
+ @id = find_id(data)
7
+ @date = find_date(data)
8
+ @sender = find_sender(data)
9
+ @subject = find_subject(data)
10
+ @mailbox_name = mailbox_name
11
+ end
12
+
13
+ def body
14
+ http = Maildrop::HTTP.new
15
+ http.get("#{@mailbox_name}/#{@id}/body") # TODO: remove maildrop header!
16
+ end
17
+
18
+ private
19
+
20
+ def find_id(data)
21
+ data.attr('data-id')
22
+ end
23
+
24
+ def find_sender(data)
25
+ data.css('td.sender').text
26
+ end
27
+
28
+ def find_subject(data)
29
+ data.css('td.subject').text
30
+ end
31
+
32
+ def find_date(data)
33
+ date_string = data.css('td.date').text
34
+ DateTime.parse(date_string)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module Maildrop::Models
2
+ class Mailbox
3
+ attr_reader :name, :emails
4
+
5
+ def initialize(name, data)
6
+ @name = name
7
+ emails = Nokogiri::HTML(data).css('tr').drop(1)
8
+ @emails = emails.map do |email_data|
9
+ Maildrop::Models::Email.new(name, email_data)
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maildrop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Melvin Lammerts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby interface to MailDrop for quick, disposable mailboxes.
14
+ email: hi@melvin.sh
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/maildrop.rb
20
+ - lib/maildrop/http.rb
21
+ - lib/maildrop/mailbox.rb
22
+ - lib/maildrop/models/email.rb
23
+ - lib/maildrop/models/mailbox.rb
24
+ homepage: https://github.com/melvinsh/maildrop
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.1
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.6.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Ruby interface to MailDrop.
48
+ test_files: []