ups 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bbb686432266ab1abecf098744a453d0c1747eb51a40629335c6f7ce083475b
4
- data.tar.gz: fbe3f140f3c29831f21cc340fe272916d26efc9365183f01cdd6dceb8c06ea58
3
+ metadata.gz: d62618324bb4d42efc9229e45d8aadf4b797d57f56849bb4687d8506797b74e5
4
+ data.tar.gz: bf5f9c912258731ecafaa692ac373a53b41ac762bcde6bdf4f71bf9777f320c7
5
5
  SHA512:
6
- metadata.gz: 791b16e26b54f1e9f0a02353d73d0a4b84c89f459461334d20292341e4ba707ab569a249e617cdc5eaa69f99964177b358ea2f13bd58295998f5627dec871292
7
- data.tar.gz: 8483e06fa271c7a514b0d073a9763011f960b7df38d08843ff9d2760dc5fa457b9d5286b429718e39a082ca0002f232a0f63aa72ee0fbbadb7ca847a55c00460
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:Package.new(
54
+ package = Ups::Package.new(
51
55
  length: 10,
52
56
  width: 8,
53
57
  height: 6,
@@ -68,7 +72,7 @@ rating_service = Ups::Rating.new(Ups.client)
68
72
  rates = rating_service.get_rates(rate_request)
69
73
 
70
74
  rates.each do |rate|
71
- puts "#{rate[:service_name]}: $#{rate[:total_cost]} #{rate[:currency]}"
75
+ puts "#{rate[:service_name]}: $#{rate[:total]} #{rate[:currency]}"
72
76
  end
73
77
  ```
74
78
 
@@ -90,8 +94,8 @@ shipping_service = Ups::Shipping.new(Ups.client)
90
94
  result = shipping_service.create_shipment(ship_request)
91
95
 
92
96
  puts "Tracking Number: #{result[:tracking_number]}"
93
- puts "Total Cost: $#{result[:total_cost]} #{result[:currency]}"
94
- puts "Label URL: #{result[:label_url]}"
97
+ puts "Total Cost: $#{result[:total]} #{result[:currency]}"
98
+ puts "Label: #{result[:label]}"
95
99
  ```
96
100
 
97
101
  ## Service Codes
@@ -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
- # ShipmentServiceOptions: {
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
@@ -118,7 +140,7 @@ module Ups
118
140
  tracking_number: results['ShipmentIdentificationNumber'],
119
141
  label: results['PackageResults'][0]['ShippingLabel']['GraphicImage'],
120
142
  extension: results['PackageResults'][0]['ShippingLabel']['ImageFormat']['Code'],
121
- cost: results['ShipmentCharges']['TotalCharges']['MonetaryValue'].to_f,
143
+ total: results['ShipmentCharges']['TotalCharges']['MonetaryValue'].to_f,
122
144
  currency: results['ShipmentCharges']['TotalCharges']['CurrencyCode'],
123
145
  data: response.as_json(except: ["GraphicImage", "HTMLImage"]),
124
146
  alerts: response['ShipmentResponse']['Response']['Alert']&.map{|s| s['Description'] }
data/lib/ups/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Ups
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Warren