lib/notifications/client/speaker.rb in notifications-ruby-client-2.5.1 vs lib/notifications/client/speaker.rb in notifications-ruby-client-2.6.0
- old
+ new
@@ -19,10 +19,12 @@
# If left nil the production url is used.
def initialize(secret_token = nil, base_url = nil)
@service_id = secret_token[secret_token.length - 73..secret_token.length - 38]
@secret_token = secret_token[secret_token.length - 36..secret_token.length]
@base_url = base_url || PRODUCTION_BASE_URL
+
+ validate_uuids!
end
##
# @param kind [String] 'email', 'sms' or 'letter'
# @param form_data [Hash]
@@ -127,9 +129,20 @@
payload = {
iss: @service_id,
iat: Time.now.to_i
}
JWT.encode payload, @secret_token, "HS256"
+ end
+
+ def validate_uuids!
+ contextual_message = [
+ "This error is probably caused by initializing the Notifications client with an invalid API key.",
+ "You can generate a new API key by logging into Notify and visiting the 'API integration' page:",
+ "https://www.notifications.service.gov.uk",
+ ].join("\n")
+
+ UuidValidator.validate!(@service_id, contextual_message)
+ UuidValidator.validate!(@secret_token, contextual_message)
end
end
end
end