ups 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +5 -1
- data/lib/ups/models/ship_request.rb +1 -1
- data/lib/ups/rating.rb +15 -8
- data/lib/ups/shipping.rb +25 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d62618324bb4d42efc9229e45d8aadf4b797d57f56849bb4687d8506797b74e5
|
4
|
+
data.tar.gz: bf5f9c912258731ecafaa692ac373a53b41ac762bcde6bdf4f71bf9777f320c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03237a9fb524ca471fc2d224edff0a8fda897f940d3eabc2d1d23f47ecf93a00e271b457946fdfa5302887fb17c6fb7e5b3b1d21ef080fd1f2a008c07d4e5dba
|
7
|
+
data.tar.gz: 9ac07d0a408b817931f3fd46112f7871a56f207f2b2430bf727e804170e853459397cfce8eaf75dcedd59de6afc335d2d92ce90378aefa656d9e66b0024715a0
|
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
|
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 ShipRequest
|
3
|
-
attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference, :description, :label_format
|
3
|
+
attr_accessor :shipper, :ship_to, :ship_from, :packages, :service_code, :reference, :description, :label_format, :dcis_type
|
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,12 +48,7 @@ module Ups
|
|
48
48
|
}
|
49
49
|
}
|
50
50
|
},
|
51
|
-
|
52
|
-
# DeliveryConfirmation: {
|
53
|
-
# DCISType: rate_request.dcis_type || 0 # "2" = Signature Required
|
54
|
-
# }
|
55
|
-
# },
|
56
|
-
Package: rate_request.packages.map { |pkg| package_hash(pkg) },
|
51
|
+
Package: rate_request.packages.map { |pkg| package_hash(pkg, dcis_type: rate_request.dcis_type) },
|
57
52
|
Service: {
|
58
53
|
Code: rate_request.service_code || "03"
|
59
54
|
}
|
@@ -72,8 +67,8 @@ module Ups
|
|
72
67
|
}
|
73
68
|
end
|
74
69
|
|
75
|
-
def package_hash(package)
|
76
|
-
{
|
70
|
+
def package_hash(package, dcis_type: 3)
|
71
|
+
base = {
|
77
72
|
PackagingType: {
|
78
73
|
Code: package.packaging_type || "02"
|
79
74
|
},
|
@@ -98,6 +93,18 @@ module Ups
|
|
98
93
|
}
|
99
94
|
}
|
100
95
|
}
|
96
|
+
base.deep_merge!(signature_required(dcis_type)) if [2,3].include?(dcis_type.to_i)
|
97
|
+
base
|
98
|
+
end
|
99
|
+
|
100
|
+
def signature_required(type = '3')
|
101
|
+
{
|
102
|
+
PackageServiceOptions: {
|
103
|
+
DeliveryConfirmation: {
|
104
|
+
DCISType: type.to_s
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
101
108
|
end
|
102
109
|
|
103
110
|
def parse_rate_response(response)
|
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) }
|
69
|
+
Package: ship_request.packages.map { |pkg| package_hash(pkg, dcis_type: ship_request.dcis_type) }
|
70
70
|
},
|
71
71
|
LabelSpecification: {
|
72
72
|
LabelImageFormat: {
|
@@ -88,8 +88,8 @@ module Ups
|
|
88
88
|
}
|
89
89
|
end
|
90
90
|
|
91
|
-
def package_hash(package)
|
92
|
-
{
|
91
|
+
def package_hash(package, dcis_type: 3)
|
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.value
|
115
|
+
}
|
116
|
+
},
|
117
|
+
InsuredValue: {
|
118
|
+
CurrencyCode: "USD",
|
119
|
+
MonetaryValue: package.value
|
120
|
+
}
|
121
|
+
}
|
122
|
+
base.deep_merge!(signature_required(dcis_type)) if [2,3].include?(dcis_type.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
|