reelagram-mail 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reelagram/mail.rb +5 -0
- data/lib/reelagram/mail/configuration.rb +6 -0
- data/lib/reelagram/mail/fetchers/base_fetcher.rb +6 -3
- data/lib/reelagram/mail/parsers/shipping_parser.rb +39 -31
- data/lib/reelagram/version.rb +1 -1
- data/test/configuration_test.rb +6 -0
- data/test/support/config_helper.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dafd98edae8423b5235bad33dc9fc937a2a0f31
|
4
|
+
data.tar.gz: dbba74e8936d1cacd2de5c724fdcc6a3d4ed10f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95bc1cca2ec8a521d9c3eb2952998624d6dc5d4a21c56a9a7193964b13d4ff10f984f4c2387e9c817bd69d80389d8b94cd86ca5f0be9ff2d1a2ae944ad05402
|
7
|
+
data.tar.gz: 22c95b4e55932f28f35fef27d14ea85dc3cb43ac53133f6e16b0eaa0f5b83083017611f25798539da01e9d9703276d2acee577bb2a9869eb088c51e0fa064d76
|
data/lib/reelagram/mail.rb
CHANGED
@@ -20,9 +20,10 @@ module Reelagram
|
|
20
20
|
|
21
21
|
@email = Mail.configuration.email
|
22
22
|
@password = Mail.configuration.password
|
23
|
-
@label = options
|
24
|
-
@after = options
|
25
|
-
@save_path = options
|
23
|
+
@label = options.fetch(:label, self.class::DEFAULT_LABEL)
|
24
|
+
@after = options.fetch(:after, nil)
|
25
|
+
@save_path = options.fetch(:save_path, "/tmp")
|
26
|
+
@test_mode = options.fetch(:test, Mail.configuration.test)
|
26
27
|
|
27
28
|
unless File.exists?(@save_path)
|
28
29
|
FileUtils.mkdir_p(@save_path)
|
@@ -39,6 +40,8 @@ module Reelagram
|
|
39
40
|
# @return [Array<String>] array with saved pdf files locations
|
40
41
|
#
|
41
42
|
def fetch(include_attachments = false)
|
43
|
+
connection.peek = true if @test_mode
|
44
|
+
|
42
45
|
results = emails.map do |message|
|
43
46
|
STDOUT.puts "Processing email: #{message_title(message)}"
|
44
47
|
|
@@ -4,54 +4,50 @@ module Reelagram
|
|
4
4
|
module Mail
|
5
5
|
module Parsers
|
6
6
|
class ShippingParser
|
7
|
-
attr_reader :doc
|
7
|
+
attr_reader :doc, :debug
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@debug = Reelagram::Mail.debug?
|
11
|
+
end
|
8
12
|
|
9
13
|
def run(string)
|
10
14
|
@doc = Nokogiri::HTML(string)
|
15
|
+
log_parsed_data if debug
|
11
16
|
self
|
12
17
|
end
|
13
18
|
|
14
19
|
def carrier
|
15
|
-
|
16
|
-
|
17
|
-
else
|
18
|
-
"Unavailable"
|
19
|
-
end
|
20
|
+
return "Unavailable" unless shipping_info_row
|
21
|
+
@row.children[1].text
|
20
22
|
end
|
21
23
|
|
22
24
|
def tracking_number
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
"Unavailable"
|
27
|
-
end
|
25
|
+
return "Unavailable" unless shipping_info_row
|
26
|
+
@row.children[3].css("a").text
|
28
27
|
end
|
29
28
|
|
30
29
|
def tracking_link
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
30
|
+
return unless shipping_info_row
|
31
|
+
begin
|
32
|
+
@row.children[3]
|
33
|
+
.css("a")
|
34
|
+
.attr("href")
|
35
|
+
.value
|
36
|
+
rescue
|
37
|
+
nil
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
41
|
def order_number
|
44
|
-
table = doc.css("table")[2]
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
.last
|
54
|
-
end
|
42
|
+
return unless table = doc.css("table")[2]
|
43
|
+
table.css("tr")
|
44
|
+
.children.css("td")
|
45
|
+
.children
|
46
|
+
.text
|
47
|
+
.gsub(/\\n+/, " ")
|
48
|
+
.scan(/\w*/)
|
49
|
+
.reject(&:empty?)
|
50
|
+
.last
|
55
51
|
end
|
56
52
|
|
57
53
|
def reset!
|
@@ -70,6 +66,18 @@ module Reelagram
|
|
70
66
|
end
|
71
67
|
end
|
72
68
|
|
69
|
+
def log_parsed_data
|
70
|
+
log("-------------------------------------")
|
71
|
+
log("Order Number: #{order_number}")
|
72
|
+
log("Carrier: #{carrier}")
|
73
|
+
log("Tracking Number: #{tracking_number}")
|
74
|
+
log("Tracking Link: #{tracking_link}")
|
75
|
+
log("-------------------------------------")
|
76
|
+
end
|
77
|
+
|
78
|
+
def log(message)
|
79
|
+
STDOUT.puts(message)
|
80
|
+
end
|
73
81
|
end
|
74
82
|
end
|
75
83
|
end
|
data/lib/reelagram/version.rb
CHANGED
data/test/configuration_test.rb
CHANGED
@@ -29,4 +29,10 @@ class ConfgurationTest < MiniTest::Unit::TestCase
|
|
29
29
|
def test_configuration_returns_true
|
30
30
|
assert_equal(true, ConfigHelper.confgure_mail)
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_configure_with_debug_mode
|
34
|
+
ConfigHelper.confgure_mail
|
35
|
+
Reelagram::Mail.configuration.debug = true
|
36
|
+
assert(Reelagram::Mail.debug?)
|
37
|
+
end
|
32
38
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ConfigHelper
|
2
2
|
def self.confgure_mail
|
3
3
|
Reelagram::Mail.configure do |c|
|
4
|
-
c.email
|
4
|
+
c.email = "foo@example.com"
|
5
5
|
c.password = "zomgLOLZ"
|
6
6
|
end
|
7
7
|
end
|
@@ -10,10 +10,12 @@ module ConfigHelper
|
|
10
10
|
Reelagram::Mail.configuration = nil
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.configure_for_testing
|
13
|
+
def self.configure_for_testing
|
14
14
|
Reelagram::Mail.configure do |c|
|
15
15
|
c.email = ENV["TEST_EMAIL"]
|
16
16
|
c.password = ENV["TEST_PASSWORD"]
|
17
|
+
c.debug = ENV["DEBUG"]
|
18
|
+
c.test = true
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|