fuel_surcharge 1.2.1 → 1.2.2

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
  SHA256:
3
- metadata.gz: f68cb01ef88675ef0ca5094c6ea5712cb669b111d4ec25c902fe6a2a4eaffc1d
4
- data.tar.gz: 5fa8a822c054f84fa35b3180b9d8b439d953a7f87f3a24d4f38b3c49ac593945
3
+ metadata.gz: a6db529ef07a052e6406c2cc32c414bfd6a8cca577ab239c78bb3622cb326a93
4
+ data.tar.gz: 29f736220eb3c8c7ef87a02ae2c02a9812f280cf4c0a9590adaffb76df02a26b
5
5
  SHA512:
6
- metadata.gz: ea6cc3b909404bd3020fd6bea0e7c9f06988ee3beee2c6ea39a547d9571e19e84ba1cc1879bd1efb6e8f5922535eec01ad6c814a62a599768520f67aea9b1272
7
- data.tar.gz: e295ab64de727767269256b972f4ba5d627734c4f9a5f479b4c8eedf6bb94330ea26803dc77018978d5cbb9dfda14eb8eea2cf577f953e39cd8d9b466d8646d4
6
+ metadata.gz: 9775e48cea5cf6b9aa79fb078e75480d8545a9716ec7a8daa3865468ddcf1a7410043da62249baa43dd2cfe0423e5591a6c1d54e28879d9621684cd2f062cfa2
7
+ data.tar.gz: 2bb3b0601f7331ba9b27ca87b2bdc0c2119cee206729e79119248ec070ca132622ca7ac09cb9e7ae365dfa9e4dc4a650b9f1aa7f62ecc9e0e13298a790cc4a93
@@ -1 +1 @@
1
- future-release=1.2.1
1
+ future-release=1.2.2
data/CHANGELOG.md CHANGED
@@ -1,7 +1,18 @@
1
1
  # Change Log
2
2
 
3
- ## [1.2.1](https://github.com/levups/fuel_surcharge/tree/1.2.1) (2019-07-22)
4
- [Full Changelog](https://github.com/levups/fuel_surcharge/compare/v1.2.0...1.2.1)
3
+ ## [1.2.2](https://github.com/levups/fuel_surcharge/tree/1.2.2) (2019-08-01)
4
+ [Full Changelog](https://github.com/levups/fuel_surcharge/compare/v1.2.1...1.2.2)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - TNT website change, again… [\#58](https://github.com/levups/fuel_surcharge/issues/58)
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Correct TNT website parsing [\#59](https://github.com/levups/fuel_surcharge/pull/59) ([bobmaerten](https://github.com/bobmaerten))
13
+
14
+ ## [v1.2.1](https://github.com/levups/fuel_surcharge/tree/v1.2.1) (2019-07-22)
15
+ [Full Changelog](https://github.com/levups/fuel_surcharge/compare/v1.2.0...v1.2.1)
5
16
 
6
17
  **Fixed bugs:**
7
18
 
@@ -9,6 +20,7 @@
9
20
 
10
21
  **Merged pull requests:**
11
22
 
23
+ - Release v1.2.1 [\#57](https://github.com/levups/fuel_surcharge/pull/57) ([bobmaerten](https://github.com/bobmaerten))
12
24
  - Adapt to TNT / Chronopost website structure changes [\#56](https://github.com/levups/fuel_surcharge/pull/56) ([bobmaerten](https://github.com/bobmaerten))
13
25
  - Bump rake from 12.3.2 to 12.3.3 [\#54](https://github.com/levups/fuel_surcharge/pull/54) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
14
26
  - Update standard requirement from ~\> 0.0.39 to ~\> 0.1.0 [\#53](https://github.com/levups/fuel_surcharge/pull/53) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fuel_surcharge (1.2.1)
4
+ fuel_surcharge (1.2.2)
5
5
  http (~> 4.0)
6
6
 
7
7
  GEM
@@ -8,10 +8,10 @@ module FuelSurcharge
8
8
  @scanner = StringScanner.new(source.to_s)
9
9
  end
10
10
 
11
- def upcoming(tag)
11
+ def upcoming(tag, attribute = nil)
12
12
  return if @scanner.eos?
13
13
 
14
- opening = "<#{tag}[^>]*>"
14
+ opening = attribute ? "<#{tag}\s[^>]*#{attribute}[^>]*>" : "<#{tag}[^>]*>"
15
15
  closing = "</#{tag}>"
16
16
  return unless @scanner.exist?(/#{opening}/) && @scanner.exist?(/#{closing}/)
17
17
 
@@ -22,11 +22,11 @@ module FuelSurcharge
22
22
  chunk[0...chunk.size - closing.size].strip
23
23
  end
24
24
 
25
- def all(tag)
25
+ def all(tag, attribute = nil)
26
26
  chunks = []
27
27
  return chunks if @scanner.eos?
28
28
 
29
- while (chunk = upcoming(tag))
29
+ while (chunk = upcoming(tag, attribute))
30
30
  chunks << chunk
31
31
  end
32
32
  chunks
@@ -16,7 +16,9 @@ module FuelSurcharge
16
16
  end
17
17
 
18
18
  def air_percentage
19
- air_value&.last&.to_s
19
+ if (value = air_value&.dig("list", 0, "surcharge"))
20
+ value.tr(".", ",") << "%"
21
+ end
20
22
  end
21
23
 
22
24
  def road_multiplier
@@ -33,21 +35,29 @@ module FuelSurcharge
33
35
 
34
36
  private
35
37
 
36
- ROAD_VALUES_REGEX = /Surcharge d[e\' ]+ (\w+ \d{4}) : (.+%)</.freeze
37
- AIR_VALUES_REGEX = /Surcharge du \d+ au \d+ (\w+ \d{4}) : (.*%)</.freeze
38
+ def json_air_url
39
+ "https://www.tnt.com/express/getDynamicData.europe.json"
40
+ end
38
41
 
39
42
  def air_value
40
- response.to_s.scan(AIR_VALUES_REGEX).first
43
+ return if (json = air_response.to_s).empty?
44
+
45
+ JSON.parse(json)
41
46
  end
42
47
 
48
+ ROAD_VALUES_REGEX = /Surcharge d[e\' ]+ (\w+ \d{4}) : (.+%)</.freeze
43
49
  def road_value
44
- response.to_s.scan(ROAD_VALUES_REGEX).first
50
+ road_response.to_s.scan(ROAD_VALUES_REGEX).first
45
51
  end
46
52
 
47
- def response
53
+ def road_response
48
54
  @response ||= HTTPRequest.new(url).response
49
55
  end
50
56
 
57
+ def air_response
58
+ @air_response ||= HTTPRequest.new(json_air_url).response
59
+ end
60
+
51
61
  FRENCH_MONTHS_NAMES = %w[
52
62
  janvier
53
63
  février
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FuelSurcharge
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuel_surcharge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Maerten
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-07-22 00:00:00.000000000 Z
12
+ date: 2019-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http