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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f532e3091b4614a9d3a4747940fc1f80a3db8d8d
4
- data.tar.gz: 07852a02a3c71e74f068dea4c5ba8b63831d7eb0
3
+ metadata.gz: 08eb5c9c91316ad4f51bc73ae30529becc999712
4
+ data.tar.gz: 6494edc93363360c9c0dcc43194eb808b69d8033
5
5
  SHA512:
6
- metadata.gz: 67449468deaabd7995bbf4da5da5b18bb6eca96bad69dcbe320f6eb4ef425ee4d800b06f5659fd3bab27257a0d8a1f3d402762299f4621c682e3cccc2f6cfe9e
7
- data.tar.gz: df18a169d4a0176194ccb204c278d367fb3259d6b6b9ac9d618d66f73765f29eae26403d707db9f271ccf00163bd18f3cb95dba670af59ccb7e2fd6ea04215be
6
+ metadata.gz: 57c50a3f424325adc1aeb7ddf4319f957508805e6a0713d3712966a93022d74e99027faa8fa3d1dec7dabc8f968499af1cccf2cf58c49703cc7dc2c750a5694d
7
+ data.tar.gz: ef27f6bde615cd71c8302dd61114d39c75dc4730a95b3ce24cef2fd0e223379d17f455b9eb0e88a96b945fa573f63fa60894f587c7040ca80824e340f1a11dc6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reelagram-mail (0.0.2)
4
+ reelagram-mail (0.0.3)
5
5
  ruby-gmail (= 0.3.1)
6
6
 
7
7
  GEM
@@ -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
- first.
30
- strip.
31
- split(" ")
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
@@ -25,7 +25,8 @@ module Reelagram
25
25
  {
26
26
  order_id: email.order_number,
27
27
  carrier: email.carrier,
28
- tracking_number: email.tracking_number
28
+ tracking_number: email.tracking_number,
29
+ tracking_link: email.tracking_link
29
30
  }
30
31
  end
31
32
  end
@@ -1,3 +1,3 @@
1
1
  module Reelagram
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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.first)
22
+ assert_equal([parsed_data], processor.run)
22
23
  end
23
24
 
24
25
  def parser
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reelagram-mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Wheeler