friendly_shipping 0.6.4 → 0.6.5

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: 107fa27ec95b49342549dbf24c53cc483cd05bdfbb64871940036aaac6567eb6
4
- data.tar.gz: 7dd9c281178e513482ae0cb93787eb551b09e5f697f10d4db50dc2aef21dd4a8
3
+ metadata.gz: 921ae3f517c9fcf14e7932e110b6468d7bf2b78e46864bb50a3272b6257e2bea
4
+ data.tar.gz: d7cf64cc30bedd17adca882b9365f647498f8c4430f59e0a4fe1a00efe1ac017
5
5
  SHA512:
6
- metadata.gz: 30c37297f77dc6be490cf9719211780b81b0d91cdc49311b349fc3844a6cbcb5755265e663b80e24a67cda9847e19d328808cec786cf7172d6986ccb75bbf6eb
7
- data.tar.gz: 022c69680c07d9fed0b2b9afa8093e40b20bb7b441b332acd743078f74db70f3de03227953952de8b08048aa40eb902895529c781b6332036cf4e38ba653804e
6
+ metadata.gz: 9080b93ddde6399677499cb65e6b1a184985af772067548b45c977fd6d8744c9c6a08899c2b27426e3fcd795b13950141d017183c40aa25026d7cb3bf2eeb120
7
+ data.tar.gz: 413036408bfc7852a141c1b19e557b7533ca3288b371e6f5e09d78da279ef470bd764c9c46de145fbc6a079de9b18b858cb5bff75b972d3bed76ce4a946a2626
data/CHANGELOG.md CHANGED
@@ -4,22 +4,29 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [0.6.4] - 2021-01-27
7
+ ## [0.6.5] - 2022-04-25
8
8
 
9
9
  ### Added
10
+ - USPS Service: Add support for returned dimensional weight (#128)
11
+ - USPS Service: Add support for returned fees (#127)
12
+
13
+ ### Changed
14
+ - ShipEngine Service: Prevent exceptions when no rates are returned (#125)
15
+ - Misc dependency updates (#116, #120, #121, #124)
16
+
17
+ ## [0.6.4] - 2021-01-27
10
18
 
19
+ ### Added
11
20
  - UPS Service: Include negotiated charges for UPS (#119)
12
21
  - UPS Service: Include shipment-level itemized charges (#117)
13
22
 
14
23
  ## [0.6.3] - 2020-10-30
15
24
 
16
25
  ### Added
17
-
18
26
  - USPS Service: Append HFP (Hold For Pickup) to service code when necessary (#110)
19
27
  - USPS Service: Add Priority Cubic shipping method (#113)
20
28
 
21
29
  ### Changed
22
-
23
30
  - USPS Service: Refactor to use explicit service codes (#111)
24
31
  - USPS Service: Match Priority Express by CLASSID instead of service name (#112)
25
32
  - UPS Service: Rename peak surcharge keys to match UPS docs (#114)
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_runtime_dependency "data_uri", "~> 0.0.3"
25
+ spec.add_runtime_dependency "data_uri", ">= 0.0.3", "< 0.2.0"
26
26
  spec.add_runtime_dependency "dry-monads", "~> 1.0"
27
27
  spec.add_runtime_dependency "money", "~> 6.0"
28
28
  spec.add_runtime_dependency "nokogiri", "~> 1.6"
@@ -30,15 +30,15 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency "rest-client", "~> 2.0"
31
31
  spec.required_ruby_version = '>= 2.5'
32
32
 
33
- spec.add_development_dependency "bundler", ">= 1.17", "< 3"
33
+ spec.add_development_dependency "bundler", ">= 2.1.4", "< 3"
34
34
  spec.add_development_dependency "dotenv", "~> 2.7"
35
- spec.add_development_dependency "factory_bot", "~> 5.0"
35
+ spec.add_development_dependency "factory_bot", "~> 6.2"
36
36
  spec.add_development_dependency "pry", "~> 0.12"
37
37
  spec.add_development_dependency "rake", ">= 12.3.3"
38
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
39
  spec.add_development_dependency "rspec_junit_formatter", "~> 0.4"
40
40
  spec.add_development_dependency "rubocop", ">= 0.80", "< 1"
41
41
  spec.add_development_dependency "simplecov", "~> 0.17"
42
- spec.add_development_dependency "vcr", "~> 5.0"
42
+ spec.add_development_dependency "vcr", "~> 6.0"
43
43
  spec.add_development_dependency "webmock", "~> 3.6"
44
44
  end
@@ -10,8 +10,14 @@ module FriendlyShipping
10
10
 
11
11
  class << self
12
12
  def call(response:, request:, options:)
13
+ error_messages = []
13
14
  parsed_json = JSON.parse(response.body)
14
15
  rates = parsed_json.map do |rate|
16
+ if rate['validation_status'] == 'invalid'
17
+ error_messages.concat rate['error_messages']
18
+ next
19
+ end
20
+
15
21
  carrier = options.carriers.detect { |c| c.id == rate['carrier_id'] }
16
22
  next unless carrier
17
23
 
@@ -31,17 +37,33 @@ module FriendlyShipping
31
37
  )
32
38
  end.compact
33
39
 
34
- Success(
35
- ApiResult.new(
36
- rates,
37
- original_request: request,
38
- original_response: response
40
+ if valid_rates(parsed_json)
41
+ Success(
42
+ ApiResult.new(
43
+ rates,
44
+ original_request: request,
45
+ original_response: response
46
+ )
47
+ )
48
+ else
49
+ Failure(
50
+ ApiFailure.new(
51
+ error_messages,
52
+ original_request: request,
53
+ original_response: response
54
+ )
39
55
  )
40
- )
56
+ end
41
57
  end
42
58
 
43
59
  private
44
60
 
61
+ def valid_rates(parsed_json)
62
+ parsed_json.map do |rate|
63
+ ["valid", "has_warnings", "unknown"].include? rate['validation_status']
64
+ end.any?
65
+ end
66
+
45
67
  def get_amounts(rate_hash)
46
68
  [:shipping, :other, :insurance, :confirmation].map do |name|
47
69
  currency = Money::Currency.new(rate_hash["#{name}_amount"]["currency"])
@@ -55,6 +55,8 @@ module FriendlyShipping
55
55
  RATE_TAG = 'Rate'
56
56
  COMMERCIAL_RATE_TAG = 'CommercialRate'
57
57
  COMMERCIAL_PLUS_RATE_TAG = 'CommercialPlusRate'
58
+ DIMENSIONAL_WEIGHT_RATE = 'DimensionalWeightRate'
59
+ FEES = './/Fees/Fee'
58
60
  CURRENCY = Money::Currency.new('USD').freeze
59
61
 
60
62
  class << self
@@ -119,6 +121,17 @@ module FriendlyShipping
119
121
  box_name_match = service_name.match(/#{BOX_REGEX}/)
120
122
  box_name = box_name_match ? box_name_match.named_captures.compact.keys.last.to_sym : :variable
121
123
 
124
+ dimensional_weight_rate = rate_node.at(DIMENSIONAL_WEIGHT_RATE)&.text&.to_i
125
+
126
+ fees = rate_node.xpath(FEES).map do |fee_node|
127
+ type = fee_node.at('FeeType').text
128
+ price = fee_node.at('FeePrice').text.to_d
129
+ {
130
+ type: type,
131
+ price: Money.new(price * CURRENCY.subunit_to_unit, CURRENCY)
132
+ }
133
+ end
134
+
122
135
  # Combine all the gathered information in a FriendlyShipping::Rate object.
123
136
  # Careful: This rate is only for one package within the shipment, and we get multiple
124
137
  # rates per package for the different shipping method/box/hold for pickup combinations.
@@ -132,7 +145,9 @@ module FriendlyShipping
132
145
  days_to_delivery: days_to_delivery,
133
146
  military: military,
134
147
  full_mail_service: service_name,
135
- service_code: service_code
148
+ service_code: service_code,
149
+ dimensional_weight_rate: dimensional_weight_rate,
150
+ fees: fees
136
151
  }
137
152
  )
138
153
  end
@@ -8,6 +8,8 @@ module FriendlyShipping
8
8
  #
9
9
  # @param [Symbol] box_name The type of box we want to get rates for. Has to be one of the keys
10
10
  # of FriendlyShipping::Services::Usps::CONTAINERS.
11
+ # @param [Symbol] return_dimensional_weight Boolean indicating whether the response should include dimensional weight.
12
+ # @param [Symbol] return_fees Boolean indicating whether the response should include fees.
11
13
  class Usps
12
14
  class RateEstimatePackageOptions < FriendlyShipping::PackageOptions
13
15
  attr_reader :box_name,
@@ -16,7 +18,9 @@ module FriendlyShipping
16
18
  :hold_for_pickup,
17
19
  :shipping_method,
18
20
  :transmit_dimensions,
19
- :rectangular
21
+ :rectangular,
22
+ :return_dimensional_weight,
23
+ :return_fees
20
24
 
21
25
  def initialize(
22
26
  box_name: :variable,
@@ -26,6 +30,8 @@ module FriendlyShipping
26
30
  shipping_method: nil,
27
31
  transmit_dimensions: true,
28
32
  rectangular: true,
33
+ return_dimensional_weight: true,
34
+ return_fees: false,
29
35
  **kwargs
30
36
  )
31
37
  @box_name = CONTAINERS.key?(box_name) ? box_name : :variable
@@ -35,6 +41,8 @@ module FriendlyShipping
35
41
  @shipping_method = shipping_method
36
42
  @transmit_dimensions = transmit_dimensions
37
43
  @rectangular = rectangular
44
+ @return_dimensional_weight = return_dimensional_weight
45
+ @return_fees = return_fees
38
46
  super kwargs
39
47
  end
40
48
 
@@ -46,6 +46,8 @@ module FriendlyShipping
46
46
  end
47
47
  end
48
48
  xml.Machinable(machinable(package))
49
+ xml.ReturnDimensionalWeight(true) if package_options.return_dimensional_weight
50
+ xml.ReturnFees(true) if package_options.return_fees
49
51
  end
50
52
  end
51
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyShipping
4
- VERSION = "0.6.4"
4
+ VERSION = "0.6.5"
5
5
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_shipping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2022-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: data_uri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.0.3
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.0.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: dry-monads
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +112,7 @@ dependencies:
106
112
  requirements:
107
113
  - - ">="
108
114
  - !ruby/object:Gem::Version
109
- version: '1.17'
115
+ version: 2.1.4
110
116
  - - "<"
111
117
  - !ruby/object:Gem::Version
112
118
  version: '3'
@@ -116,7 +122,7 @@ dependencies:
116
122
  requirements:
117
123
  - - ">="
118
124
  - !ruby/object:Gem::Version
119
- version: '1.17'
125
+ version: 2.1.4
120
126
  - - "<"
121
127
  - !ruby/object:Gem::Version
122
128
  version: '3'
@@ -140,14 +146,14 @@ dependencies:
140
146
  requirements:
141
147
  - - "~>"
142
148
  - !ruby/object:Gem::Version
143
- version: '5.0'
149
+ version: '6.2'
144
150
  type: :development
145
151
  prerelease: false
146
152
  version_requirements: !ruby/object:Gem::Requirement
147
153
  requirements:
148
154
  - - "~>"
149
155
  - !ruby/object:Gem::Version
150
- version: '5.0'
156
+ version: '6.2'
151
157
  - !ruby/object:Gem::Dependency
152
158
  name: pry
153
159
  requirement: !ruby/object:Gem::Requirement
@@ -244,14 +250,14 @@ dependencies:
244
250
  requirements:
245
251
  - - "~>"
246
252
  - !ruby/object:Gem::Version
247
- version: '5.0'
253
+ version: '6.0'
248
254
  type: :development
249
255
  prerelease: false
250
256
  version_requirements: !ruby/object:Gem::Requirement
251
257
  requirements:
252
258
  - - "~>"
253
259
  - !ruby/object:Gem::Version
254
- version: '5.0'
260
+ version: '6.0'
255
261
  - !ruby/object:Gem::Dependency
256
262
  name: webmock
257
263
  requirement: !ruby/object:Gem::Requirement
@@ -412,7 +418,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
412
418
  - !ruby/object:Gem::Version
413
419
  version: '0'
414
420
  requirements: []
415
- rubygems_version: 3.0.3
421
+ rubygems_version: 3.1.6
416
422
  signing_key:
417
423
  specification_version: 4
418
424
  summary: An integration layer for shipping services