reelagram-mail 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/reelagram/mail/parsers/shipping_parser.rb +20 -5
- data/lib/reelagram/mail/processors/shipping_processor.rb +2 -1
- data/lib/reelagram/version.rb +1 -1
- data/test/parsers/shipping_parser_test.rb +24 -0
- data/test/processors/shipping_processor_test.rb +3 -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: 08eb5c9c91316ad4f51bc73ae30529becc999712
|
4
|
+
data.tar.gz: 6494edc93363360c9c0dcc43194eb808b69d8033
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57c50a3f424325adc1aeb7ddf4319f957508805e6a0713d3712966a93022d74e99027faa8fa3d1dec7dabc8f968499af1cccf2cf58c49703cc7dc2c750a5694d
|
7
|
+
data.tar.gz: ef27f6bde615cd71c8302dd61114d39c75dc4730a95b3ce24cef2fd0e223379d17f455b9eb0e88a96b945fa573f63fa60894f587c7040ca80824e340f1a11dc6
|
data/Gemfile.lock
CHANGED
@@ -21,14 +21,29 @@ module Reelagram
|
|
21
21
|
shipping_info[-1]
|
22
22
|
end
|
23
23
|
|
24
|
+
def tracking_link
|
25
|
+
tracking_block = string.gsub(/\n/, "").scan(/(?<=Shipped By Tracking Number).*(?=\=>)/)
|
26
|
+
if tracking_block.any?
|
27
|
+
link = tracking_block.first.
|
28
|
+
split("<").
|
29
|
+
last
|
30
|
+
"#{link}="
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
private
|
25
35
|
|
26
36
|
def shipping_info
|
27
|
-
string.gsub(/\n/, " ").
|
28
|
-
scan(/(?<=Shipped By Tracking Number).*(?=\<http)/)
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
shipping_info_block = string.gsub(/\n/, " ").
|
38
|
+
scan(/(?<=Shipped By Tracking Number).*(?=\<http)/)
|
39
|
+
|
40
|
+
if shipping_info_block.any?
|
41
|
+
shipping_info_block.first.
|
42
|
+
strip.
|
43
|
+
split(" ")
|
44
|
+
else
|
45
|
+
["Unavailable", "Unavailable"]
|
46
|
+
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
data/lib/reelagram/version.rb
CHANGED
@@ -22,6 +22,26 @@ class ShippingParserTest < MiniTest::Unit::TestCase
|
|
22
22
|
assert_equal("92748999982943513015002409", parsed_string.tracking_number)
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_tracking_link_returns_the_tracking_link
|
26
|
+
parsed_string = parser.run(data)
|
27
|
+
assert_equal("http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=92748999982943513015002409&track.x=Track%20target=", parsed_string.tracking_link)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_when_there_is_no_shipping_information_link_is_unavailable
|
31
|
+
parsed_string = parser.run(no_shipping_data)
|
32
|
+
assert_equal(nil, parsed_string.tracking_link)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_when_there_is_no_shipping_information_carrier_is_unavailable
|
36
|
+
parsed_string = parser.run(no_shipping_data)
|
37
|
+
assert_equal("Unavailable", parsed_string.carrier)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_when_there_is_no_shipping_information_tracking_number_is_unavailable
|
41
|
+
parsed_string = parser.run(no_shipping_data)
|
42
|
+
assert_equal("Unavailable", parsed_string.tracking_number)
|
43
|
+
end
|
44
|
+
|
25
45
|
def parser
|
26
46
|
@parser ||= Reelagram::Mail::Parsers::ShippingParser.new
|
27
47
|
end
|
@@ -29,4 +49,8 @@ class ShippingParserTest < MiniTest::Unit::TestCase
|
|
29
49
|
def data
|
30
50
|
FixtureHelper.fixture("email_body.txt")
|
31
51
|
end
|
52
|
+
|
53
|
+
def no_shipping_data
|
54
|
+
""
|
55
|
+
end
|
32
56
|
end
|
@@ -16,9 +16,10 @@ class ShippingUpdateProcessorTest < MiniTest::Unit::TestCase
|
|
16
16
|
parsed_data = {
|
17
17
|
order_id: "7780000265",
|
18
18
|
carrier: "United States Postal Service",
|
19
|
-
tracking_number: "92748999982943513015002409"
|
19
|
+
tracking_number: "92748999982943513015002409",
|
20
|
+
tracking_link: "http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=92748999982943513015002409&track.x=Track%20target="
|
20
21
|
}
|
21
|
-
assert_equal(parsed_data, processor.run
|
22
|
+
assert_equal([parsed_data], processor.run)
|
22
23
|
end
|
23
24
|
|
24
25
|
def parser
|