Skip to content

Commit

Permalink
Add device and build data to request headers
Browse files Browse the repository at this point in the history
Add device and build data to Stash request headers.
  • Loading branch information
oliexe committed Aug 19, 2024
1 parent 0578e5f commit fb467ef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
15 changes: 14 additions & 1 deletion Assets/Stash.Sample/Scripts/DeeplinkExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Stash.Core;
using Stash.Core.Exceptions;
using Stash.Models;
using Stash.Scripts.Core;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -38,9 +39,21 @@ private void Awake()
}
}

private void Start()
private async void Start()
{
Debug.Log("TRYING ");

try
{
LinkResponse response = await StashCustomLogin.LinkFacebook("LINK_CODE", "PLAYER_ID", "FB_APPID", "ACCESS_TOKEN", StashEnvironment.Test);

}
catch (StashRequestError e)
{
Console.WriteLine(e);
throw;
}

}


Expand Down
24 changes: 22 additions & 2 deletions Assets/Stash/Scripts/Core/RestClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Stash.Models;
using UnityEngine;
using UnityEngine.Networking;

namespace Stash.Core
Expand Down Expand Up @@ -80,11 +82,29 @@ public static async Task<Response> Post(string url, string body, IEnumerable<Req
webRequest.SetRequestHeader(header.Key, header.Value);
}
}

// Set default headers for a JSON request
// Set default Stash headers
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.SetRequestHeader("Accept", "application/json");

// Set analytics headers
try
{
webRequest.SetRequestHeader("x-stash-unity-sdk-version", StashConstants.SdkVersion);
webRequest.SetRequestHeader("x-stash-unity-platform", Application.platform.ToString());
webRequest.SetRequestHeader("x-stash-unity-runtime", Application.unityVersion);
webRequest.SetRequestHeader("x-stash-unity-build-guid", Application.buildGUID);
webRequest.SetRequestHeader("x-stash-unity-app-version", Application.version);
webRequest.SetRequestHeader("x-stash-unity-device-os", SystemInfo.operatingSystem);
webRequest.SetRequestHeader("x-stash-unity-device-model", SystemInfo.deviceModel);
webRequest.SetRequestHeader("x-stash-unity-device-type", SystemInfo.deviceType.ToString());
webRequest.SetRequestHeader("x-stash-unity-editor", Application.isEditor.ToString());
}
catch (Exception e)
{
Debug.Log("[STASH] Skipping analytics headers, error: " + e);
}

// Set the body payload and download handler for the request
webRequest.uploadHandler = new UploadHandlerRaw(bodyPayload);
webRequest.downloadHandler = new DownloadHandlerBuffer();
Expand Down
3 changes: 3 additions & 0 deletions Assets/Stash/Scripts/Core/StashConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace Stash.Core
{
public class StashConstants
{
//TODO: Switch to package file.
public const string SdkVersion = "0.9.0";

//Root URLs
public const string RootUrl = "https://api.stash.gg";
public const string RootUrlTest = "https://test-api.stash.gg";
Expand Down
4 changes: 2 additions & 2 deletions Assets/Stash/Scripts/Core/StashCustomLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public static class StashCustomLogin
/// <param name="code">Stash code challenge from the log in deeplink.</param>
/// <param name="playerId">Player identification, that will be used to identify purchases.</param>
/// <param name="idToken">Valid identification token (OICD) of the player.</param>
/// <param name="profileImageUrl">URL to the player's profile image/avatar to be displayed during login and on web shop.</param>
/// <param name="profileImageUrl">Profile image url of the player.</param>
/// <param name="environment">Stash API environment (Defaults to Test).</param>
/// <returns>Returns a confirmation response, or throws StashAPIRequestError if fails.</returns>
public static async Task<LinkResponse> CustomLogin(string code, string playerId, string idToken, string profileImageUrl, StashEnvironment environment = StashEnvironment.Test)
public static async Task<LinkResponse> CustomLogin(string code, string playerId, string idToken, string profileImageUrl = null, StashEnvironment environment = StashEnvironment.Test)
{
// Create the authorization header with the access token
RequestHeader authorizationHeader = new()
Expand Down

0 comments on commit fb467ef

Please sign in to comment.