/// <summary> /// Constructs a request with the given bytes to be sent. Useful for nested JSON data, which can /// be constructed beforehand. Don't use for GET. /// </summary> /// <param name="method"></param> /// <param name="bytes"></param> public RESTRequest(HTTPMethod method, byte[] bytes, OnRequestFinish callback) { this.thisCallback = callback; this.method = method; this.bytes = bytes; this.headers = new Dictionary <string, string>(); rawBytes = true; }
/// <summary> /// Constructs an empty RESTRequest object with the given method set. /// </summary> /// <param name="method">The method to use for the request.</param> public RESTRequest(HTTPMethod method, OnRequestFinish callback) { this.thisCallback = callback; this.method = method; this.stringParameters = new Dictionary <string, string>(); this.numericParameters = new Dictionary <string, int>(); this.headers = new Dictionary <string, string>(); this.noParameters = 0; this.rawBytes = false; }
/// <summary> /// REST request with an empty callback function. Can still gather data if you manually check that the request is finishe /// </summary> public RESTRequest() { this.thisCallback = null; this.method = HTTPMethod.GET; this.stringParameters = new Dictionary <string, string>(); this.numericParameters = new Dictionary <string, int>(); this.headers = new Dictionary <string, string>(); this.noParameters = 0; this.rawBytes = false; }
/// <summary> /// Method that will be called to load all the items available /// for purchase from the backend server /// </summary> public static void LoadAll(OnRequestFinish callback) { string getAllProductsUrl = string.Format( "/games/{0}/products", Proba.Configuration.GameId ); Request request = new Request(getAllProductsUrl); request.Get().onFinish += (r) => { ProductCollection collection = JsonUtility.FromJson <ProductCollection>(r.Response); callback(collection); }; }
/// <summary> /// Get a collection of all the achievements available /// to the player so we can display them in the game /// </summary> public static void List(OnRequestFinish callback) { string achievementsListUrl = string.Format( "/games/{0}/achievements", Proba.Configuration.GameId ); Request request = new Request(achievementsListUrl); request.Get().onFinish += (r) => { AchievementCollection collection = JsonUtility.FromJson <AchievementCollection>(r.Response); callback(collection); }; }
/// <summary> /// This will retrieve the data for the player. Since the data can change depending /// on the game we need to pass the reponse serializable definition so we can /// parse it from the APIs JSON response /// </summary> public static void LoadData(OnRequestFinish callback) { string playerDataUrl = string.Format( "/games/{0}/player/data", Proba.Configuration.GameId ); Request request = new Request(playerDataUrl); request.Get().onFinish += (r) => { PlayerDataResponse response = JsonUtility.FromJson <PlayerDataResponse>(r.Response); callback(response.data); }; }