hermes_api 0.2.1 → 0.3.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 +4 -2
- data/hermes_api.gemspec +13 -12
- data/lib/dev/config.rb +5 -2
- data/lib/dev/zeitwerk_loader.rb +1 -0
- data/lib/hermes_api.rb +6 -0
- data/lib/hermes_api/cache.rb +10 -0
- data/lib/hermes_api/configuration.rb +14 -1
- data/lib/hermes_api/resources/json_base.rb +26 -0
- data/lib/hermes_api/resources/o_auth.rb +17 -0
- data/lib/hermes_api/resources/print_in_store_qr.rb +14 -0
- data/lib/hermes_api/resources/return_label.rb +61 -1
- data/lib/hermes_api/version.rb +1 -1
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1313c32c78bfdd9fb7a8256298157ca5a13f8a92a5074edeb1671969cb5f43
|
4
|
+
data.tar.gz: 14a9dbfd88d46e2c0dce1e49baf0fd8d992332ac5051a60e24b7dc9af083c9a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bab7f7db1681634318f832ce9e2aacd1d059025f2745dfddc6a115581dfaad5de7baa552ceb23116e31fa3dae7cbdc16f9200ddad8ad61b7a828156a3fd925b
|
7
|
+
data.tar.gz: 31f1ea2846b709e074a7a280b8ee7fa84820db2622370c2b011fe53d69d1bcd3ff536b921a8aaa20bfe2a6aad66d3098d1f81bea283866b74e9d5eb555e3cdff
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hermes_api (0.1
|
4
|
+
hermes_api (0.2.1)
|
5
5
|
activeresource (>= 4.1.0, < 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -32,6 +32,7 @@ GEM
|
|
32
32
|
dotenv (2.7.6)
|
33
33
|
ffi (1.15.3)
|
34
34
|
formatador (0.3.0)
|
35
|
+
gem-release (2.2.2)
|
35
36
|
guard (2.17.0)
|
36
37
|
formatador (>= 0.2.4)
|
37
38
|
listen (>= 2.7, < 4.0)
|
@@ -117,6 +118,7 @@ PLATFORMS
|
|
117
118
|
|
118
119
|
DEPENDENCIES
|
119
120
|
dotenv
|
121
|
+
gem-release
|
120
122
|
guard-rspec
|
121
123
|
hermes_api!
|
122
124
|
pry
|
@@ -127,4 +129,4 @@ DEPENDENCIES
|
|
127
129
|
standard
|
128
130
|
|
129
131
|
BUNDLED WITH
|
130
|
-
2.2.
|
132
|
+
2.2.24
|
data/hermes_api.gemspec
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
require_relative "lib/hermes_api/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
10
|
-
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
6
|
+
spec.name = "hermes_api"
|
7
|
+
spec.version = HermesAPI::VERSION
|
8
|
+
spec.authors = ["Andy Chong"]
|
9
|
+
spec.email = ["andygg1996personal@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Unofficial Ruby object based Hermes UK API wrapper."
|
12
|
+
spec.description = "Unofficial Ruby object based Hermes UK API wrapper."
|
13
|
+
spec.homepage = "https://github.com/PostCo/hermes_api"
|
14
|
+
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
@@ -25,11 +25,11 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
27
|
end
|
28
|
-
spec.bindir
|
29
|
-
spec.executables
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.add_dependency "activeresource", ">= 4.1.0", "< 6.0.0"
|
32
|
+
spec.add_dependency "activeresource", ">= 4.1.0", "< 6.0.0"
|
33
33
|
|
34
34
|
spec.add_development_dependency "rspec", "~> 3.2"
|
35
35
|
spec.add_development_dependency "dotenv"
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency "pry"
|
38
38
|
spec.add_development_dependency "guard-rspec"
|
39
39
|
spec.add_development_dependency "standard"
|
40
|
+
spec.add_development_dependency "gem-release"
|
40
41
|
|
41
42
|
# Uncomment to register a new dependency of your gem
|
42
43
|
# spec.add_dependency "example-gem", "~> 1.0"
|
data/lib/dev/config.rb
CHANGED
@@ -2,9 +2,12 @@ require "dotenv/load"
|
|
2
2
|
|
3
3
|
def set_config
|
4
4
|
HermesAPI.configure do |config|
|
5
|
-
config.user = ENV["HERMES_API_USER"]
|
5
|
+
config.user = ENV["HERMES_API_USER"]
|
6
6
|
config.password = ENV["HERMES_API_PASSWORD"]
|
7
7
|
config.env = :test
|
8
8
|
config.proxy = ENV["HERMES_API_PROXY"]
|
9
|
+
config.auth_id = ENV["HERMES_API_AUTH_ID"]
|
10
|
+
config.auth_secret = ENV["HERMES_API_AUTH_SECRET"]
|
11
|
+
config.api_key = ENV["HERMES_API_KEY"]
|
9
12
|
end
|
10
|
-
end
|
13
|
+
end
|
data/lib/dev/zeitwerk_loader.rb
CHANGED
data/lib/hermes_api.rb
CHANGED
@@ -4,10 +4,16 @@ require_relative "hermes_api/version"
|
|
4
4
|
require "active_resource"
|
5
5
|
|
6
6
|
module HermesAPI
|
7
|
+
require "hermes_api/cache"
|
7
8
|
require "hermes_api/configuration"
|
8
9
|
require "hermes_api/creation_error"
|
9
10
|
require "hermes_api/connection"
|
10
11
|
|
11
12
|
require "hermes_api/resources/base"
|
12
13
|
require "hermes_api/resources/return_label"
|
14
|
+
|
15
|
+
require "hermes_api/resources/o_auth"
|
16
|
+
require "hermes_api/resources/json_base"
|
17
|
+
require "hermes_api/resources/print_in_store_qr"
|
18
|
+
|
13
19
|
end
|
@@ -1,11 +1,19 @@
|
|
1
1
|
module HermesAPI
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :proxy, :env, :user, :password
|
3
|
+
attr_accessor :proxy, :env, :user, :password, :auth_id, :auth_secret, :api_key
|
4
4
|
end
|
5
5
|
|
6
6
|
PRODUCTION_SITE = "https://www.hermes-europe.co.uk"
|
7
7
|
TESTING_SITE = "https://sit.hermes-europe.co.uk"
|
8
8
|
|
9
|
+
OAUTH_PRODUCTION_SITE = "https://hermes-client-integration-prod.eu.auth0.com"
|
10
|
+
OAUTH_TESTING_SITE = "https://hermes-client-integration-pre.eu.auth0.com"
|
11
|
+
|
12
|
+
JSON_PRODUCTION_SITE = "https://api.hermesworld.co.uk"
|
13
|
+
JSON_TESTING_SITE = "https://api.hermesworld.co.uk"
|
14
|
+
# temporarily disabled until it is fixed
|
15
|
+
# JSON_TESTING_SITE = "https://hermeslive-pre-prod.apigee.net"
|
16
|
+
|
9
17
|
class << self
|
10
18
|
def config
|
11
19
|
@config ||= Configuration.new
|
@@ -16,6 +24,11 @@ module HermesAPI
|
|
16
24
|
HermesAPI::Base.proxy = config.proxy
|
17
25
|
HermesAPI::Base.user = config.user
|
18
26
|
HermesAPI::Base.password = config.password
|
27
|
+
|
28
|
+
HermesAPI::JsonBase.site = config.env.to_s == "production" ? JSON_PRODUCTION_SITE : JSON_TESTING_SITE
|
29
|
+
HermesAPI::OAuth.site = config.env.to_s == "production" ? OAUTH_PRODUCTION_SITE : OAUTH_TESTING_SITE
|
30
|
+
|
31
|
+
HermesAPI::JsonBase.headers["apikey"] = config.api_key
|
19
32
|
end
|
20
33
|
|
21
34
|
def configure
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module HermesAPI
|
2
|
+
class JsonBase < ActiveResource::Base
|
3
|
+
self.include_format_in_path = false
|
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
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HermesAPI
|
2
|
+
class OAuth < ActiveResource::Base
|
3
|
+
self.include_format_in_path = false
|
4
|
+
self.element_name=""
|
5
|
+
self.prefix="/oauth/token"
|
6
|
+
|
7
|
+
def initialize(attributes = {}, persisted = false)
|
8
|
+
attributes = {
|
9
|
+
grant_type: "client_credentials",
|
10
|
+
client_id: HermesAPI.config.auth_id,
|
11
|
+
client_secret: HermesAPI.config.auth_secret,
|
12
|
+
**attributes
|
13
|
+
}
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HermesAPI
|
2
|
+
class PrintInStoreQr < JsonBase
|
3
|
+
self.element_name = ""
|
4
|
+
self.prefix = "/client-print-in-store-api/v1/references"
|
5
|
+
|
6
|
+
OAUTH_AUDIENCE = "client-print-in-store-api"
|
7
|
+
|
8
|
+
def load(attributes, remove_root = false, persisted = false)
|
9
|
+
# remove the outer array before parsing the response body
|
10
|
+
attributes = attributes[0] if attributes.is_a?(Array) && attributes.length == 1
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -50,6 +50,8 @@ module HermesAPI
|
|
50
50
|
rescue NameError
|
51
51
|
end
|
52
52
|
|
53
|
+
alias_method :label, :labels
|
54
|
+
|
53
55
|
def tracking_numbers
|
54
56
|
entries = routingResponseEntries.routingResponseEntry
|
55
57
|
if entries.is_a?(Array)
|
@@ -62,7 +64,65 @@ module HermesAPI
|
|
62
64
|
rescue NameError
|
63
65
|
end
|
64
66
|
|
65
|
-
alias_method :label, :labels
|
66
67
|
alias_method :tracking_number, :tracking_numbers
|
68
|
+
|
69
|
+
def request_print_in_store_qr_code(attrs = {
|
70
|
+
dimensions: {
|
71
|
+
depth: 15,
|
72
|
+
length: 20,
|
73
|
+
width: 15,
|
74
|
+
weight: 1
|
75
|
+
},
|
76
|
+
value: {
|
77
|
+
currency: "GBP",
|
78
|
+
amount: 10
|
79
|
+
}
|
80
|
+
})
|
81
|
+
return nil if attributes["routingResponseEntries"].blank?
|
82
|
+
|
83
|
+
entries = routingResponseEntries.routingResponseEntry
|
84
|
+
entry = entries.is_a?(Array) ? entries[0] : entries
|
85
|
+
carrier = entry.inboundCarriers.carrier1
|
86
|
+
barcode = carrier.barcode1
|
87
|
+
customer = collectionRoutingRequestEntries[0].customer
|
88
|
+
address = customer.address
|
89
|
+
|
90
|
+
self.print_in_store_qr_code = PrintInStoreQr.create(
|
91
|
+
customer: {
|
92
|
+
customerReference1: customer.customerReference1
|
93
|
+
},
|
94
|
+
deliveryAddress: {
|
95
|
+
name: "#{address.firstName} #{address.lastName}",
|
96
|
+
addressLine1: address.addressLine1,
|
97
|
+
countryCode: address.countryCode,
|
98
|
+
postcode: address.postCode
|
99
|
+
},
|
100
|
+
labelType: "RETURN",
|
101
|
+
barcode: {
|
102
|
+
barcode: barcode.barcodeNumber,
|
103
|
+
barcodeDisplay: barcode.barcodeDisplay
|
104
|
+
},
|
105
|
+
client: {
|
106
|
+
clientId: clientId,
|
107
|
+
clientName: clientName
|
108
|
+
},
|
109
|
+
routing: {
|
110
|
+
deliveryMethod: {
|
111
|
+
deliveryMethodId: carrier.deliveryMethodCode,
|
112
|
+
deliveryMethodDescription: carrier.deliveryMethodDesc
|
113
|
+
},
|
114
|
+
sortLevels: {
|
115
|
+
sortLevel1: carrier.sortLevel1.strip,
|
116
|
+
sortLevel2: carrier.sortLevel2
|
117
|
+
}
|
118
|
+
},
|
119
|
+
serviceOffers: [],
|
120
|
+
**attrs
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def base64_print_in_store_qr_code
|
125
|
+
as_json.dig("print_in_store_qr_code", "qrCode", "base64EncodedBytes")
|
126
|
+
end
|
67
127
|
end
|
68
128
|
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.3.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-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -114,6 +114,20 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: gem-release
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
117
131
|
description: Unofficial Ruby object based Hermes UK API wrapper.
|
118
132
|
email:
|
119
133
|
- andygg1996personal@gmail.com
|
@@ -137,10 +151,14 @@ files:
|
|
137
151
|
- lib/dev/config.rb
|
138
152
|
- lib/dev/zeitwerk_loader.rb
|
139
153
|
- lib/hermes_api.rb
|
154
|
+
- lib/hermes_api/cache.rb
|
140
155
|
- lib/hermes_api/configuration.rb
|
141
156
|
- lib/hermes_api/connection.rb
|
142
157
|
- lib/hermes_api/creation_error.rb
|
143
158
|
- lib/hermes_api/resources/base.rb
|
159
|
+
- lib/hermes_api/resources/json_base.rb
|
160
|
+
- lib/hermes_api/resources/o_auth.rb
|
161
|
+
- lib/hermes_api/resources/print_in_store_qr.rb
|
144
162
|
- lib/hermes_api/resources/return_label.rb
|
145
163
|
- lib/hermes_api/version.rb
|
146
164
|
homepage: https://github.com/PostCo/hermes_api
|
@@ -166,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
184
|
- !ruby/object:Gem::Version
|
167
185
|
version: '0'
|
168
186
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.2.22
|
170
188
|
signing_key:
|
171
189
|
specification_version: 4
|
172
190
|
summary: Unofficial Ruby object based Hermes UK API wrapper.
|