// Copyright (c) 2024 Synty Studios Limited. All rights reserved. // // Use of this software is subject to the terms and conditions of the Synty Studios End User Licence Agreement (EULA) // available at: https://syntystore.com/pages/end-user-licence-agreement // // For additional details, see the LICENSE.MD file bundled with this software. #if UNITY_EDITOR using System.Collections.Generic; using System.Net; using UnityEngine.Networking; namespace Synty.SidekickCharacters.Network { /// /// Manages all URLs used in the application to communicate with the Synty API. /// internal static class UrlManager { // Base URL private const string _BASE_URL = "https://api.syntystudios.com/"; // API version we're connecting to private const int _API_VERSION = 1; // API URLs private const string _API_GET_DB_UPDATE = "sidekick-database"; /// /// Creates a new POST request built from the provided URL and form data with the api key added into the header if required. /// /// The URL to attach the post request to. /// Any form data to attach to the request. /// The api key to use, if required. /// A UnityWebRequest.POST with the given details. public static UnityWebRequest CreatePostRequest(string url, List formData, string apiKey = "") { UnityWebRequest webRequest = UnityWebRequest.Post(url, formData); if (apiKey != "") { webRequest.SetRequestHeader("Authorization", "Bearer " + apiKey); } return webRequest; } /// /// Creates a new GET request built from the provided URL with the api key added into the header if required. /// /// The URL to attach the post request to. /// The api key to use, if required. /// A UnityWebRequest.GET with the given details. public static UnityWebRequest CreateGetRequest(string url, string apiKey = "") { UnityWebRequest webRequest = UnityWebRequest.Get(url); if (apiKey != "") { webRequest.SetRequestHeader("Authorization", "Bearer " + apiKey); } return webRequest; } /// /// Returns the base API URL. /// /// The base API URL. private static string GetBaseUrl() { return _BASE_URL + "api/v" + _API_VERSION + "/"; } /// /// Gets the Sidekick DB update URL. /// /// The Sidekick DB URL. public static string GetDbUpdateUrl() { // TODO : do we still need this encoding? // As this URL contains "unsafe" characters, we encode them first. return GetBaseUrl() + WebUtility.UrlEncode(_API_GET_DB_UPDATE); } } } #endif