notifications-ruby-client 2.5.1 → 2.6.0
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/CHANGELOG.md +5 -0
- data/lib/notifications/client.rb +1 -0
- data/lib/notifications/client/speaker.rb +13 -0
- data/lib/notifications/client/uuid_validator.rb +26 -0
- data/lib/notifications/client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942f912e7dce40facdd4d15a7554c34366efbbfb
|
4
|
+
data.tar.gz: 7804cd65bf20d992f480e1f576cd9cab44e6b69c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1a019e8ff6e295d6f781aa956aadffdf89e2e116e1cd51dd7739427955d97949122f5d4252b538f03afb50101ad9b151a914efe3848d25933c4123a0cc20968
|
7
|
+
data.tar.gz: a75e8a79f6cda877bda9f6bf4b4d7f783c14e9d7d7a43e3f305718407e4690cb0a9e162adae3124ca0dac3dd711a74115c84a479416ab857c93c5ed678165fd5
|
data/CHANGELOG.md
CHANGED
data/lib/notifications/client.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "client/received_text_collection"
|
|
8
8
|
require_relative "client/response_template"
|
9
9
|
require_relative "client/template_collection"
|
10
10
|
require_relative "client/template_preview"
|
11
|
+
require_relative "client/uuid_validator"
|
11
12
|
require "forwardable"
|
12
13
|
|
13
14
|
module Notifications
|
@@ -21,6 +21,8 @@ module Notifications
|
|
21
21
|
@service_id = secret_token[secret_token.length - 73..secret_token.length - 38]
|
22
22
|
@secret_token = secret_token[secret_token.length - 36..secret_token.length]
|
23
23
|
@base_url = base_url || PRODUCTION_BASE_URL
|
24
|
+
|
25
|
+
validate_uuids!
|
24
26
|
end
|
25
27
|
|
26
28
|
##
|
@@ -130,6 +132,17 @@ module Notifications
|
|
130
132
|
}
|
131
133
|
JWT.encode payload, @secret_token, "HS256"
|
132
134
|
end
|
135
|
+
|
136
|
+
def validate_uuids!
|
137
|
+
contextual_message = [
|
138
|
+
"This error is probably caused by initializing the Notifications client with an invalid API key.",
|
139
|
+
"You can generate a new API key by logging into Notify and visiting the 'API integration' page:",
|
140
|
+
"https://www.notifications.service.gov.uk",
|
141
|
+
].join("\n")
|
142
|
+
|
143
|
+
UuidValidator.validate!(@service_id, contextual_message)
|
144
|
+
UuidValidator.validate!(@secret_token, contextual_message)
|
145
|
+
end
|
133
146
|
end
|
134
147
|
end
|
135
148
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Notifications
|
2
|
+
class UuidValidator
|
3
|
+
HEX = /[0-9a-f]/
|
4
|
+
REGEX = /^#{HEX}{8}-#{HEX}{4}-#{HEX}{4}-#{HEX}{4}-#{HEX}{12}$/
|
5
|
+
|
6
|
+
attr_accessor :uuid
|
7
|
+
|
8
|
+
def initialize(uuid)
|
9
|
+
self.uuid = uuid
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
!!(uuid && uuid.match(REGEX))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.validate!(uuid, contextual_message = nil)
|
17
|
+
return if new(uuid).valid?
|
18
|
+
|
19
|
+
message = "#{uuid.inspect} is not a valid uuid"
|
20
|
+
message += "\n#{contextual_message}" if contextual_message
|
21
|
+
|
22
|
+
raise ArgumentError, message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifications-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Government Digital Service
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/notifications/client/speaker.rb
|
149
149
|
- lib/notifications/client/template_collection.rb
|
150
150
|
- lib/notifications/client/template_preview.rb
|
151
|
+
- lib/notifications/client/uuid_validator.rb
|
151
152
|
- lib/notifications/client/version.rb
|
152
153
|
- notifications-ruby-client.gemspec
|
153
154
|
homepage: https://github.com/alphagov/notifications-ruby-client
|