ups 0.0.2 → 0.0.4

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: 31c3c330095fb77264cc9f1d7b63060d72862cc51c76ff0dd71e561319d50477
4
- data.tar.gz: bc9d453d32e0d1e4a1a0829629e753dea696166d164ca4eadc6740138bf9c1e9
3
+ metadata.gz: 6f299fda5bfe8460f0531eb9d9e63415485e2cbbcd765a354987b4fde149c6e3
4
+ data.tar.gz: 0fac23629a457243445d9dffd7f88fcb30aece68d93c1abce23712295289b121
5
5
  SHA512:
6
- metadata.gz: 1385e2e5bb4142356857948230f60ee54243003361becb9a85badc8a819d923d981c78004e2a5d42e2074909371ba8aab199e63aee1ceb3c4e92ebfe5b14eee8
7
- data.tar.gz: 1a2ebcc5cde6664a6214b24abe58c4fe16d32d48a3c35cd00fdbd0084ec0409b0d362e0f8b13978085f487f21e3ec643c374b2c9ece299825019c0c5759eb967
6
+ metadata.gz: f1248beb741ad2d3761602dd0f3e24794d480d90d7e35622572eb096b03b86694cfbf49dbc7934687125e19a3a3f2ff57c4042e25510d67e0d04c05468268e4b
7
+ data.tar.gz: fd11af41e93dcb64e62d44c0602181ad774b805ad7a38c1ac374663d1c283b6c4ee241d2a859b88c1fd25f046a45d75bb37aa87605d420ff29f7c3dc695a06ea
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A Ruby wrapper for the UPS Shipping API that allows you to get shipping rates and create shipping labels.
4
4
 
5
+ This gem handles the new OAuth flow in the UPS API that retrieves a JWT first to make requests with. It will allow you to fetch rates for a given package and purchase a shipping label.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -13,6 +15,8 @@ gem 'ups'
13
15
  ## Configuration
14
16
 
15
17
  ```ruby
18
+ # config/initializers/ups.rb
19
+
16
20
  Ups.configure do |config|
17
21
  config.client_id = Rails.application.credentials.ups.client_id
18
22
  config.client_secret = Rails.application.credentials.ups.client_secret
@@ -47,7 +51,7 @@ ship_to = Ups::Address.new(
47
51
  )
48
52
 
49
53
  # Create package
50
- package = Ups:Package.new(
54
+ package = Ups::Package.new(
51
55
  length: 10,
52
56
  width: 8,
53
57
  height: 6,
@@ -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}=") }
data/lib/ups/rating.rb CHANGED
@@ -48,11 +48,6 @@ module Ups
48
48
  }
49
49
  }
50
50
  },
51
- # ShipmentServiceOptions: {
52
- # DeliveryConfirmation: {
53
- # DCISType: rate_request.dcis_type || 0 # "2" = Signature Required
54
- # }
55
- # },
56
51
  Package: rate_request.packages.map { |pkg| package_hash(pkg) },
57
52
  Service: {
58
53
  Code: rate_request.service_code || "03"
@@ -73,7 +68,7 @@ module Ups
73
68
  end
74
69
 
75
70
  def package_hash(package)
76
- {
71
+ base = {
77
72
  PackagingType: {
78
73
  Code: package.packaging_type || "02"
79
74
  },
@@ -94,7 +89,28 @@ module Ups
94
89
  PackageServiceOptions: {
95
90
  DeclaredValue: {
96
91
  CurrencyCode: "USD",
97
- MonetaryValue: package.value
92
+ MonetaryValue: package.insurance
93
+ }
94
+ }
95
+ }
96
+ base.deep_merge!(signature_required(package.delivery_confirmation)) if [2,3].include?(package&.delivery_confirmation.to_i)
97
+ base
98
+ end
99
+
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
+ # }
110
+ {
111
+ PackageServiceOptions: {
112
+ DeliveryConfirmation: {
113
+ DCISType: type.to_s
98
114
  }
99
115
  }
100
116
  }
data/lib/ups/shipping.rb CHANGED
@@ -89,7 +89,7 @@ module Ups
89
89
  end
90
90
 
91
91
  def package_hash(package)
92
- {
92
+ base = {
93
93
  Description: package.description || "Package",
94
94
  Packaging: {
95
95
  Code: package.packaging_type || "02"
@@ -107,6 +107,28 @@ module Ups
107
107
  Code: package.weight_unit || "LBS"
108
108
  },
109
109
  Weight: package.weight.to_s
110
+ },
111
+ PackageServiceOptions: {
112
+ DeclaredValue: {
113
+ CurrencyCode: "USD",
114
+ MonetaryValue: package.insurance
115
+ }
116
+ },
117
+ InsuredValue: {
118
+ CurrencyCode: "USD",
119
+ MonetaryValue: package.insurance
120
+ }
121
+ }
122
+ base.deep_merge!(signature_required(package.delivery_confirmation)) if [2,3].include?(package&.delivery_confirmation.to_i)
123
+ base
124
+ end
125
+
126
+ def signature_required(type = '3')
127
+ {
128
+ PackageServiceOptions: {
129
+ DeliveryConfirmation: {
130
+ DCISType: type.to_s
131
+ }
110
132
  }
111
133
  }
112
134
  end
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.2
4
+ version: 0.0.4
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-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty