Skip to content

Commit 1be31bf

Browse files
committed
feat: Created a commmon class to get default headers
1 parent 1174348 commit 1be31bf

13 files changed

+227
-15
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ message = [skip ci] docs: Update version numbers from {current_version} -> {new_
55

66
[bumpversion:file:Doxyfile]
77

8-
[bumpversion:file:Scripts/Utilities/Constants.cs]
8+
[bumpversion:file:Common/Common.cs]
99
search = {current_version}
1010
replace = {new_version}

Common.meta

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

Common/Common.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2019 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.Cloud.SDK.Utilities;
19+
using System.Collections.Generic;
20+
using UnityEngine;
21+
22+
namespace IBM.Watson
23+
{
24+
public class Common : MonoBehaviour
25+
{
26+
public const string Version = "watson-apis-unity-sdk-2.12.0";
27+
/// <summary>
28+
/// Returns a set of default headers to use with each request.
29+
/// </summary>
30+
/// <param name="serviceName">The service name to be used in X-IBMCloud-SDK-Analytics header.</param>
31+
/// <param name="serviceVersion">The service version to be used in X-IBMCloud-SDK-Analytics header.</param>
32+
/// <param name="operation">The operation name to be used in X-IBMCloud-SDK-Analytics header.</param>
33+
/// <returns></returns>
34+
public static Dictionary<string, string> GetDefaultheaders(string serviceName, string serviceVersion, string operationId)
35+
{
36+
Dictionary<string, string> defaultHeaders = new Dictionary<string, string>();
37+
defaultHeaders.Add("X-IBMCloud-SDK-Analytics",
38+
string.Format("service_name={0};service_version={1};operation_id={2}",
39+
serviceName,
40+
serviceVersion,
41+
operationId));
42+
defaultHeaders.Add("User-Agent",
43+
string.Format(
44+
"{0} {1} {2} {3}",
45+
Version,
46+
SystemInformation.Os,
47+
SystemInformation.OsVersion,
48+
Application.unityVersion
49+
));
50+
return defaultHeaders;
51+
}
52+
}
53+
}

Common/Common.cs.meta

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

Core/Connection/RESTConnector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ private void AddHeaders(Dictionary<string, string> headers)
344344
headers[kp.Key] = kp.Value;
345345
}
346346
}
347-
348-
headers.Add("User-Agent", Constants.String.Version);
349347
}
350348

351349
private IEnumerator ProcessRequestQueue()

Core/Utilities/Constants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public static class Path
4646
/// </summary>
4747
public static class String
4848
{
49-
/// <exclude />
50-
public const string Version = "watson-apis-unity-sdk/2.12.0";
5149
/// <exclude />
5250
public const string DebugDispalyQuality = "Quality: {0}";
5351
/// <summary>

Core/Utilities/SystemInformation.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright 2019 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 System;
19+
using System.Collections;
20+
using System.Collections.Generic;
21+
using System.Text;
22+
using UnityEngine;
23+
using UnityEngine.Networking;
24+
using System.Text.RegularExpressions;
25+
26+
namespace IBM.Cloud.SDK.Utilities
27+
{
28+
public static class SystemInformation
29+
{
30+
private static string osInfo = null;
31+
public static string OsInfo
32+
{
33+
get
34+
{
35+
if (string.IsNullOrEmpty(osInfo))
36+
{
37+
osInfo = SystemInfo.operatingSystem;
38+
}
39+
40+
return osInfo;
41+
}
42+
}
43+
44+
private static string os = null;
45+
public static string Os
46+
{
47+
get
48+
{
49+
if (string.IsNullOrEmpty(os))
50+
{
51+
string tempos = OsInfo.Replace(OsVersion, "").Replace(" ", "");
52+
if (tempos.Contains("()"))
53+
{
54+
os = tempos.Replace("()", "-");
55+
}
56+
}
57+
58+
return os;
59+
}
60+
}
61+
62+
private static string osVersion = null;
63+
public static string OsVersion
64+
{
65+
get
66+
{
67+
if (string.IsNullOrEmpty(osVersion))
68+
{
69+
Regex pattern = new Regex("\\d+(\\.\\d+)+");
70+
Match m = pattern.Match(OsInfo);
71+
osVersion = m.Value;
72+
}
73+
74+
return osVersion;
75+
}
76+
}
77+
}
78+
}

Core/Utilities/SystemInformation.cs.meta

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

Tests/CoreTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2019 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 System.Collections;
19+
using System.Collections.Generic;
20+
using NUnit.Framework;
21+
using UnityEngine;
22+
using UnityEngine.TestTools;
23+
24+
namespace IBM.Watson.Tests
25+
{
26+
public class CoreTests
27+
{
28+
[Test]
29+
public void TestGetDefaultHeaders()
30+
{
31+
Dictionary<string, string> defaultHeaders = Common.GetDefaultheaders("TestSevice", "V1", "TestOperation");
32+
Assert.IsNotNull(defaultHeaders);
33+
Assert.IsTrue(defaultHeaders.Count == 2);
34+
35+
}
36+
}
37+
}

Tests/CoreTests.cs.meta

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

Tests/IBM.Watson.Tests.asmdef

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "IBM.Watson.Tests",
3+
"references": [
4+
"WatsonUnitySDK"
5+
],
6+
"optionalUnityReferences": [
7+
"TestAssemblies"
8+
],
9+
"includePlatforms": [],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": false,
13+
"precompiledReferences": [],
14+
"autoReferenced": true,
15+
"defineConstraints": []
16+
}

Tests/Tests.asmdef.meta renamed to Tests/IBM.Watson.Tests.asmdef.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/Tests.asmdef

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

0 commit comments

Comments
 (0)