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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65a94a9ac25c80f8748a3673bcf2adcdc2781f28
4
- data.tar.gz: 42ef3adcb397cf19e1d8c6bfe1cc5dbad7eea2a5
3
+ metadata.gz: 6dafd98edae8423b5235bad33dc9fc937a2a0f31
4
+ data.tar.gz: dbba74e8936d1cacd2de5c724fdcc6a3d4ed10f8
5
5
  SHA512:
6
- metadata.gz: 14b67e3754f417bcd036b29ff0d7a41c2b9723527ea1c3bf29ea8c413b2720ce6a70d433614909e913229732baf33e3fe0c0c2031879939dec59a846ab4c7ebc
7
- data.tar.gz: baace5a087ae5a72663b9e227c205a343a26794fd37a77b879dad9d11c2d75e0ac7c67d25b92f1dc9706dbb2ee8896c555d7e8f40e79805f3a839ffe8903bda0
6
+ metadata.gz: d95bc1cca2ec8a521d9c3eb2952998624d6dc5d4a21c56a9a7193964b13d4ff10f984f4c2387e9c817bd69d80389d8b94cd86ca5f0be9ff2d1a2ae944ad05402
7
+ data.tar.gz: 22c95b4e55932f28f35fef27d14ea85dc3cb43ac53133f6e16b0eaa0f5b83083017611f25798539da01e9d9703276d2acee577bb2a9869eb088c51e0fa064d76
@@ -27,5 +27,10 @@ module Reelagram
27
27
  parser = Parsers::ShippingParser.new
28
28
  Processors::ShippingProcessor.new(emails, parser).run
29
29
  end
30
+
31
+ def self.debug?
32
+ false unless configured?
33
+ configuration.debug
34
+ end
30
35
  end
31
36
  end
@@ -2,6 +2,12 @@ module Reelagram
2
2
  module Mail
3
3
  class Configuration
4
4
  attr_accessor :email, :password
5
+ attr_accessor :debug, :test
6
+
7
+ def initialize
8
+ @test = false
9
+ @debug = false
10
+ end
5
11
 
6
12
  def configured?
7
13
  !email.nil? && !password.nil?
@@ -20,9 +20,10 @@ module Reelagram
20
20
 
21
21
  @email = Mail.configuration.email
22
22
  @password = Mail.configuration.password
23
- @label = options[:label] || self.class::DEFAULT_LABEL
24
- @after = options[:after]
25
- @save_path = options[:save_path] || "/tmp"
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
- if shipping_info_row
16
- @row.children[1].text
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
- if shipping_info_row
24
- @row.children[3].css("a").text
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
- if shipping_info_row
32
- begin
33
- @row.children[3]
34
- .css("a")
35
- .attr("href")
36
- .value
37
- rescue
38
- nil
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
- if table
46
- table.css("tr")
47
- .children.css("td")
48
- .children
49
- .text
50
- .gsub(/\\n+/, " ")
51
- .scan(/\w*/)
52
- .reject(&:empty?)
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
@@ -1,3 +1,3 @@
1
1
  module Reelagram
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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 = "foo@example.com"
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 # TODO stub this shit
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
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Wheeler