Skip to content
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
9 changes: 9 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "daily"
time: "03:00"
timezone: "UTC"
open-pull-requests-limit: 5
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
/Assets/Plugins/.signature.p7s
/Assets/UnityXapiPublisher/Runtime/.vscode
reports
reports.meta
.clj-kondo
.lsp
.vscode
Binary file modified Assemblies/Microsoft.Bcl.AsyncInterfaces.dll
Binary file not shown.
Binary file modified Assemblies/RestSharp.dll
Binary file not shown.
Binary file added Assemblies/System.IO.Pipelines.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions Assemblies/System.IO.Pipelines.dll.meta

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

Binary file modified Assemblies/System.Runtime.CompilerServices.Unsafe.dll
Binary file not shown.
Binary file modified Assemblies/System.Text.Encodings.Web.dll
Binary file not shown.
Binary file modified Assemblies/System.Text.Json.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<configuration>
<packageSources>
<clear/>
<add key="NuGet" value="http://www.nuget.org/api/v2/" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<config>
<add key="repositoryPath" value="./Packages" />
<add key="DefaultPushSource" value="http://www.nuget.org/api/v2/" />
<add key="DefaultPushSource" value="https://www.nuget.org/api/v2/package" />
</config>
</configuration>
48 changes: 29 additions & 19 deletions Runtime/LRS/Domain/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static void InvokeStatementSent(JsonObject statement)
OnStatementSent?.Invoke(statement);
}

private JsonObject formAgent() {
private JsonObject formAgent()
{
bool hasEmail = PlayerPrefs.HasKey("LRSEmail");
bool hasAccount = PlayerPrefs.HasKey("LRSAccountId") && PlayerPrefs.HasKey("LRSHomepage");
if (hasEmail)
Expand Down Expand Up @@ -78,8 +79,14 @@ private JsonObject formAgent() {
private String gameId { get { return PlayerPrefs.GetString("LRSGameId"); } }
private String gameDisplay { get { return PlayerPrefs.GetString("LRSGameDisplay"); } }

private bool hasCustomActivityEnv { get { return PlayerPrefs.HasKey("LRSActivityId") &&
PlayerPrefs.HasKey("LRSActivityDefinition"); } }
private bool hasCustomActivityEnv
{
get
{
return PlayerPrefs.HasKey("LRSActivityId") &&
PlayerPrefs.HasKey("LRSActivityDefinition");
}
}

private String customActivityId { get { return PlayerPrefs.GetString("LRSActivityId"); } }
private String customActivityDefinition { get { return PlayerPrefs.GetString("LRSActivityDefinition"); } }
Expand Down Expand Up @@ -114,13 +121,13 @@ private async Task<JsonObject> GetLocation()
}

// otherwise, we go ahead and populate the cache by calling the API
return await Task.Run(async () =>
var request = new RestRequest($"json/{ip}");
location = await client.GetAsync<JsonObject>(request);
if (location != null)
{
location = await client.GetJsonAsync<JsonObject>(string.Format("json/{0}", ip));
downloadCache.TryAdd("location", location);

return location;
});
}
return location;
}

private async Task<JsonObject> FormBasicStatement(String verbId,
Expand Down Expand Up @@ -152,7 +159,8 @@ private async Task<JsonObject> FormBasicStatement(String verbId,
};

// location
if (enableUserLocation) {
if (enableUserLocation)
{
JsonObject loc = await this.locationTask;
contextExtension["http://ip-api.com/location"] = loc;
}
Expand All @@ -161,7 +169,8 @@ private async Task<JsonObject> FormBasicStatement(String verbId,
String activityDefinition = gameDisplay;

// if there's a custom ActivityID in the env, set activityId to that one.
if (hasCustomActivityEnv) {
if (hasCustomActivityEnv)
{
activityId = customActivityId;
activityDefinition = customActivityDefinition;
}
Expand All @@ -185,7 +194,7 @@ private async Task<JsonObject> FormBasicStatement(String verbId,
["platform"] = gameId,
["extensions"] = contextExtension
},
["timestamp"] = DateTime.UtcNow.ToString("o",CultureInfo.InvariantCulture)
["timestamp"] = DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)
};

return statementFn(statement);
Expand All @@ -203,14 +212,14 @@ private async Task<JsonObject> FormBasicStatement(String verbId,
String activityDescription,
Func<JsonObject, JsonObject> statementFn)
{
Func <JsonObject, JsonObject> setObjektFn = (s) =>
Func<JsonObject, JsonObject> setObjektFn = (s) =>
{
s["object"]["id"] = activityID;
s["object"]["definition"]["name"]["en-US"] = activityDescription;
return statementFn(s);

};
JsonObject statement = await FormBasicStatement(verbId,
JsonObject statement = await FormBasicStatement(verbId,
verbDisplay,
user,
gameId,
Expand Down Expand Up @@ -240,7 +249,8 @@ private JsonObject FormActivity(String activityID,
};
}

private void DebugStatements(string statement, RestResponse response) {
private void DebugStatements(string statement, RestResponse response)
{
Debug.Log(statement);
Debug.Log(response.Content);
Debug.Log(response.ResponseStatus);
Expand Down Expand Up @@ -280,7 +290,7 @@ public void SendCompletedStatement(String activityID,
public async void SendStatement(String verbId,
String verbDisplay)
{
Func <JsonObject, JsonObject> identity = (s) =>
Func<JsonObject, JsonObject> identity = (s) =>
{
return s;
};
Expand All @@ -300,7 +310,7 @@ public async void SendStatement(String verbId,

public async void SendStatement(String verbId,
String verbDisplay,
Func <JsonObject, JsonObject> statementFn)
Func<JsonObject, JsonObject> statementFn)
{
var statement = await FormBasicStatement(verbId,
verbDisplay,
Expand All @@ -321,7 +331,7 @@ public async void SendStatement(String verbId,
String activityID,
String activityDisplay)
{
Func <JsonObject, JsonObject> identity = (s) =>
Func<JsonObject, JsonObject> identity = (s) =>
{
return s;
};
Expand All @@ -345,7 +355,7 @@ public async void SendStatement(String verbId,
String verbDisplay,
String activityID,
String activityDisplay,
Func <JsonObject, JsonObject> statementFn)
Func<JsonObject, JsonObject> statementFn)
{
var statement = await FormBasicStatement(verbId,
verbDisplay,
Expand All @@ -370,7 +380,7 @@ async void SendCustomStatement(String verbId,
String gameDisplay,
String registrationIdentifier)
{
Func <JsonObject, JsonObject> identity = (s) =>
Func<JsonObject, JsonObject> identity = (s) =>
{
return s;
};
Expand Down
25 changes: 15 additions & 10 deletions Runtime/LRS/Sender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
using System.Threading.Tasks;


namespace LRS {
public class Sender {
namespace LRS
{
public class Sender
{
public Sender(String LRSUrl,
String LRSKey,
String LRSSecret)
String LRSSecret)
{
this.LRSUrl = LRSUrl;
this.LRSKey = LRSKey;
this.LRSSecret = LRSSecret;
}

private String LRSUrl {set;get;}
private String LRSKey {set;get;}
private String LRSSecret {set;get;}
private String LRSUrl { set; get; }
private String LRSKey { set; get; }
private String LRSSecret { set; get; }

public async Task<RestResponse> SendStatement(String statement) {
var client = new RestClient(LRSUrl) {
Authenticator = new HttpBasicAuthenticator(LRSKey,LRSSecret)
public async Task<RestResponse> SendStatement(String statement)
{
var options = new RestClientOptions(LRSUrl)
{
Authenticator = new HttpBasicAuthenticator(LRSKey, LRSSecret)
};
var client = new RestClient(options);
var request = new RestRequest("/xapi/statements", Method.Post);
request.AddHeader("Accept", "application/json");
request.AddStringBody(statement,DataFormat.Json);
request.AddStringBody(statement, DataFormat.Json);
request.AddHeader("X-Experience-API-Version", "1.0.1");
return await client.ExecutePostAsync(request);
}
Expand Down
Loading