// Copyright (c) Proyecto 26. // Licensed under the MIT License. using System; using UnityEngine.Networking; using System.Collections.Generic; namespace Proyecto26 { /// /// RestClient for Unity /// Version: 2.6.0 /// public static partial class RestClient { #region Common /// /// Gets the version of the RestClient library. /// public static System.Version Version { get { return typeof(RestClient).Assembly.GetName().Version; } } /// /// Default query string params. /// private static Dictionary _defaultRequestParams; public static Dictionary DefaultRequestParams { get { if (_defaultRequestParams == null) { _defaultRequestParams = new Dictionary(); } return _defaultRequestParams; } set { _defaultRequestParams = value; } } /// /// Clear default query string params. /// public static void ClearDefaultParams() { DefaultRequestParams.Clear(); } /// /// Default headers. /// private static Dictionary _defaultRequestHeaders; public static Dictionary DefaultRequestHeaders { get { if (_defaultRequestHeaders == null) { _defaultRequestHeaders = new Dictionary(); } return _defaultRequestHeaders; } set { _defaultRequestHeaders = value; } } /// /// Clear default headers. /// public static void ClearDefaultHeaders() { DefaultRequestHeaders.Clear(); } #endregion #region Callbacks /// /// Create an HTTP request with the specified options and callback. /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Request(RequestHelper options, Action callback) { StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback)); } /// /// Create an HTTP request with the specified options and callback. /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Request(RequestHelper options, Action callback) { StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback)); } /// /// Load data from the server using a HTTP GET request. /// /// A string containing the URL to which the request is sent. /// A callback function that is executed when the request is finished. public static void Get(string url, Action callback) { Get(new RequestHelper { Uri = url }, callback); } /// /// Load data from the server using a HTTP GET request. /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Get(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbGET; Request(options, callback); } /// /// Load data from the server using a HTTP GET request. /// /// A string containing the URL to which the request is sent. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Get(string url, Action callback) { Get(new RequestHelper { Uri = url }, callback); } /// /// Load data from the server using a HTTP GET request. /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Get(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbGET; Request(options, callback); } /// /// Load a JSON array from the server using a HTTP GET request /// /// A string containing the URL to which the request is sent. /// A callback function that is executed when the request is finished. /// The element type of the array. public static void GetArray(string url, Action callback) { GetArray(new RequestHelper { Uri = url }, callback); } /// /// Load a JSON array from the server using a HTTP GET request /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the array. public static void GetArray(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbGET; StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback)); } /// /// Load data from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A plain object that is sent to the server with the request. /// A callback function that is executed when the request is finished. public static void Post(string url, object body, Action callback) { Post(new RequestHelper { Uri = url, Body = body }, callback); } /// /// Load data from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A string that is sent to the server with the request. /// A callback function that is executed when the request is finished. public static void Post(string url, string bodyString, Action callback) { Post(new RequestHelper { Uri = url, BodyString = bodyString }, callback); } /// /// Load data from the server using a HTTP POST request. /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Post(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbPOST; Request(options, callback); } /// /// Load data from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A plain object that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Post(string url, object body, Action callback) { Post(new RequestHelper { Uri = url, Body = body }, callback); } /// /// Load data from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A string that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Post(string url, string bodyString, Action callback) { Post(new RequestHelper { Uri = url, BodyString = bodyString }, callback); } /// /// Load data from the server using a HTTP POST request. /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Post(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbPOST; Request(options, callback); } /// /// Load a JSON array from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A plain object that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the array. public static void PostArray(string url, object body, Action callback) { PostArray(new RequestHelper { Uri = url, Body = body }, callback); } /// /// Load a JSON array from the server using a HTTP POST request. /// /// A string containing the URL to which the request is sent. /// A string that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the array. public static void PostArray(string url, string bodyString, Action callback) { PostArray(new RequestHelper { Uri = url, BodyString = bodyString }, callback); } /// /// Load a JSON array from the server using a HTTP POST request. /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the array. public static void PostArray(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbPOST; StaticCoroutine.StartCoroutine(HttpBase.DefaultUnityWebRequest(options, callback)); } /// /// Load data from the server using a HTTP PUT request. /// /// A string containing the URL to which the request is sent. /// A plain object that is sent to the server with the request. /// A callback function that is executed when the request is finished. public static void Put(string url, object body, Action callback) { Put(new RequestHelper { Uri = url, Body = body }, callback); } /// /// Load data from the server using a HTTP PUT request. /// /// A string containing the URL to which the request is sent. /// A string that is sent to the server with the request. /// A callback function that is executed when the request is finished. public static void Put(string url, string bodyString, Action callback) { Put(new RequestHelper { Uri = url, BodyString = bodyString }, callback); } /// /// Load data from the server using a HTTP PUT request. /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Put(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbPUT; Request(options, callback); } /// /// Load data from the server using a HTTP PUT request. /// /// A string containing the URL to which the request is sent. /// A plain object that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Put(string url, object body, Action callback) { Put(new RequestHelper { Uri = url, Body = body }, callback); } /// /// Load data from the server using a HTTP PUT request. /// /// A string containing the URL to which the request is sent. /// A string that is sent to the server with the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Put(string url, string bodyString, Action callback) { Put(new RequestHelper { Uri = url, BodyString = bodyString }, callback); } /// /// Load data from the server using a HTTP PUT request. /// /// The options of the request. /// A callback function that is executed when the request is finished. /// The element type of the response. public static void Put(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbPUT; Request(options, callback); } /// /// Delete the specified resource identified by the URI. /// /// A string containing the URL to which the request is sent. /// A callback function that is executed when the request is finished. public static void Delete(string url, Action callback) { Delete(new RequestHelper { Uri = url }, callback); } /// /// Delete the specified resource identified by the URI. /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Delete(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbDELETE; Request(options, callback); } /// /// Request the headers that are returned from the server /// /// A string containing the URL to which the request is sent. /// A callback function that is executed when the request is finished. public static void Head(string url, Action callback) { Head(new RequestHelper { Uri = url }, callback); } /// /// Request the headers that are returned from the server /// /// The options of the request. /// A callback function that is executed when the request is finished. public static void Head(RequestHelper options, Action callback) { options.Method = UnityWebRequest.kHttpVerbHEAD; Request(options, callback); } #endregion } }