public IEnumerator UpdateUserProfile(string @namespace, string userAccessToken,
                                             UpdateUserProfileRequest updateRequest, ResultCallback <UserProfile> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update user profile! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't update user profile! UserAccessToken parameter is null!");
            Assert.IsNotNull(updateRequest, "Can't update user profile! ProfileRequest parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/users/me/profiles")
                          .WithPathParam("namespace", @namespace)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(updateRequest.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator SetSessionAttribute(string @namespace, string accessToken, string userId, Dictionary <string, string> attributes, ResultCallback callback)
        {
            Assert.IsFalse(string.IsNullOrEmpty(@namespace), "namespace cannot be null or empty");
            Assert.IsFalse(string.IsNullOrEmpty(accessToken), "accessToken cannot be null or empty");
            Assert.IsFalse(string.IsNullOrEmpty(userId), "userId cannot be null or empty");
            Assert.IsFalse(attributes == null || attributes.Count == 0, "attributes cannot be null or empty.");

            ServerSetSessionAttributeRequest body = new ServerSetSessionAttributeRequest()
            {
                attributes = attributes
            };

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/admin/player/namespaces/{namespace}/users/{userId}/attributes")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(body.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator UpdateUserStatItems(string @namespace, string userId, string additionalKey, StatItemUpdate[] data,
                                               string accessToken, ResultCallback <StatItemOperationResult[]> callback)
        {
            Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null");
            Assert.IsNotNull(userId, nameof(userId) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");
            Assert.IsNotNull(data, nameof(data) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v2/admin/namespaces/{namespace}/users/{userId}/statitems/value/bulk")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithQueryParam("additionalKey", additionalKey)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(data.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <StatItemOperationResult[]>();

            callback.Try(result);
        }
        public IEnumerator UpdateUserStatItems(string @namespace, string userId, string additionalKey, StatItemUpdate[] updates, string accessToken, ResultCallback <StatItemOperationResult[]> callback)
        {
            Assert.IsNotNull(@namespace, "Can't add stat item value! namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't add stat item value! accessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't add stat item value! userId parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v2/public/namespaces/{namespace}/users/{userId}/statitems/value/bulk")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithQueryParam("additionalKey", additionalKey)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(updates.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <StatItemOperationResult[]>();

            callback.Try(result);
        }
Exemple #5
0
        public IEnumerator ConsumeUserEntitlement(string @namespace, string userId, string userAccessToken, string entitlementId, int useCount,
                                                  ResultCallback <EntitlementInfo> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't consume user entitlement! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't consume user entitlement! userId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't consume user entitlement! userAccessToken parameter is null!");
            Assert.IsNotNull(entitlementId, "Can't consume user entitlement! entitlementId parameter is null!");

            ConsumeUserEntitlementRequest consumeUserEntitlement = new ConsumeUserEntitlementRequest
            {
                useCount = useCount
            };

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/entitlements/{entitlementId}/decrement")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("entitlementId", entitlementId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(consumeUserEntitlement.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator CreditUserWallet(string @namespace, string userId, string accessToken, string currencyCode,
                                            CreditUserWalletRequest creditUserWalletRequest, ResultCallback <WalletInfo> callback)
        {
            Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null");
            Assert.IsNotNull(userId, nameof(userId) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");
            Assert.IsNotNull(currencyCode, nameof(currencyCode) + " cannot be null");
            Assert.IsNotNull(creditUserWalletRequest, nameof(creditUserWalletRequest) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/admin/namespaces/{namespace}/users/{userId}/wallets/{currencyCode}/credit")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("currencyCode", currencyCode)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(creditUserWalletRequest.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator WritePartyStorage(string @namespace, string accessToken, PartyDataUpdateRequest data,
                                             string partyId, ResultCallback <PartyDataUpdateNotif> callback, Action callbackOnConflictedData = null)
        {
            Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");
            Assert.IsNotNull(partyId, nameof(partyId) + " cannot be null");
            Assert.IsNotNull(data, nameof(data) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/admin/party/namespaces/{namespace}/parties/{partyId}/attributes")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("partyId", partyId)
                          .WithBearerAuth(accessToken)
                          .WithBody(data.ToUtf8Json())
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            if (result.IsError && result.Error.Code == ErrorCode.PreconditionFailed)
            {
                callbackOnConflictedData?.Invoke();
            }
            else
            {
                callback.Try(result);
            }
        }
        public IEnumerator <ITask> Update(string @namespace, string userId, string userAccessToken,
                                          UpdateUserRequest updateUserRequest, ResultCallback <UserData> callback)
        {
            Assert.IsNotNull(@namespace, "Can't update user! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't update user! UserAccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't update user! UserId parameter is null!");
            Assert.IsNotNull(updateUserRequest, "Can't update user! Request parameter is null!");

            var strUpdateRequest = SimpleJson.SimpleJson.SerializeObject(updateUserRequest);

            var request =
                HttpRequestBuilder.CreatePut(this.baseUrl + "/iam/namespaces/{namespace}/users/{userId}")
                .WithPathParam("namespace", @namespace)
                .WithPathParam("userId", userId)
                .WithBearerAuth(userAccessToken)
                .WithContentType(MediaType.ApplicationJson)
                .WithBody(strUpdateRequest)
                .Accepts(MediaType.ApplicationJson)
                .ToRequest();

            HttpWebResponse response = null;

            yield return(Task.Await(request, rsp => response = rsp));

            var result = response.TryParseJsonBody <UserData>();

            callback.Try(result);
        }
        public IEnumerator ReplaceGameRecord(string @namespace, string accessToken, string key,
                                             ConcurrentReplaceRequest data, ResultCallback callback, Action callbackOnConflictedData = null)
        {
            Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");
            Assert.IsNotNull(key, nameof(key) + " cannot be null");
            Assert.IsNotNull(data, nameof(data) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/namespaces/{namespace}/concurrent/records/{key}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("key", key)
                          .WithBearerAuth(accessToken)
                          .WithBody(data.ToUtf8Json())
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            if (result.IsError && result.Error.Code == ErrorCode.GameRecordPreconditionFailed && callbackOnConflictedData != null)
            {
                callbackOnConflictedData?.Invoke();
            }
            else
            {
                callback.Try(result);
            }
        }
        public IEnumerator UpdateGameProfileAtrribute(string @namespace, string userId, string accessToken,
                                                      string profileId, GameProfileAttribute attribute, ResultCallback <GameProfile> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update a game profile attribute! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a game profile attribute! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a game profile attribute! accessToken parameter is null!");
            Assert.IsNotNull(profileId, "Can't update a game profile attribute! profileId parameter is null!");
            Assert.IsNotNull(attribute, "Can't update a game profile attribute! attribute parameter is null!");
            Assert.IsNotNull(attribute.name, "Can't update a game profile attribute! attribute.name is null!");

            var request = HttpRequestBuilder
                          .CreatePut(
                this.baseUrl +
                "/public/namespaces/{namespace}/users/{userId}/profiles/{profileId}/attributes/{attributeName}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("profileId", profileId)
                          .WithPathParam("attributeName", attribute.name)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(attribute.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator UpdateGroupPredefinedRule(string namespace_, string accessToken, string groupId, AllowedAction allowedAction, UpdateGroupPredefinedRuleRequest ruleUpdateRequest,
                                                     ResultCallback <GroupInformation> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsFalse(string.IsNullOrEmpty(namespace_), "Can't update group predefined rule! Namespace parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(accessToken), "Can't update group predefined rule! AccessToken parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(groupId), "Can't update group predefined rule! GroupId parameter is null!");
            Assert.AreNotEqual(AllowedAction.None, allowedAction, "Can't update group predefined rule! allowedAction parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/groups/{groupId}/rules/defined/{allowedAction}")
                          .WithPathParam("namespace", namespace_)
                          .WithPathParam("groupId", groupId)
                          .WithPathParam("allowedAction", allowedAction.ToString())
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(ruleUpdateRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator UpdateGroupCustomRule(string namespace_, string accessToken, string groupId, Dictionary <string, object> ruleUpdateRequest,
                                                 ResultCallback <GroupInformation> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsFalse(string.IsNullOrEmpty(namespace_), "Can't update group custon rule! Namespace parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(accessToken), "Can't update group custon rule! AccessToken parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(groupId), "Can't update group custon rule! GroupId parameter is null!");

            UpdateGroupCustomRuleRequest customRule = new UpdateGroupCustomRuleRequest {
                groupCustomRule = ruleUpdateRequest
            };

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/groups/{groupId}/rules/custom")
                          .WithPathParam("namespace", namespace_)
                          .WithPathParam("groupId", groupId)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(customRule.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator ReplaceGameRecord(string @namespace, string accessToken, string key, Dictionary <string, object> recordRequest,
                                             ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't replace game record! Namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't replace game record! AccessToken parameter is null!");
            Assert.IsNotNull(key, "Can't replace game record! Key parameter is null!");
            Assert.IsNotNull(recordRequest, "Can't replace game record! recordRequest parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/namespaces/{namespace}/records/{key}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("key", key)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(recordRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
Exemple #14
0
        public IEnumerator UpdateDistributionReceiver(string @namespace, string userId, string userAccessToken, string extUserId,
                                                      Attributes currentAttributes, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't update distribution receiver! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update distribution receiver! UserId parameter is null!");
            Assert.IsNotNull(extUserId, "Can't update distribution receiver! extUserId parameter is null!");
            Assert.IsNotNull(currentAttributes, "Can't update distribution receiver! distributionAttributes parameter is null!");

            DistributionAttributes distributionAttributes = new DistributionAttributes
            {
                attributes = currentAttributes
            };

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/entitlements/receivers/{extUserId}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("extUserId", extUserId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(distributionAttributes.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator UpdateCustomAttributes(string @namespace, string userId, string userAccessToken,
                                                  Dictionary <string, object> updates, ResultCallback <Dictionary <string, object> > callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't get custom attributes! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't get custom attributes! userId is null!");
            Assert.IsNotNull(userAccessToken, "Can't get custom attributes! UserAccessToken parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/users/{userId}/profiles/customAttributes")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(updates.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <Dictionary <string, object> >();

            callback.Try(result);
        }
Exemple #16
0
        public IEnumerator UpdateSlotMetadata(string @namespace, string userId, string accessToken, string slotId,
                                              string[] tags, string label, string customMetadata, ResultCallback <Slot> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update a slot! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a slot! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            Assert.IsNotNull(slotId, "Can't update a slot! slotId parameter is null!");

            FormDataContent customAttribute = new FormDataContent();

            customAttribute.Add("customAttribute", customMetadata);

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/slots/{slotId}/metadata")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("slotId", slotId)
                          .WithQueryParam("tags", tags)
                          .WithQueryParam("label", label)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBearerAuth(accessToken)
                          .WithContentType(customAttribute.GetMediaType())
                          .WithBody(customAttribute)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #17
0
        public IEnumerator SyncXBoxDLC(string @namespace, string userId, string userAccessToken, XBoxDLCSync XBoxDLCSync, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't sync DLC item! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't sync DLC item! UserId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't sync DLC item! userAccessToken parameter is null!");

            string content = "{}";

            if (!string.IsNullOrEmpty(XBoxDLCSync.xstsToken))
            {
                content = string.Format("{\"xstsToken\": \"{0}\"}", XBoxDLCSync.xstsToken);
            }

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/dlc/xbl/sync")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(content)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator CancelOrderApi(string orderNo, string @namespace, string userId, string userAccessToken, ResultCallback <OrderInfo> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(orderNo, "Can't cancel the order! orderNo parameter is null!");
            Assert.IsNotNull(@namespace, "Can't cancel the order! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't cancel the order! userId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't cancel the order! userAccessToken parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/orders/{orderNo}/cancel")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("orderNo", orderNo)
                          .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 <OrderInfo>();

            callback.Try(result);
        }
        public IEnumerator UnlockAchievement(string @namespace, string userId, string accessToken, string achievementCode,
                                             ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't unlock achievement! Namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't unlock achievement! AccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't unlock achievement! UserId parameter is null!");
            Assert.IsNotNull(achievementCode, "Can't unlock achievement! AchievementCode parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/users/{userId}/achievements/{achievementCode}/unlock")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("achievementCode", achievementCode)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
Exemple #20
0
        public IEnumerator ReplaceUserRecord(string @namespace, string userId, string accessToken, string key, Dictionary <string, object> recordRequest, bool isPublic,
                                             ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't replace user record! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't replace user record! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't replace user record! AccessToken parameter is null!");
            Assert.IsNotNull(key, "Can't replace user record! Key parameter is null!");
            Assert.IsNotNull(recordRequest, "Can't replace user record! recordRequest parameter is null!");

            string url = "/v1/admin/namespaces/{namespace}/users/{userId}/records/{key}";

            if (isPublic)
            {
                url += "/public";
            }

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + url)
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("key", key)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(recordRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public void CreatePut_Success()
        {
            const string url            = "https://example.com/";
            const string expectedMethod = "PUT";

            var httpRequest = HttpRequestBuilder.CreatePut(url).GetResult();

            Assert.AreEqual(httpRequest.Method, expectedMethod);
        }
Exemple #22
0
        public IEnumerator UpdateSlot(string @namespace, string userId, string accessToken, string slotId, byte[] data,
                                      string filename, ResultCallback <Slot> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't update a slot! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a slot! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            Assert.IsNotNull(data, "Can't update a slot! data parameter is null!");
            Assert.IsNotNull(filename, "Can't update a slot! filename parameter is null!");
            Assert.IsNotNull(slotId, "Can't update a slot! slotId parameter is null!");

            string checkSum;

            using (MD5 md5 = MD5.Create())
            {
                byte[] computeHash = md5.ComputeHash(data);
                checkSum = BitConverter.ToString(computeHash).Replace("-", "");
            }

            FormDataContent formDataContent = new FormDataContent();

            formDataContent.Add(filename, data);

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/slots/{slotId}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("slotId", slotId)
                          .WithQueryParam("checksum", checkSum)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBearerAuth(accessToken)
                          .WithContentType(formDataContent.GetMediaType())
                          .WithBody(formDataContent)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator UpdateGroup(string namespace_, string accessToken, string groupId, UpdateGroupRequest updateGroupRequest,
                                       ResultCallback <GroupInformation> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(namespace_, "Can't update group information! Namespace parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(accessToken), "Can't update group information! AccessToken parameter is null!");
            Assert.IsFalse(string.IsNullOrEmpty(groupId), "Can't update group information! GroupId parameter is null!");


            var builder = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/groups/{groupId}")
                          .WithPathParam("namespace", namespace_)
                          .WithPathParam("groupId", groupId)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson);

            if (updateGroupRequest.groupType == GroupType.NONE)
            {
                UpdateGroupNoTypeRequest updateRequest = new UpdateGroupNoTypeRequest
                {
                    customAttributes = updateGroupRequest.customAttributes,
                    groupDescription = updateGroupRequest.groupDescription,
                    groupIcon        = updateGroupRequest.groupIcon,
                    groupName        = updateGroupRequest.groupName,
                    groupRegion      = updateGroupRequest.groupRegion
                };
                builder.WithBody(updateRequest.ToUtf8Json());
            }
            else
            {
                builder.WithBody(updateGroupRequest.ToUtf8Json());
            }

            var           request  = builder.GetResult();
            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #24
0
        public IEnumerator UpdateEmail(UpdateEmailRequest updateEmailRequest, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(updateEmailRequest, "Update failed. updateEmailRequest is null!");

            var request = HttpRequestBuilder.CreatePut(this.baseUrl + "/v4/public/namespaces/{namespace}/users/me/email")
                          .WithPathParam("namespace", this.@namespace)
                          .WithBearerAuth(this.session.AuthorizationToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(updateEmailRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
Exemple #25
0
        public IEnumerator SyncMobilePlatformPurchaseApple(string @namespace, string userId, string userAccessToken, PlatformSyncMobileApple syncRequest, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't update distribution receiver! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update distribution receiver! UserId parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/iap/apple/receipt")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(syncRequest.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator ModifyContent(string @namespace, string userId, string accessToken, string channelId, string contentId, UGCRequest modifyRequest, ResultCallback <UGCResponse> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't modify content! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't modify content! UserId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't modify content! AccessToken parameter is null!");
            Assert.IsNotNull(channelId, "Can't modify content! channelId parameter is null!");
            Assert.IsNotNull(contentId, "Can't modify content! name parameter is null!");
            Assert.IsNotNull(modifyRequest, "Can't modify content! type parameter is null!");

            UGCRequest Req = modifyRequest;

            if (string.IsNullOrEmpty(Req.contentType))
            {
                Req.contentType = "application/octet-stream";
            }

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/public/namespaces/{namespace}/users/{userId}/channels/{channelId}/contents/s3/{contentId}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("channelId", channelId)
                          .WithPathParam("contentId", contentId)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(Req.ToUtf8Json())
                          .WithBearerAuth(accessToken)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #27
0
        public IEnumerator ResetManyUsersStatItems(string @namespace, UserStatItemReset[] data,
                                                   string accessToken, ResultCallback <StatItemOperationResult[]> callback)
        {
            Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null");
            Assert.IsNotNull(data, nameof(data) + " cannot be null");
            Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/v1/admin/namespaces/{namespace}/statitems/value/reset/bulk")
                          .WithPathParam("namespace", @namespace)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(data.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <StatItemOperationResult[]>();

            callback.Try(result);
        }
Exemple #28
0
        public IEnumerator SyncPSNDLC(string @namespace, string userId, string userAccessToken, PlayStationDLCSync playStationDLCSync,
                                      ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't sync DLC item! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't sync DLC item! UserId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't sync DLC item! userAccessToken parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/dlc/psn/sync")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(string.Format("{\"serviceLabel\": \"{0}\"}", playStationDLCSync.serviceLabel))
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> UpdateGameProfileAtrribute(string @namespace, string userId, string accessToken,
                                                              string profileId, GameProfileAttribute attribute, ResultCallback <GameProfile> callback)
        {
            Assert.IsNotNull(@namespace, "Can't update a game profile attribute! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't update a game profile attribute! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't update a game profile attribute! accessToken parameter is null!");
            Assert.IsNotNull(profileId, "Can't update a game profile attribute! profileId parameter is null!");
            Assert.IsNotNull(attribute, "Can't update a game profile attribute! attribute parameter is null!");
            Assert.IsNotNull(attribute.name, "Can't update a game profile attribute! attribute.name is null!");

            var request = HttpRequestBuilder
                          .CreatePut(this.baseUrl + "/soc-profile/public/namespaces/{namespace}/users/{userId}/profiles/{profileId}/attributes/{attributeName}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("profileId", profileId)
                          .WithPathParam("attributeName", attribute.name)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(SimpleJson.SimpleJson.SerializeObject(attribute))
                          .ToRequest();

            HttpWebResponse response = null;

            yield return(Task.Await(request, rsp => response = rsp));

            if (response == null)
            {
                callback.Try(Result <GameProfile> .CreateError(ErrorCode.NetworkError, "There is no response"));
                yield break;
            }

            var responseText = response.GetBodyText();

            response.Close();
            Result <GameProfile> result;

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                try
                {
                    GameProfile gameProfile = SimpleJson.SimpleJson.DeserializeObject <GameProfile>(responseText);
                    result = Result <GameProfile> .CreateOk(gameProfile);
                }
                catch (ArgumentException ex)
                {
                    result = Result <GameProfile> .CreateError(ErrorCode.InvalidResponse,
                                                               "Update game profile attribute failed to deserialize response body: " + ex.Message);
                }

                break;

            case HttpStatusCode.NotFound:
                result = Result <GameProfile> .CreateError(ErrorCode.CategoryNotFound,
                                                           "Update game profile attribute failed due to the resource not found");

                break;

            default:
                result = Result <GameProfile> .CreateError((ErrorCode)response.StatusCode,
                                                           "Update game profile attribute failed with status: " + response.StatusCode);

                break;
            }

            callback.Try(result);
        }