Пример #1
0
        /// <summary>
        /// Query user entitlements.
        /// </summary>
        /// <param name="entitlementName">The name of the entitlement (optional)</param>
        /// <param name="itemId">Item's id (optional)</param>
        /// <param name="offset">Offset of the list that has been sliced based on Limit parameter (optional, default = 0)</param>
        /// <param name="limit">The limit of item on page (optional)</param>
        /// <param name="callback">Returns a Result that contains EntitlementPagingSlicedResult via callback when completed</param>
        /// <param name="entitlementClazz">Class of the entitlement (optional)</param>
        /// <param name="entitlementAppType">This is the type of application that entitled (optional)</param>
        public void QueryUserEntitlements(string entitlementName, string itemId, int offset, int limit, ResultCallback <EntitlementPagingSlicedResult> callback,
                                          EntitlementClazz entitlementClazz = EntitlementClazz.NONE, EntitlementAppType entitlementAppType = EntitlementAppType.NONE)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(entitlementName, "Can't query user entitlements! EntitlementName parameter is null!");
            Assert.IsNotNull(itemId, "Can't query user entitlements! ItemId parameter is null!");

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(
                this.api.QueryUserEntitlements(
                    this.@namespace,
                    this.session.UserId,
                    this.session.AuthorizationToken,
                    entitlementName,
                    itemId,
                    offset,
                    limit,
                    entitlementClazz,
                    entitlementAppType,
                    callback));
        }
Пример #2
0
        public IEnumerator QueryUserEntitlements(string @namespace, string userId, string userAccessToken, string entitlementName, string itemId, int offset,
                                                 int limit, EntitlementClazz entitlementClazz, EntitlementAppType entitlementAppType, ResultCallback <EntitlementPagingSlicedResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't get user entitlements! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't get user entitlements! UserId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't get user entitlements! UserAccessToken parameter is null!");

            var request = HttpRequestBuilder
                          .CreateGet(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/entitlements")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithQueryParam("entitlementClazz", (entitlementClazz == EntitlementClazz.NONE) ? "" : entitlementClazz.ToString())
                          .WithQueryParam("entitlementAppType", (entitlementAppType == EntitlementAppType.NONE) ? "" : entitlementAppType.ToString())
                          .WithQueryParam("entitlementName", entitlementName)
                          .WithQueryParam("itemId", itemId)
                          .WithQueryParam("offset", (offset >= 0) ? offset.ToString() : "")
                          .WithQueryParam("limit", (limit >= 0)? limit.ToString() : "")
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

            yield return(this.httpClient.SendRequest(request, rsp => response = rsp));

            var result = response.TryParseJson <EntitlementPagingSlicedResult>();

            callback.Try(result);
        }