ups 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d62618324bb4d42efc9229e45d8aadf4b797d57f56849bb4687d8506797b74e5
4
- data.tar.gz: bf5f9c912258731ecafaa692ac373a53b41ac762bcde6bdf4f71bf9777f320c7
3
+ metadata.gz: 35bf9beb313035a44c0368e0e6e56a4b0092b8db9b7c174352a753afada6e86b
4
+ data.tar.gz: 9bc83318963bdb23e80ff441ded0b570b86e1ffe842e0d0d301e13aceaef842d
5
5
  SHA512:
6
- metadata.gz: 03237a9fb524ca471fc2d224edff0a8fda897f940d3eabc2d1d23f47ecf93a00e271b457946fdfa5302887fb17c6fb7e5b3b1d21ef080fd1f2a008c07d4e5dba
7
- data.tar.gz: 9ac07d0a408b817931f3fd46112f7871a56f207f2b2430bf727e804170e853459397cfce8eaf75dcedd59de6afc335d2d92ce90378aefa656d9e66b0024715a0
6
+ metadata.gz: b7b24ffd26fc3c9a04d86dc20c82c6000d114459917c8ceaf6cd30283fd6c1b07402ab6e6421648077365f4154127ffc64419dd8c7b7d006125a2e6d848a2101
7
+ data.tar.gz: 70fe24d8d6b75f2eaca7cc73a2c5d29d438a69c531adf5f3b68dbfda1ace11af8f9ef060bc502e31e172edc416b301bb13bba1852b1dad90c087129e4db4fcfd
@@ -2,8 +2,9 @@ module Ups
2
2
  class Configuration
3
3
  attr_accessor :client_id, :client_secret, :account_number, :sandbox
4
4
 
5
- def initialize
5
+ def initialize(params = {})
6
6
  @sandbox = true
7
+ params.map{|k, v| send("#{k}=", v) if respond_to?("#{k}=") }
7
8
  end
8
9
 
9
10
  def base_url
@@ -1,6 +1,6 @@
1
1
  module Ups
2
2
  class Package
3
- attr_accessor :description, :packaging_type, :length, :width, :height, :weight, :dimension_unit, :weight_unit, :value
3
+ attr_accessor :description, :packaging_type, :length, :width, :height, :weight, :dimension_unit, :weight_unit, :insurance, :delivery_confirmation
4
4
 
5
5
  def initialize(attrs = {})
6
6
  attrs.map{|k,v| send("#{k}=", v) if respond_to?("#{k}=") }
@@ -1,6 +1,6 @@
1
1
  module Ups
2
2
  class RateRequest
3
- attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference, :dcis_type
3
+ attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference
4
4
 
5
5
  def initialize(attrs = {})
6
6
  attrs.map{|k, v| send("#{k}=", v) if respond_to?("#{k}=") }
@@ -1,6 +1,6 @@
1
1
  module Ups
2
2
  class ShipRequest
3
- attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference, :description, :label_format, :dcis_type
3
+ attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference, :description, :label_format
4
4
 
5
5
  def initialize(attrs = {})
6
6
  attrs.map{|k, v| send("#{k}=", v) if respond_to?("#{k}=") }
data/lib/ups/rating.rb CHANGED
@@ -48,7 +48,7 @@ module Ups
48
48
  }
49
49
  }
50
50
  },
51
- Package: rate_request.packages.map { |pkg| package_hash(pkg, dcis_type: rate_request.dcis_type) },
51
+ Package: rate_request.packages.map { |pkg| package_hash(pkg) },
52
52
  Service: {
53
53
  Code: rate_request.service_code || "03"
54
54
  }
@@ -67,7 +67,7 @@ module Ups
67
67
  }
68
68
  end
69
69
 
70
- def package_hash(package, dcis_type: 3)
70
+ def package_hash(package)
71
71
  base = {
72
72
  PackagingType: {
73
73
  Code: package.packaging_type || "02"
@@ -89,15 +89,24 @@ module Ups
89
89
  PackageServiceOptions: {
90
90
  DeclaredValue: {
91
91
  CurrencyCode: "USD",
92
- MonetaryValue: package.value
92
+ MonetaryValue: package.insurance
93
93
  }
94
94
  }
95
95
  }
96
- base.deep_merge!(signature_required(dcis_type)) if [2,3].include?(dcis_type.to_i)
96
+ base.deep_merge!(signature_required(package.delivery_confirmation)) if [2,3].include?(package&.delivery_confirmation.to_i)
97
97
  base
98
98
  end
99
99
 
100
- def signature_required(type = '3')
100
+ def signature_required(type)
101
+ # https://github.com/UPS-API/api-documentation/blob/main/Rating.yaml
102
+ # DCISType fails if the value is nil, 0, or 1...
103
+ # but 2 and 3 work as expected. So we need to omit
104
+ # the key altogether if the value is not one of 2 or 3.
105
+ # {
106
+ # 1 => 'Unsupported', # this fails for some reason, so ignore it
107
+ # 2 => 'Delivery Confirmation Signature Required',
108
+ # 3 => 'Delivery Confirmation Adult Signature Required'
109
+ # }
101
110
  {
102
111
  PackageServiceOptions: {
103
112
  DeliveryConfirmation: {
data/lib/ups/shipping.rb CHANGED
@@ -66,7 +66,7 @@ module Ups
66
66
  Code: ship_request.service_code || "02",
67
67
  Description: "Service Code"
68
68
  },
69
- Package: ship_request.packages.map { |pkg| package_hash(pkg, dcis_type: ship_request.dcis_type) }
69
+ Package: ship_request.packages.map { |pkg| package_hash(pkg) }
70
70
  },
71
71
  LabelSpecification: {
72
72
  LabelImageFormat: {
@@ -88,7 +88,7 @@ module Ups
88
88
  }
89
89
  end
90
90
 
91
- def package_hash(package, dcis_type: 3)
91
+ def package_hash(package)
92
92
  base = {
93
93
  Description: package.description || "Package",
94
94
  Packaging: {
@@ -111,15 +111,15 @@ module Ups
111
111
  PackageServiceOptions: {
112
112
  DeclaredValue: {
113
113
  CurrencyCode: "USD",
114
- MonetaryValue: package.value
114
+ MonetaryValue: package.insurance
115
115
  }
116
116
  },
117
117
  InsuredValue: {
118
118
  CurrencyCode: "USD",
119
- MonetaryValue: package.value
119
+ MonetaryValue: package.insurance
120
120
  }
121
121
  }
122
- base.deep_merge!(signature_required(dcis_type)) if [2,3].include?(dcis_type.to_i)
122
+ base.deep_merge!(signature_required(package.delivery_confirmation)) if [2,3].include?(package&.delivery_confirmation.to_i)
123
123
  base
124
124
  end
125
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Warren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-13 00:00:00.000000000 Z
11
+ date: 2025-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty