diff --git a/README.md b/README.md index fdf47d2..9dd8dec 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ The following services are currently supported by this library. Therefore, you c - [PostgreSQL](https://console.ng.bluemix.net/catalog/services/compose-for-postgresql/) - [Push SDK](https://console.ng.bluemix.net/catalog/services/push-notifications) - [Redis](https://console.ng.bluemix.net/catalog/services/redis-cloud) -- [Watson Conversation](https://console.ng.bluemix.net/catalog/services/conversation) +- [Watson Assistant](https://console.ng.bluemix.net/catalog/services/watson-assistant-formerly-conversation) - [Weather Company Data](https://console.bluemix.net/catalog/services/weather-company-data) If you don't see listed above the service you intend to use in your Swift application, you can leverage the generic `getDictionary(name: String)` method to get the corresponding credentials: diff --git a/Sources/CloudEnvironment/NaturalLangUnderstandingCredentials.swift b/Sources/CloudEnvironment/NaturalLanguageUnderstandingCredentials.swift similarity index 58% rename from Sources/CloudEnvironment/NaturalLangUnderstandingCredentials.swift rename to Sources/CloudEnvironment/NaturalLanguageUnderstandingCredentials.swift index ecc5de0..6024cec 100644 --- a/Sources/CloudEnvironment/NaturalLangUnderstandingCredentials.swift +++ b/Sources/CloudEnvironment/NaturalLanguageUnderstandingCredentials.swift @@ -14,32 +14,34 @@ * limitations under the License. */ -/// NaturalLangUnderstandingCredentials class +/// NaturalLanguageUnderstandingCredentials class /// /// Contains the credentials for a Natural Language Understanding service instance. -public class NaturalLangUnderstandingCredentials: Credentials { - // Just a simpler wrapper to provide a type for natural language credentials +public class NaturalLanguageUnderstandingCredentials { + + public let apiKey: String + public let url: String + + public init(apiKey: String, url: String) { + self.apiKey = apiKey + self.url = url + } } extension CloudEnv { - /// Returns a NaturalLangUnderstandingCredentials object with the corresponding credentials. + /// Returns a NaturalLanguageUnderstandingCredentials object with the corresponding credentials. /// /// - Parameter name: The key to lookup the credentials object. - public func getNaturalLangUnderstandingCredentials(name: String) -> NaturalLangUnderstandingCredentials? { + public func getNaturalLanguageUnderstandingCredentials(name: String) -> NaturalLanguageUnderstandingCredentials? { guard let credentials = getDictionary(name: name), - let username = credentials["username"] as? String, - let password = credentials["password"] as? String, + let apiKey = credentials["apikey"] as? String, let url = credentials["url"] as? String else { return nil } - return NaturalLangUnderstandingCredentials( - username: username, - password: password, - url: url) + return NaturalLanguageUnderstandingCredentials(apiKey: apiKey, url: url) } - } diff --git a/Sources/CloudEnvironment/WatsonConversationCredentials.swift b/Sources/CloudEnvironment/WatsonAssistantCredentials.swift similarity index 52% rename from Sources/CloudEnvironment/WatsonConversationCredentials.swift rename to Sources/CloudEnvironment/WatsonAssistantCredentials.swift index d3d7c61..5fd48a4 100644 --- a/Sources/CloudEnvironment/WatsonConversationCredentials.swift +++ b/Sources/CloudEnvironment/WatsonAssistantCredentials.swift @@ -14,28 +14,33 @@ * limitations under the License. */ -/// WatsonConversationCredentials class +/// WatsonAssistantCredentials class /// -/// Contains the credentials for a Watson Conversation service instance. -public class WatsonConversationCredentials: Credentials { - // Just a simpler wrapper to provide a type for conversation credentials +/// Contains the credentials for a Watson Assistant service instance. +public class WatsonAssistantCredentials { + + public let apiKey: String + public let url: String + + public init(apiKey: String, url: String) { + self.apiKey = apiKey + self.url = url + } } extension CloudEnv { - /// Returns an WatsonConversationCredentials object with the corresponding credentials. + /// Returns an WatsonAssistantCredentials object with the corresponding credentials. /// /// - Parameter name: The key to lookup the environment variable. - public func getWatsonConversationCredentials(name: String) -> WatsonConversationCredentials? { + public func getWatsonAssistantCredentials(name: String) -> WatsonAssistantCredentials? { guard let credentials = getDictionary(name: name), - let username = credentials["username"] as? String, - let password = credentials["password"] as? String, - let url = credentials["url"] as? String else { + let apiKey = credentials["apikey"] as? String, + let url = credentials["url"] as? String else { return nil } - return WatsonConversationCredentials(username: username, password: password, url: url) + return WatsonAssistantCredentials(apiKey: apiKey, url: url) } - } diff --git a/Tests/CloudEnvironmentTests/NaturalLangUnderstandingTests.swift b/Tests/CloudEnvironmentTests/NaturalLanguageUnderstandingTests.swift similarity index 77% rename from Tests/CloudEnvironmentTests/NaturalLangUnderstandingTests.swift rename to Tests/CloudEnvironmentTests/NaturalLanguageUnderstandingTests.swift index 518d27d..4e17611 100644 --- a/Tests/CloudEnvironmentTests/NaturalLangUnderstandingTests.swift +++ b/Tests/CloudEnvironmentTests/NaturalLanguageUnderstandingTests.swift @@ -18,9 +18,9 @@ import XCTest import Configuration @testable import CloudEnvironment -class NaturalLangUnderstandingTests: XCTestCase { +class NaturalLanguageUnderstandingTests: XCTestCase { - static var allTests : [(String, (NaturalLangUnderstandingTests) -> () throws -> Void)] { + static var allTests : [(String, (NaturalLanguageUnderstandingTests) -> () throws -> Void)] { return [ ("testGetCredentials", testGetCredentials), ] @@ -31,13 +31,12 @@ class NaturalLangUnderstandingTests: XCTestCase { // Load test mappings.json file and Cloud Foundry test credentials-- VCAP_SERVICES and VCAP_APPLICATION let cloudEnv = CloudEnv(mappingsFilePath: "Tests/CloudEnvironmentTests/resources", cloudFoundryFile: "Tests/CloudEnvironmentTests/resources/config_cf_example.json") - guard let credentials = cloudEnv.getNaturalLangUnderstandingCredentials(name: "NLUKey") else { + guard let credentials = cloudEnv.getNaturalLanguageUnderstandingCredentials(name: "NLUKey") else { XCTFail("Could not load Natural Language Understanding service credentials.") return } - XCTAssertEqual(credentials.username, "natural-language-user") - XCTAssertEqual(credentials.password, "natural-language-pwd") + XCTAssertEqual(credentials.apiKey, "natural-language-apikey") XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/natural-language-understanding/api") } diff --git a/Tests/CloudEnvironmentTests/WatsonConversationTests.swift b/Tests/CloudEnvironmentTests/WatsonAssistantTests.swift similarity index 55% rename from Tests/CloudEnvironmentTests/WatsonConversationTests.swift rename to Tests/CloudEnvironmentTests/WatsonAssistantTests.swift index a72e947..e9c533d 100644 --- a/Tests/CloudEnvironmentTests/WatsonConversationTests.swift +++ b/Tests/CloudEnvironmentTests/WatsonAssistantTests.swift @@ -18,9 +18,9 @@ import XCTest import Configuration @testable import CloudEnvironment -class WatsonConversationTests: XCTestCase { +class WatsonAssistantTests: XCTestCase { - static var allTests : [(String, (WatsonConversationTests) -> () throws -> Void)] { + static var allTests : [(String, (WatsonAssistantTests) -> () throws -> Void)] { return [ ("testGetCredentials", testGetCredentials), ] @@ -31,17 +31,12 @@ class WatsonConversationTests: XCTestCase { // Load test mappings.json file and Cloud Foundry test credentials-- VCAP_SERVICES and VCAP_APPLICATION let cloudEnv = CloudEnv(mappingsFilePath: "Tests/CloudEnvironmentTests/resources", cloudFoundryFile: "Tests/CloudEnvironmentTests/resources/config_cf_example.json") - guard let credentials = cloudEnv.getWatsonConversationCredentials(name: "ConversationKey") else { - XCTFail("Could not load Watson Conversation service credentials.") + guard let credentials = cloudEnv.getWatsonAssistantCredentials(name: "AssistantKey") else { + XCTFail("Could not load Watson Assistant service credentials.") return } - XCTAssertEqual(credentials.username, "conversation-user", "Watson Conversation service username should match.") - XCTAssertEqual(credentials.password, "conversation-pwd", "Watson Conversation service password should match.") - XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/conversation/api", "Watson Conversation service url should match.") - XCTAssertEqual(credentials.port, 443, "Watson Conversation service port should match.") - XCTAssertEqual(credentials.host, "gateway.watsonplatform.net", "Watson Conversation service host should match.") - XCTAssertTrue(credentials.secured, "Watson Conversation service url should be secured.") + XCTAssertEqual(credentials.apiKey, "assistant-apikey", "Watson Assistant service username should match.") + XCTAssertEqual(credentials.url, "https://gateway.watsonplatform.net/assistant/api", "Watson Assistant service url should match.") } - } diff --git a/Tests/CloudEnvironmentTests/resources/config_cf_example.json b/Tests/CloudEnvironmentTests/resources/config_cf_example.json index 8fccd41..0128b7e 100644 --- a/Tests/CloudEnvironmentTests/resources/config_cf_example.json +++ b/Tests/CloudEnvironmentTests/resources/config_cf_example.json @@ -43,9 +43,8 @@ "conversation": [ { "credentials": { - "password": "conversation-pwd", - "url": "https://gateway.watsonplatform.net/conversation/api", - "username": "conversation-user" + "apikey": "assistant-apikey", + "url": "https://gateway.watsonplatform.net/assistant/api" }, "label": "conversation", "name": "ConversationService", @@ -62,9 +61,8 @@ "natural-language-understanding": [ { "credentials": { - "password": "natural-language-pwd", + "apikey": "natural-language-apikey", "url": "https://gateway.watsonplatform.net/natural-language-understanding/api", - "username": "natural-language-user" }, "label": "natural-language-understanding", "name": "NLUService", diff --git a/Tests/CloudEnvironmentTests/resources/mappings.json b/Tests/CloudEnvironmentTests/resources/mappings.json index 8e7e8e6..00b86cb 100644 --- a/Tests/CloudEnvironmentTests/resources/mappings.json +++ b/Tests/CloudEnvironmentTests/resources/mappings.json @@ -53,7 +53,7 @@ ] } }, - "ConversationKey": { + "AssistantKey": { "credentials": { "searchPatterns": [ "cloudfoundry:ConversationService", diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index b8d785b..a1f4460 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -30,8 +30,8 @@ XCTMain([ testCase(PostgreSQLTests.allTests), testCase(PushSDKTests.allTests), testCase(RedisTests.allTests), - testCase(WatsonConversationTests.allTests), - testCase(NaturalLangUnderstandingTests.allTests), + testCase(WatsonAssistantTests.allTests), + testCase(NaturalLanguageUnderstandingTests.allTests), testCase(WeatherCompanyDataTests.allTests), testCase(EnvironmentVariablesTests.allTests), testCase(LocalFileTests.allTests),