Skip to content

Commit a3b1562

Browse files
authored
Merge pull request #540 from watson-developer-cloud/feature-v3-datetime
DateTime formatting
2 parents 290258c + 04d50db commit a3b1562

File tree

12 files changed

+89
-183
lines changed

12 files changed

+89
-183
lines changed

README.md

Lines changed: 31 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ Ensure that you have the following prerequisites:
3232

3333
## Configuring Unity
3434
* Change the build settings in Unity (**File > Build Settings**) to any platform except for web player/Web GL. The IBM Watson SDK for Unity does not support Unity Web Player.
35-
* If using Unity 2018.2 or later you'll need to set Scripting Runtime Version in Build Settings to .NET 4.x equivalent. We need to access security options to enable TLS 1.2.
35+
* If using Unity 2018.2 or later you'll need to set Scripting Runtime Version and Api Compatibility Level in Build Settings to .NET 4.x equivalent. We need to access security options to enable TLS 1.2.
3636

3737
## Getting the Watson SDK and adding it to Unity
3838
You can get the latest SDK release by clicking [here][latest_release].
3939

4040
### Installing the SDK source into your Unity project
41-
Move the **`unity-sdk`** directory into the **`Assets`** directory of your Unity project. _Optional: rename the SDK directory from `unity-sdk` to `Watson`_.
41+
1. Move the **`unity-sdk`** directory into the **`Assets`** directory of your Unity project. _Optional: rename the SDK directory from `unity-sdk` to `Watson`_.
42+
2. Using the command line, from the sdk directory run `git submodule init` and `git submodule update` to get the correct commit of the SDK core.
4243

4344
## Configuring your service credentials
4445
To create instances of Watson services and their credentials, follow the steps below.
@@ -124,17 +125,12 @@ IEnumerator TokenExample()
124125

125126
_assistant = new Assistant(_credentials);
126127
_assistant.VersionDate = "2018-02-16";
127-
_assistant.ListWorkspaces(OnListWorkspaces, OnFail);
128+
_assistant.ListWorkspaces(OnListWorkspaces);
128129
}
129130

130-
private void OnListWorkspaces(WorkspaceCollection response, Dictionary<string, object> customData)
131+
private void OnListWorkspaces(DetailedResponse<WorkspaceCollection> response, IBMError error)
131132
{
132-
Log.Debug("OnListWorkspaces()", "Response: {0}", customData["json"].ToString());
133-
}
134-
135-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
136-
{
137-
Log.Debug("OnFail()", "Failed: {0}", error.ToString());
133+
Log.Debug("OnListWorkspaces()", "Response: {0}", response.Response);
138134
}
139135
```
140136

@@ -153,24 +149,19 @@ void TokenExample()
153149

154150
_assistant = new Assistant(_credentials);
155151
_assistant.VersionDate = "2018-02-16";
156-
_assistant.ListWorkspaces(OnListWorkspaces, OnFail);
152+
_assistant.ListWorkspaces(OnListWorkspaces);
157153
}
158154

159-
private void OnListWorkspaces(WorkspaceCollection response, Dictionary<string, object> customData)
155+
private void OnListWorkspaces(DetailedResponse<WorkspaceCollection> response, IBMError error)
160156
{
161-
Log.Debug("OnListWorkspaces()", "Response: {0}", customData["json"].ToString());
162-
}
163-
164-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
165-
{
166-
Log.Debug("OnFail()", "Failed: {0}", error.ToString());
157+
Log.Debug("OnListWorkspaces()", "Response: {0}", response.Response);
167158
}
168159
```
169160

170161
### Username and password
171162
```cs
172-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
173-
using IBM.Watson.DeveloperCloud.Utilities;
163+
using IBM.Watson.Assistant.v1;
164+
using IBM.Cloud.SDK.Utilities;
174165

175166
void Start()
176167
{
@@ -180,37 +171,25 @@ void Start()
180171
```
181172

182173
## Callbacks
183-
Success and failure callbacks are required. You can specify the return type in the callback.
174+
Success callbacks are required. You can specify the return type in the callback.
184175
```cs
185176
private void Example()
186177
{
187178
// Call with sepcific callbacks
188-
assistant.Message(OnMessage, OnGetEnvironmentsFail, _workspaceId, "");
189-
discovery.GetEnvironments(OnGetEnvironments, OnFail);
179+
assistant.Message(OnMessage, _workspaceId);
180+
discovery.GetEnvironments(OnGetEnvironments);
190181
}
191182

192183
// OnMessage callback
193-
private void OnMessage(object resp, Dictionary<string, object> customData)
184+
private void OnMessage(DetailedResponse<JObject> resp, IBMError error)
194185
{
195-
Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", customData["json"].ToString());
186+
Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", resp.Response);
196187
}
197188

198189
// OnGetEnvironments callback
199-
private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary<string, object> customData)
200-
{
201-
Log.Debug("ExampleCallback.OnGetEnvironments()", "Response received: {0}", customData["json"].ToString());
202-
}
203-
204-
// OnMessageFail callback
205-
private void OnMessageFail(RESTConnector.Error error, Dictionary<string, object> customData)
190+
private void OnGetEnvironments(DetailedResponse<GetEnvironmentsResponse> resp, IBMError error)
206191
{
207-
Log.Error("ExampleCallback.OnMessageFail()", "Error received: {0}", error.ToString());
208-
}
209-
210-
// OnGetEnvironmentsFail callback
211-
private void OnGetEnvironmentsFail(RESTConnector.Error error, Dictionary<string, object> customData)
212-
{
213-
Log.Error("ExampleCallback.OnGetEnvironmentsFail()", "Error received: {0}", error.ToString());
192+
Log.Debug("ExampleCallback.OnGetEnvironments()", "Response received: {0}", resp.Response);
214193
}
215194
```
216195

@@ -219,131 +198,47 @@ Since the success callback signature is generic and the failure callback always
219198
private void Example()
220199
{
221200
// Call with generic callbacks
222-
assistant.Message(OnSuccess, OnMessageFail, "<workspace-id>", "");
223-
discovery.GetEnvironments(OnSuccess, OnFail);
201+
assistant.Message(OnSuccess, "<workspace-id>", "");
202+
discovery.GetEnvironments(OnSuccess);
224203
}
225204

226205
// Generic success callback
227-
private void OnSuccess<T>(T resp, Dictionary<string, object> customData)
228-
{
229-
Log.Debug("ExampleCallback.OnSuccess()", "Response received: {0}", customData["json"].ToString());
230-
}
231-
232-
// Generic fail callback
233-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
206+
private void OnSuccess<T>(DetailedResponse<T> resp, IBMError error)
234207
{
235-
Log.Error("ExampleCallback.OnFail()", "Error received: {0}", error.ToString());
236-
}
237-
```
238-
239-
## Custom data
240-
Custom data can be passed through a `Dictionary<string, object> customData` in each call. In most cases, the raw json response is returned in the customData under `"json"` entry. In cases where there is no returned json, the entry will contain the success and http response code of the call.
241-
242-
```cs
243-
void Example()
244-
{
245-
Dictionary<string, object> customData = new Dictionary<string, object>();
246-
customData.Add("foo", "bar");
247-
assistant.Message(OnSuccess, OnFail, "<workspace-id>", "", customData);
248-
}
249-
250-
// Generic success callback
251-
private void OnSuccess<T>(T resp, Dictionary<string, object> customData)
252-
{
253-
Log.Debug("ExampleCustomData.OnSuccess()", "Custom Data: {0}", customData["foo"].ToString()); // returns "bar"
254-
}
255-
256-
// Generic fail callback
257-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
258-
{
259-
Log.Error("ExampleCustomData.OnFail()", "Error received: {0}", error.ToString()); // returns error string
260-
Log.Debug("ExampleCustomData.OnFail()", "Custom Data: {0}", customData["foo"].ToString()); // returns "bar"
208+
Log.Debug("ExampleCallback.OnSuccess()", "Response received: {0}", resp.Response);
261209
}
262210
```
263211

264212
## Custom Request Headers
265-
You can send custom request headers by adding them to the `customData` object.
213+
You can send custom request headers by adding them to the service.
266214

267215
```cs
268216
void Example()
269217
{
270-
// Create customData object
271-
Dictionary<string, object> customData = new Dictionary<string, object>();
272-
// Create a dictionary of custom headers
273-
Dictionary<string, string> customHeaders = new Dictionary<string, string>();
274-
// Add to the header dictionary
275-
customHeaders.Add("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
276-
// Add the header dictionary to the custom data object
277-
customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders);
278-
279-
assistant.Message(OnSuccess, OnFail, "<workspace-id>", customData: customData);
218+
assistant.AddHeader("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
219+
assistant.Message(OnSuccess, "<workspace-id>");
280220
}
281221
```
282222

283223
## Response Headers
284-
You can get responseheaders in the `customData` object in the callback.
224+
You can get response headers in the `headers` object in the DetailedResponse.
285225

286226
```cs
287227
void Example()
288228
{
289-
assistant.Message(OnMessage, OnFail, "<workspace-id>");
229+
assistant.Message(OnMessage, "<workspace-id>");
290230
}
291231

292-
private void OnMessage(object resp, Dictionary<string, object> customData)
232+
private void OnMessage(DetailedResponse<JOBject> resp, IBMError error)
293233
{
294234
// List all headers in the response headers object
295-
if (customData.ContainsKey(Constants.String.RESPONSE_HEADERS))
235+
foreach (KeyValuePair<string, string> kvp in resp.Headers)
296236
{
297-
foreach (KeyValuePair<string, string> kvp in customData[Constants.String.RESPONSE_HEADERS] as Dictionary<string, string>)
298-
{
299-
Log.Debug("ExampleCustomHeader.OnMessage()", "{0}: {1}", kvp.Key, kvp.Value);
300-
}
237+
Log.Debug("ExampleCustomHeader.OnMessage()", "{0}: {1}", kvp.Key, kvp.Value);
301238
}
302239
}
303240
```
304241

305-
## Authentication Tokens
306-
307-
**Authenticating with the `X-Watson-Authorization-Token` header is deprecated. The token continues to work with Cloud Foundry services, but is not supported for services that use Identity and Access Management (IAM) authentication. For details see [Authenticating with IAM tokens](https://console.bluemix.net/docs/services/watson/getting-started-iam.html#iam) or the [README](#IAM) in the IBM Watson SDK you use.**
308-
309-
You use tokens to write applications that make authenticated requests to IBM Watson™ services without embedding service credentials in every call.
310-
311-
You can write an authentication proxy in IBM Cloud that obtains and returns a token to your client application, which can then use the token to call the service directly. This proxy eliminates the need to channel all service requests through an intermediate server-side application, which is otherwise necessary to avoid exposing your service credentials from your client application.
312-
313-
```cs
314-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
315-
using IBM.Watson.DeveloperCloud.Utilities;
316-
317-
void Start()
318-
{
319-
Credentials credentials = new Credentials(<service-url>)
320-
{
321-
AuthenticationToken = <authentication-token>
322-
};
323-
Assistant _assistant = new Assistant(credentials);
324-
}
325-
```
326-
327-
There is a helper class included to obtain tokens from within your Unity application.
328-
329-
```cs
330-
using IBM.Watson.DeveloperCloud.Utilities;
331-
332-
AuthenticationToken _authenticationToken;
333-
334-
void Start()
335-
{
336-
if (!Utility.GetToken(OnGetToken, <service-url>, <service-username>, <service-password>))
337-
Log.Debug("ExampleGetToken.Start()", "Failed to get token.");
338-
}
339-
340-
private void OnGetToken(AuthenticationToken authenticationToken, string customData)
341-
{
342-
_authenticationToken = authenticationToken;
343-
Log.Debug("ExampleGetToken.OnGetToken()", "created: {0} | time to expiration: {1} minutes | token: {2}", _authenticationToken.Created, _authenticationToken.TimeUntilExpiration, _authenticationToken.Token);
344-
}
345-
```
346-
347242
## Streaming outside of US South region
348243
Watson services have upgraded their hosts to TLS 1.2. The US South region has a TLS 1.0 endpoint that will work for streaming but if you are streaming in other regions you will need to use Unity 2018.2 and set Scripting Runtime Version in Build Settings to .NET 4.x equivalent. In lower versions of Unity you will need to create the Speech to Text instance in US South.
349244

@@ -366,7 +261,7 @@ The Watson Unity SDK does not support IBM Cloud Private because connection via p
366261
Documentation can be found [here][documentation]. You can also access the documentation by selecting API Reference the Watson menu (**Watson -> API Reference**).
367262

368263
## Getting started videos
369-
You can view Getting Started videos for the IBM Watson SDK for Unity on [YouTube](https://www.youtube.com/watch?v=Sa5hmukwHV8&list=PLZDyxLlNKRY8MdgiUq45cZztn_f0EVz6c).
264+
You can view Getting Started videos for the IBM Watson SDK for Unity on [YouTube](https://www.youtube.com/watch?v=sNPsdUWSi34&list=PLZDyxLlNKRY9b2vurEhkSoNWZN5c5l4Nr).
370265

371266
## Questions
372267

Scripts/Services/Assistant/V1/AssistantService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace IBM.Watson.Assistant.V1
3030
{
3131
public partial class AssistantService : BaseService
3232
{
33-
private const string serviceId = "conversation";
33+
private const string serviceId = "assistant";
3434
private const string defaultUrl = "https://gateway.watsonplatform.net/assistant/api";
3535

3636
#region Credentials

Scripts/Services/Assistant/V2/AssistantService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace IBM.Watson.Assistant.V2
3030
{
3131
public partial class AssistantService : BaseService
3232
{
33-
private const string serviceId = "conversation";
33+
private const string serviceId = "assistant";
3434
private const string defaultUrl = "https://gateway.watsonplatform.net/assistant/api";
3535

3636
#region Credentials

Scripts/Services/CompareComply/V1/CompareComplyService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace IBM.Watson.CompareComply.V1
3030
{
3131
public partial class CompareComplyService : BaseService
3232
{
33-
private const string serviceId = "compare-comply";
33+
private const string serviceId = "compare_comply";
3434
private const string defaultUrl = "https://gateway.watsonplatform.net/compare-comply/api";
3535

3636
#region Credentials

Scripts/Services/NaturalLanguageUnderstanding/V1/NaturalLanguageUnderstandingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace IBM.Watson.NaturalLanguageUnderstanding.V1
3030
{
3131
public partial class NaturalLanguageUnderstandingService : BaseService
3232
{
33-
private const string serviceId = "natural-language-understanding";
33+
private const string serviceId = "natural_language_understanding";
3434
private const string defaultUrl = "https://gateway.watsonplatform.net/natural-language-understanding/api";
3535

3636
#region Credentials

Scripts/Services/SpeechToText/V1/SpeechToTextService.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,11 +4030,17 @@ private void OnUpgradeAcousticModelResponse(RESTConnector.Request req, RESTConne
40304030
/// * `application/zip` for a **.zip** file
40314031
/// * `application/gzip` for a **.tar.gz** file.
40324032
///
4033-
/// All audio files contained in the archive must have the same audio format. Use the `Contained-Content-Type`
4034-
/// parameter to specify the format of the contained audio files. The parameter accepts all of the audio formats
4035-
/// supported for use with speech recognition and with the `Content-Type` header, including the `rate`,
4036-
/// `channels`, and `endianness` parameters that are used with some formats. The default contained audio format
4037-
/// is `audio/wav`.
4033+
/// When you add an archive-type resource, the `Contained-Content-Type` header is optional depending on the
4034+
/// format of the files that you are adding:
4035+
/// * For audio files of type `audio/alaw`, `audio/basic`, `audio/l16`, or `audio/mulaw`, you must use the
4036+
/// `Contained-Content-Type` header to specify the format of the contained audio files. Include the `rate`,
4037+
/// `channels`, and `endianness` parameters where necessary. In this case, all audio files contained in the
4038+
/// archive file must have the same audio format.
4039+
/// * For audio files of all other types, you can omit the `Contained-Content-Type` header. In this case, the
4040+
/// audio files contained in the archive file can have any of the formats not listed in the previous bullet. The
4041+
/// audio files do not need to have the same format.
4042+
///
4043+
/// Do not use the `Contained-Content-Type` header when adding an audio-type resource.
40384044
///
40394045
/// ### Naming restrictions for embedded audio files
40404046
///
@@ -4056,11 +4062,18 @@ private void OnUpgradeAcousticModelResponse(RESTConnector.Request req, RESTConne
40564062
/// * Do not use the name of an audio resource that has already been added to the custom model.</param>
40574063
/// <param name="audioResource">The audio resource that is to be added to the custom acoustic model, an
40584064
/// individual audio file or an archive file.</param>
4059-
/// <param name="containedContentType">For an archive-type resource, specifies the format of the audio files
4060-
/// that are contained in the archive file. The parameter accepts all of the audio formats that are supported
4061-
/// for use with speech recognition, including the `rate`, `channels`, and `endianness` parameters that are used
4062-
/// with some formats. For more information, see **Content types for audio-type resources** in the method
4063-
/// description. (optional, default to audio/wav)</param>
4065+
/// <param name="containedContentType">**For an archive-type resource,** specify the format of the audio files
4066+
/// that are contained in the archive file if they are of type `audio/alaw`, `audio/basic`, `audio/l16`, or
4067+
/// `audio/mulaw`. Include the `rate`, `channels`, and `endianness` parameters where necessary. In this case,
4068+
/// all audio files that are contained in the archive file must be of the indicated type.
4069+
///
4070+
/// For all other audio formats, you can omit the header. In this case, the audio files can be of multiple types
4071+
/// as long as they are not of the types listed in the previous paragraph.
4072+
///
4073+
/// The parameter accepts all of the audio formats that are supported for use with speech recognition. For more
4074+
/// information, see **Content types for audio-type resources** in the method description.
4075+
///
4076+
/// **For an audio-type resource,** omit the header. (optional)</param>
40644077
/// <param name="allowOverwrite">If `true`, the specified audio resource overwrites an existing audio resource
40654078
/// with the same name. If `false`, the request fails if an audio resource with the same name already exists.
40664079
/// The parameter has no effect if an audio resource with the same name does not already exist. (optional,

Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ private void OnListVoicesResponse(RESTConnector.Request req, RESTConnector.Respo
270270
/// language for the input text on the specified voice. Use a voice that matches the language of the input text.
271271
///
272272
///
273-
/// The service returns the synthesized audio stream as an array of bytes. You can pass a maximum of 5 KB of
274-
/// text to the service.
273+
/// The method accepts a maximum of 5 KB of input text in the body of the request, and 8 KB for the URL and
274+
/// headers. The 5 KB limit includes any SSML tags that you specify. The service returns the synthesized audio
275+
/// stream as an array of bytes.
275276
///
276277
/// **See also:** [The HTTP interface](https://cloud.ibm.com/docs/services/text-to-speech/http.html).
277278
///

0 commit comments

Comments
 (0)