hermes_api 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -14
- data/hermes_api.gemspec +1 -1
- data/lib/hermes_api.rb +3 -2
- data/lib/hermes_api/bearer_token_setup.rb +23 -0
- data/lib/hermes_api/resources/json_base.rb +0 -20
- data/lib/hermes_api/resources/print_in_store_qr_code.rb +2 -2
- data/lib/hermes_api/resources/return_label.rb +33 -18
- data/lib/hermes_api/resources/tracking_event.rb +12 -0
- data/lib/hermes_api/resources/web_tracking.rb +29 -0
- data/lib/hermes_api/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfeafd10d08ea6ffa236a36b66d94dc11f3b7883931aade9995a93488d9a17e9
|
4
|
+
data.tar.gz: 3d4fb22d7d6f794988fedbefc1d79c384b744a13085fb9b9e6073fed00bd7638
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc203dac84c6484c990dcca4d2c070c083d8f0c588d465daa6c3de2eb0a02a0c2523376d9d30e9d37e2dc518c20b57b76c63c80070c5c45dc90404e6a5b46c8
|
7
|
+
data.tar.gz: 59160916b4fe767ead70309ef93f7c67c0392c577159ccde3f6d8fb8bded452194401db92781636cce250be07b614723461729d61fc9144fac4b153659051c45
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hermes_api (0.3.
|
4
|
+
hermes_api (0.3.1)
|
5
5
|
activeresource (>= 4.1.0, < 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -49,15 +49,11 @@ GEM
|
|
49
49
|
rspec (>= 2.99.0, < 4.0)
|
50
50
|
i18n (1.8.10)
|
51
51
|
concurrent-ruby (~> 1.0)
|
52
|
-
image_processing (1.12.1)
|
53
|
-
mini_magick (>= 4.9.5, < 5)
|
54
|
-
ruby-vips (>= 2.0.17, < 3)
|
55
52
|
listen (3.5.1)
|
56
53
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
57
54
|
rb-inotify (~> 0.9, >= 0.9.10)
|
58
55
|
lumberjack (1.2.8)
|
59
56
|
method_source (1.0.0)
|
60
|
-
mini_magick (4.11.0)
|
61
57
|
minitest (5.14.4)
|
62
58
|
nenv (0.3.0)
|
63
59
|
notiffany (0.1.3)
|
@@ -66,10 +62,6 @@ GEM
|
|
66
62
|
parallel (1.20.1)
|
67
63
|
parser (3.0.1.1)
|
68
64
|
ast (~> 2.4.1)
|
69
|
-
pdf-core (0.9.0)
|
70
|
-
prawn (2.4.0)
|
71
|
-
pdf-core (~> 0.9.0)
|
72
|
-
ttfunk (~> 1.7)
|
73
65
|
pry (0.14.1)
|
74
66
|
coderay (~> 1.1)
|
75
67
|
method_source (~> 1.0)
|
@@ -111,14 +103,11 @@ GEM
|
|
111
103
|
rubocop (>= 1.7.0, < 2.0)
|
112
104
|
rubocop-ast (>= 0.4.0)
|
113
105
|
ruby-progressbar (1.11.0)
|
114
|
-
ruby-vips (2.1.2)
|
115
|
-
ffi (~> 1.12)
|
116
106
|
shellany (0.0.1)
|
117
107
|
standard (1.1.3)
|
118
108
|
rubocop (= 1.18.1)
|
119
109
|
rubocop-performance (= 1.11.2)
|
120
110
|
thor (1.1.0)
|
121
|
-
ttfunk (1.7.0)
|
122
111
|
tzinfo (2.0.4)
|
123
112
|
concurrent-ruby (~> 1.0)
|
124
113
|
unicode-display_width (2.0.0)
|
@@ -132,8 +121,6 @@ DEPENDENCIES
|
|
132
121
|
gem-release
|
133
122
|
guard-rspec
|
134
123
|
hermes_api!
|
135
|
-
image_processing
|
136
|
-
prawn
|
137
124
|
pry
|
138
125
|
pry-byebug
|
139
126
|
rake (~> 13.0)
|
data/hermes_api.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "hermes_api"
|
7
7
|
spec.version = HermesAPI::VERSION
|
8
8
|
spec.authors = ["Andy Chong"]
|
9
|
-
spec.email = ["
|
9
|
+
spec.email = ["andy@postco.co"]
|
10
10
|
|
11
11
|
spec.summary = "Unofficial Ruby object based Hermes UK API wrapper."
|
12
12
|
spec.description = "Unofficial Ruby object based Hermes UK API wrapper."
|
data/lib/hermes_api.rb
CHANGED
@@ -11,9 +11,10 @@ module HermesAPI
|
|
11
11
|
|
12
12
|
require "hermes_api/resources/base"
|
13
13
|
require "hermes_api/resources/return_label"
|
14
|
-
|
14
|
+
|
15
15
|
require "hermes_api/resources/o_auth"
|
16
16
|
require "hermes_api/resources/json_base"
|
17
17
|
require "hermes_api/resources/print_in_store_qr_code"
|
18
|
-
|
18
|
+
require "hermes_api/resources/tracking_event"
|
19
|
+
require "hermes_api/resources/web_tracking"
|
19
20
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HermesAPI
|
2
|
+
module BearerTokenSetup
|
3
|
+
def connection(refresh = false)
|
4
|
+
connection = super
|
5
|
+
connection.bearer_token = fetch_token
|
6
|
+
connection
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch_token
|
10
|
+
oauth_audience = prefix.match(/^\/?([^\/]*)/).captures.first
|
11
|
+
cached_token = HermesAPI.cache.read("#{oauth_audience}/oauth_token")
|
12
|
+
return cached_token if cached_token
|
13
|
+
|
14
|
+
response = OAuth.create(audience: oauth_audience)
|
15
|
+
HermesAPI.cache.write(
|
16
|
+
"#{oauth_audience}/oauth_token",
|
17
|
+
response.access_token,
|
18
|
+
expires_in: response.expires_in - 15 # clear cache earlier
|
19
|
+
)
|
20
|
+
response.access_token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,25 +2,5 @@ module HermesAPI
|
|
2
2
|
class JsonBase < ActiveResource::Base
|
3
3
|
self.include_format_in_path = false
|
4
4
|
self.auth_type = :bearer
|
5
|
-
|
6
|
-
OAUTH_AUDIENCE = nil
|
7
|
-
|
8
|
-
def save
|
9
|
-
token = HermesAPI.cache.read("#{self.class.name}/oauth_token") || fetch_token
|
10
|
-
connection.bearer_token = token
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def fetch_token
|
17
|
-
response = OAuth.create(audience: self.class::OAUTH_AUDIENCE)
|
18
|
-
HermesAPI.cache.write(
|
19
|
-
"#{self.class.name}/oauth_token",
|
20
|
-
response.access_token,
|
21
|
-
expires_in: response.expires_in - 15 # clear cache earlier
|
22
|
-
)
|
23
|
-
response.access_token
|
24
|
-
end
|
25
5
|
end
|
26
6
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module HermesAPI
|
2
2
|
class PrintInStoreQrCode < JsonBase
|
3
|
+
extend BearerTokenSetup
|
4
|
+
|
3
5
|
self.element_name = ""
|
4
6
|
self.prefix = "/client-print-in-store-api/v1/references"
|
5
7
|
|
6
|
-
OAUTH_AUDIENCE = "client-print-in-store-api"
|
7
|
-
|
8
8
|
def load(attributes, remove_root = false, persisted = false)
|
9
9
|
# remove the outer array before parsing the response body
|
10
10
|
attributes = attributes[0] if attributes.is_a?(Array) && attributes.length == 1
|
@@ -66,18 +66,11 @@ module HermesAPI
|
|
66
66
|
|
67
67
|
alias_method :tracking_number, :tracking_numbers
|
68
68
|
|
69
|
-
def request_print_in_store_qr_code(attrs
|
70
|
-
dimensions:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
weight: 1
|
75
|
-
},
|
76
|
-
value: {
|
77
|
-
currency: "GBP",
|
78
|
-
amount: 10
|
79
|
-
}
|
80
|
-
})
|
69
|
+
def request_print_in_store_qr_code(**attrs)
|
70
|
+
if ([:dimensions, :value, :deliveryAddress] - attrs.keys).length > 0
|
71
|
+
raise ArgumentError, request_print_in_store_qr_code_error_message
|
72
|
+
end
|
73
|
+
|
81
74
|
return nil if attributes["routingResponseEntries"].blank?
|
82
75
|
|
83
76
|
entries = routingResponseEntries.routingResponseEntry
|
@@ -91,12 +84,6 @@ module HermesAPI
|
|
91
84
|
customer: {
|
92
85
|
customerReference1: customer.customerReference1
|
93
86
|
},
|
94
|
-
deliveryAddress: {
|
95
|
-
name: "#{address.firstName} #{address.lastName}",
|
96
|
-
addressLine1: address.addressLine1,
|
97
|
-
countryCode: address.countryCode,
|
98
|
-
postcode: address.postCode
|
99
|
-
},
|
100
87
|
labelType: "RETURN",
|
101
88
|
barcode: {
|
102
89
|
barcode: barcode.barcodeNumber,
|
@@ -120,5 +107,33 @@ module HermesAPI
|
|
120
107
|
**attrs
|
121
108
|
)
|
122
109
|
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def request_print_in_store_qr_code_error_message
|
114
|
+
<<~HEREDOC
|
115
|
+
Missing attributes
|
116
|
+
Example:
|
117
|
+
HermesAPI::ReturnLabel#request_print_in_store_qr_code(
|
118
|
+
dimensions: {
|
119
|
+
depth: 15,
|
120
|
+
length: 20,
|
121
|
+
width: 15,
|
122
|
+
weight: 1
|
123
|
+
},
|
124
|
+
value: {
|
125
|
+
currency: 'GBP',
|
126
|
+
amount: 10
|
127
|
+
},
|
128
|
+
deliveryAddress: {
|
129
|
+
name: 'Don Joe',
|
130
|
+
addressLine1: 'Real Logic',
|
131
|
+
addressLine2: '4-4 Ridings Park, Eastern Way',
|
132
|
+
countryCode: 'GB',
|
133
|
+
postcode: 'WS117FJ'
|
134
|
+
}
|
135
|
+
)
|
136
|
+
HEREDOC
|
137
|
+
end
|
123
138
|
end
|
124
139
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module HermesAPI
|
2
|
+
class WebTracking < ActiveResource::Base
|
3
|
+
self.element_name = ""
|
4
|
+
self.site = "https://api.hermesworld.co.uk"
|
5
|
+
self.prefix = "/enterprise-tracking-api/v1/parcels"
|
6
|
+
self.include_format_in_path = false
|
7
|
+
headers["apiKey"] = ENV["HERMES_WEB_TRACKING_API_KEY"]
|
8
|
+
|
9
|
+
MAPPING = {
|
10
|
+
"715" => "pending_drop_off",
|
11
|
+
"708" => "dropped_off",
|
12
|
+
"690" => "dropped_off",
|
13
|
+
"710" => "collected_by_courier",
|
14
|
+
"688" => "collected_by_courier",
|
15
|
+
"689" => "collected_by_courier",
|
16
|
+
"711" => "collected_by_courier"
|
17
|
+
}
|
18
|
+
|
19
|
+
def load(attributes, remove_root = false, persisted = false)
|
20
|
+
attributes = attributes.dig("results", 0)
|
21
|
+
super(attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(barcode)
|
25
|
+
uniqueId = format.decode(connection.get("#{prefix}/search/#{barcode}", headers).body).first
|
26
|
+
find_single("", params: {uniqueIds: uniqueId})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/hermes_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hermes_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
version: '0'
|
131
131
|
description: Unofficial Ruby object based Hermes UK API wrapper.
|
132
132
|
email:
|
133
|
-
-
|
133
|
+
- andy@postco.co
|
134
134
|
executables: []
|
135
135
|
extensions: []
|
136
136
|
extra_rdoc_files: []
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/dev/config.rb
|
152
152
|
- lib/dev/zeitwerk_loader.rb
|
153
153
|
- lib/hermes_api.rb
|
154
|
+
- lib/hermes_api/bearer_token_setup.rb
|
154
155
|
- lib/hermes_api/cache.rb
|
155
156
|
- lib/hermes_api/configuration.rb
|
156
157
|
- lib/hermes_api/connection.rb
|
@@ -160,6 +161,8 @@ files:
|
|
160
161
|
- lib/hermes_api/resources/o_auth.rb
|
161
162
|
- lib/hermes_api/resources/print_in_store_qr_code.rb
|
162
163
|
- lib/hermes_api/resources/return_label.rb
|
164
|
+
- lib/hermes_api/resources/tracking_event.rb
|
165
|
+
- lib/hermes_api/resources/web_tracking.rb
|
163
166
|
- lib/hermes_api/version.rb
|
164
167
|
homepage: https://github.com/PostCo/hermes_api
|
165
168
|
licenses:
|