Skip to content

Common class for headers #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ message = [skip ci] docs: Update version numbers from {current_version} -> {new_

[bumpversion:file:Doxyfile]

[bumpversion:file:Scripts/Utilities/Constants.cs]
[bumpversion:file:Common/Common.cs]
search = {current_version}
replace = {new_version}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ before_script:
script:
- ./Travis/createProject.sh
- ./Travis/installSDK.sh
- ./Travis/runTests.sh
# - ./Travis/runTests.sh
# - ./Travis/build.sh
deploy:
- provider: script
Expand Down
8 changes: 8 additions & 0 deletions Common.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Common/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using IBM.Cloud.SDK.Utilities;
using System.Collections.Generic;
using UnityEngine;

namespace IBM.Watson
{
public class Common : MonoBehaviour
{
public const string Version = "watson-apis-unity-sdk-2.12.0";
/// <summary>
/// Returns a set of default headers to use with each request.
/// </summary>
/// <param name="serviceName">The service name to be used in X-IBMCloud-SDK-Analytics header.</param>
/// <param name="serviceVersion">The service version to be used in X-IBMCloud-SDK-Analytics header.</param>
/// <param name="operation">The operation name to be used in X-IBMCloud-SDK-Analytics header.</param>
/// <returns></returns>
public static Dictionary<string, string> GetDefaultheaders(string serviceName, string serviceVersion, string operationId)
{
Dictionary<string, string> defaultHeaders = new Dictionary<string, string>();
defaultHeaders.Add("X-IBMCloud-SDK-Analytics",
string.Format("service_name={0};service_version={1};operation_id={2}",
serviceName,
serviceVersion,
operationId));
defaultHeaders.Add("User-Agent",
string.Format(
"{0} {1} {2} {3}",
Version,
SystemInformation.Os,
SystemInformation.OsVersion,
Application.unityVersion
));
return defaultHeaders;
}
}
}
11 changes: 11 additions & 0 deletions Common/Common.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Core/Connection/RESTConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ private void AddHeaders(Dictionary<string, string> headers)
headers[kp.Key] = kp.Value;
}
}

headers.Add("User-Agent", Constants.String.Version);
}

private IEnumerator ProcessRequestQueue()
Expand Down
2 changes: 0 additions & 2 deletions Core/Utilities/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public static class Path
/// </summary>
public static class String
{
/// <exclude />
public const string Version = "watson-apis-unity-sdk/2.12.0";
/// <exclude />
public const string DebugDispalyQuality = "Quality: {0}";
/// <summary>
Expand Down
78 changes: 78 additions & 0 deletions Core/Utilities/SystemInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using System.Text.RegularExpressions;

namespace IBM.Cloud.SDK.Utilities
{
public static class SystemInformation
{
private static string osInfo = null;
public static string OsInfo
{
get
{
if (string.IsNullOrEmpty(osInfo))
{
osInfo = SystemInfo.operatingSystem;
}

return osInfo;
}
}

private static string os = null;
public static string Os
{
get
{
if (string.IsNullOrEmpty(os))
{
string tempos = OsInfo.Replace(OsVersion, "").Replace(" ", "");
if (tempos.Contains("()"))
{
os = tempos.Replace("()", "-");
}
}

return os;
}
}

private static string osVersion = null;
public static string OsVersion
{
get
{
if (string.IsNullOrEmpty(osVersion))
{
Regex pattern = new Regex("\\d+(\\.\\d+)+");
Match m = pattern.Match(OsInfo);
osVersion = m.Value;
}

return osVersion;
}
}
}
}
11 changes: 11 additions & 0 deletions Core/Utilities/SystemInformation.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading