Skip to content

Commit b622fe9

Browse files
committed
fix warnings, add example for callbacks
1 parent 2aa2bfb commit b622fe9

File tree

7 files changed

+152
-27
lines changed

7 files changed

+152
-27
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.Watson.DeveloperCloud.Connection;
19+
using IBM.Watson.DeveloperCloud.Logging;
20+
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
21+
using IBM.Watson.DeveloperCloud.Services.Discovery.v1;
22+
using IBM.Watson.DeveloperCloud.Utilities;
23+
using System.Collections.Generic;
24+
using UnityEngine;
25+
26+
namespace IBM.Watson.DeveloperCloud.Examples
27+
{
28+
public class ExampleCallback : MonoBehaviour
29+
{
30+
private string _conversationUsername = "";
31+
private string _conversationPassword = "";
32+
private string _conversationUrl = "https://gateway.watsonplatform.net/conversation/api";
33+
private string _workspaceId = "";
34+
35+
private string _discoveryUsername = "";
36+
private string _discoveryPassword = "";
37+
private string _discoveryUrl = "https://gateway.watsonplatform.net/discovery/api";
38+
39+
void Start()
40+
{
41+
LogSystem.InstallDefaultReactors();
42+
43+
// Create conversation instance
44+
Credentials conversationCredentials = new Credentials(_conversationUsername, _conversationPassword, _conversationUrl);
45+
Conversation conversation = new Conversation(conversationCredentials);
46+
conversation.VersionDate = "2017-05-26";
47+
48+
// Create discovery instance
49+
Credentials discoveryCredentials = new Credentials(_discoveryUsername, _discoveryPassword, _discoveryUrl);
50+
Discovery discovery = new Discovery(discoveryCredentials);
51+
discovery.VersionDate = "2016-12-01";
52+
53+
// Call with generic callbacks
54+
conversation.Message(OnSuccess, OnMessageFail, _workspaceId, "");
55+
discovery.GetEnvironments(OnSuccess, OnFail);
56+
57+
// Call with sepcific callbacks
58+
conversation.Message(OnMessage, OnGetEnvironmentsFail, _workspaceId, "");
59+
discovery.GetEnvironments(OnGetEnvironments, OnFail);
60+
}
61+
62+
// Generic success callback
63+
private void OnSuccess<T>(T resp, Dictionary<string, object> customData)
64+
{
65+
Log.Debug("ExampleCallback.OnSuccess()", "Response received: {0}", customData["json"].ToString());
66+
}
67+
68+
// Generic fail callback
69+
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
70+
{
71+
Log.Error("ExampleCallback.OnFail()", "Error received: {0}", error.ToString());
72+
}
73+
74+
// OnMessage callback
75+
private void OnMessage(object resp, Dictionary<string, object> customData)
76+
{
77+
Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", customData["json"].ToString());
78+
}
79+
80+
// OnGetEnvironments callback
81+
private void OnGetEnvironments(GetEnvironmentsResponse resp, Dictionary<string, object> customData)
82+
{
83+
Log.Debug("ExampleCallback.OnGetEnvironments()", "Response received: {0}", customData["json"].ToString());
84+
}
85+
86+
// OnMessageFail callback
87+
private void OnMessageFail(RESTConnector.Error error, Dictionary<string, object> customData)
88+
{
89+
Log.Error("ExampleCallback.OnMessageFail()", "Error received: {0}", error.ToString());
90+
}
91+
92+
// OnGetEnvironmentsFail callback
93+
private void OnGetEnvironmentsFail(RESTConnector.Error error, Dictionary<string, object> customData)
94+
{
95+
Log.Error("ExampleCallback.OnGetEnvironmentsFail()", "Error received: {0}", error.ToString());
96+
}
97+
}
98+
}

Examples/ServiceExamples/Scripts/ExampleCallback.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/ServiceExamples/Scripts/ExampleNaturalLanguageUnderstanding.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class ExampleNaturalLanguageUnderstanding : MonoBehaviour
2929
private string _username = null;
3030
private string _password = null;
3131
private string _url = null;
32-
private fsSerializer _serializer = new fsSerializer();
3332

3433
NaturalLanguageUnderstanding _naturalLanguageUnderstanding;
3534

Examples/ServiceExamples/ServiceExamples.unity

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.37311926, g: 0.38073996, b: 0.35872692, a: 1}
41+
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
4242
--- !u!157 &3
4343
LightmapSettings:
4444
m_ObjectHideFlags: 0
@@ -800,3 +800,43 @@ Transform:
800800
m_Father: {fileID: 0}
801801
m_RootOrder: 14
802802
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
803+
--- !u!1 &2041722972
804+
GameObject:
805+
m_ObjectHideFlags: 0
806+
m_PrefabParentObject: {fileID: 0}
807+
m_PrefabInternal: {fileID: 0}
808+
serializedVersion: 5
809+
m_Component:
810+
- component: {fileID: 2041722973}
811+
- component: {fileID: 2041722974}
812+
m_Layer: 0
813+
m_Name: ExampleCallback
814+
m_TagString: Untagged
815+
m_Icon: {fileID: 0}
816+
m_NavMeshLayer: 0
817+
m_StaticEditorFlags: 0
818+
m_IsActive: 1
819+
--- !u!4 &2041722973
820+
Transform:
821+
m_ObjectHideFlags: 0
822+
m_PrefabParentObject: {fileID: 0}
823+
m_PrefabInternal: {fileID: 0}
824+
m_GameObject: {fileID: 2041722972}
825+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
826+
m_LocalPosition: {x: 0, y: 3, z: 0}
827+
m_LocalScale: {x: 1, y: 1, z: 1}
828+
m_Children: []
829+
m_Father: {fileID: 0}
830+
m_RootOrder: 16
831+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
832+
--- !u!114 &2041722974
833+
MonoBehaviour:
834+
m_ObjectHideFlags: 0
835+
m_PrefabParentObject: {fileID: 0}
836+
m_PrefabInternal: {fileID: 0}
837+
m_GameObject: {fileID: 2041722972}
838+
m_Enabled: 1
839+
m_EditorHideFlags: 0
840+
m_Script: {fileID: 11500000, guid: 5c93a3595292dc6479dfb6e7c721838b, type: 3}
841+
m_Name:
842+
m_EditorClassIdentifier:
-1.95 MB
Binary file not shown.

Examples/ServiceExamples/TestData/test-audio.wav.meta

Lines changed: 0 additions & 22 deletions
This file was deleted.

Scripts/UnitTests/TestSpeechToText.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class TestSpeechToText : UnitTest
3636
private fsSerializer _serializer = new fsSerializer();
3737
//private string _token = "<authentication-token>";
3838

39-
private AudioClip _audioClip;
4039
private SpeechToText _speechToText;
4140

4241
private string _modelNameToGet;
@@ -138,8 +137,6 @@ public override IEnumerator RunTest()
138137
_speechToText = new SpeechToText(credentials);
139138
_customCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/theJabberwocky-utf8.txt";
140139
_customWordsFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-words.json";
141-
_wavFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-audio.wav";
142-
_audioClip = WaveFile.ParseWAV("testClip", File.ReadAllBytes(_wavFilePath));
143140
_acousticResourceMimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));
144141

145142
Runnable.Run(DownloadAcousticResource());

0 commit comments

Comments
 (0)