Exemplo n.º 1
0
 /// <summary>
 /// Fetches the history of transactions run for this user. The current balance (resulting values) needs to be queried
 /// via a different call (Balance).
 /// </summary>
 /// <returns>Promise resolved when the operation has completed. The result is paginated, for more information see
 ///     #CotcSdk.PagedList<DataType>.</returns>
 /// <param name="unit">If specified, retrieves only the transactions matching a given unit (e.g. "gold").</param>
 /// <param name="limit">For pagination, allows to set a greater or smaller page size than the default 30.</param>
 /// <param name="offset">For pagination, avoid using it explicitly.</param>
 public Promise<PagedList<Transaction>> History(string unit = null, int limit = 30, int offset = 0)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/tx").Path(domain).QueryParam("skip", offset).QueryParam("limit", limit);
     if (unit != null) url.QueryParam("unit", unit);
     // Request for current results
     return Common.RunInTask<PagedList<Transaction>>(Gamer.MakeHttpRequest(url), (response, task) => {
         PagedList<Transaction> transactions = new PagedList<Transaction>(response.BodyJson, offset, response.BodyJson["count"]);
         foreach (Bundle b in response.BodyJson["history"].AsArray()) {
             transactions.Add(new Transaction(b));
         }
         // Handle pagination
         if (offset > 0) {
             transactions.Previous = () => History(unit, limit, offset - limit);
         }
         if (offset + transactions.Count < transactions.Total) {
             transactions.Next = () => History(unit, limit, offset + limit);
         }
         task.PostResult(transactions);
     });
 }