public IEnumerator <ITask> Verify(string @namespace, string userAccessToken, string userId,
                                          string verificationCode, string contactType, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't post verification code! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't post verification code! UserAccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't post verification code! UserId parameter is null!");
            Assert.IsNotNull(verificationCode, "Can't post verification code! VerificationCode parameter is null!");
            Assert.IsNotNull(contactType, "Can't post verification code! ContactType parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/namespaces/{namespace}/users/{userId}/verification")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(string.Format("{{\"Code\": \"{0}\", \"ContactType\": \"{1}\"}}", verificationCode,
                                                  contactType))
                          .ToRequest();

            HttpWebResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
Exemple #2
0
        public IEnumerator BulkGetUserInfo(string[] userIds, ResultCallback <ListBulkUserInfoResponse> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(userIds, "userIds cannot be null.");

            ListBulkUserInfoRequest bulkUserInfoRequest = new ListBulkUserInfoRequest
            {
                userIds = userIds
            };

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/v3/public/namespaces/{namespace}/users/bulk/basic")
                          .WithPathParam("namespace", this.@namespace)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(bulkUserInfoRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            Result <ListBulkUserInfoResponse> result = response.TryParseJson <ListBulkUserInfoResponse>();

            callback.Try(result);
        }
        public IEnumerator CreateUserProfile(string @namespace, string userAccessToken,
                                             CreateUserProfileRequest createRequest, ResultCallback <UserProfile> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't create user profile! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't create user profile! UserAccessToken parameter is null!");
            Assert.IsNotNull(createRequest, "Can't create user profile! CreateRequest parameter is null!");
            Assert.IsNotNull(
                createRequest.language,
                "Can't create user profile! CreateRequest.language parameter is null!");

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

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator CreateUserStatItems(string @namespace, string userId, string accessToken,
                                               CreateStatItemRequest[] statItems, 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(statItems, nameof(statItems) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/v1/public/namespaces/{namespace}/users/{userId}/statitems/bulk")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(statItems.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #5
0
        public IEnumerator Verify(string verificationCode, string contactType, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(verificationCode, "Can't post verification code! VerificationCode parameter is null!");
            Assert.IsNotNull(contactType, "Can't post verification code! ContactType parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/v3/public/namespaces/{namespace}/users/me/code/verify")
                          .WithPathParam("namespace", this.@namespace)
                          .WithBearerAuth(this.session.AuthorizationToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(
                string.Format(
                    "{{" + "\"code\": \"{0}\", " + "\"contactType\": \"{1}\"" + "}}",
                    verificationCode,
                    contactType))
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> CreateOrder(string @namespace, string userId, string userAccessToken,
                                               OrderRequest orderRequest,
                                               ResultCallback <OrderInfo> callback)
        {
            Assert.IsNotNull(@namespace, "Can't create order! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't create order! UserId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't create order! UserAccessToken parameter is null!");
            Assert.IsNotNull(orderRequest, "Can't create order! OrderRequest parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/platform/public/namespaces/{namespace}/users/{userId}/orders")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(SimpleJson.SimpleJson.SerializeObject(orderRequest))
                          .Accepts(MediaType.ApplicationJson)
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #7
0
        public IEnumerator DeregisterLocalServer(string name, string accessToken, ResultCallback callback)
        {
            Assert.IsNotNull(name, "Deregister failed. name is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");

            if (this.serverType != ServerType.LOCALSERVER)
            {
                callback.TryError(ErrorCode.Conflict, "Server not registered as Local Server.");

                yield break;
            }

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/namespaces/{namespace}/servers/local/deregister")
                          .WithPathParam("namespace", this.namespace_)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(string.Format("{{\"name\": \"{0}\"}}", name))
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            serverType = ServerType.NONE;

            callback.Try(result);
        }
        public IEnumerator LoginWithOtherPlatform(PlatformType platformType, string platformToken,
                                                  ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(platformToken, "PlatformToken parameter is null.");

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/platforms/{platformId}/token")
                          .WithPathParam("platformId", platformType.ToString().ToLower())
                          .WithBasicAuth(this.clientId, this.clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("platform_token", platformToken)
                          .WithFormParam("namespace", this.@namespace)
                          .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        public IEnumerator LoginWithUsername(string username, string password, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(username, "Username parameter is null.");
            Assert.IsNotNull(password, "Password parameter is null.");

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/token")
                          .WithBasicAuth(this.clientId, this.clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("grant_type", "password")
                          .WithFormParam("username", username)
                          .WithFormParam("password", password)
                          .WithFormParam("namespace", this.@namespace)
                          .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        public IEnumerator <ITask> ResetPassword(string @namespace, string clientId, string clientSecret,
                                                 string resetCode, string userName, string newPassword, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't reset password! Namespace parameter is null!");
            Assert.IsNotNull(clientId, "Can't reset password! clientId parameter is null!");
            Assert.IsNotNull(clientSecret, "Can't reset password! clientSecret parameter is null!");

            var jsonResetRequest = string.Format(
                "{{" +
                "\"Code\": \"{0}\"," +
                "\"LoginID\": \"{1}\"," +
                "\"NewPassword\": \"{2}\"" +
                "}}",
                resetCode,
                userName,
                newPassword);

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/namespaces/{namespace}/users/resetPassword")
                          .WithPathParam("namespace", @namespace)
                          .WithBasicAuth(clientId, clientSecret)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(jsonResetRequest)
                          .ToRequest();

            HttpWebResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> UnlinkOtherPlatform(string @namespace, string userAccessToken, string userId,
                                                       string platformId, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't unlink platfrom account! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't unlink platfrom account! UserAccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't unlink platfrom account! UserId parameter is null!");
            Assert.IsNotNull(platformId, "Can't unlink platfrom account! Email parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/namespaces/{namespace}/users/{userId}/platforms/{platformId}/unlink")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithPathParam("platformId", platformId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.TextPlain)
                          .ToRequest();

            HttpWebResponse response = null;

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> Register(string @namespace, string clientAccessToken, UserInfo info,
                                            ResultCallback <UserData> callback)
        {
            Assert.IsNotNull(@namespace, "Can't create user! Namespace parameter is null!");
            Assert.IsNotNull(clientAccessToken, "Can't create user! ClientAccessToken parameter is null!");
            Assert.IsNotNull(info, "Can't create user! Info parameter is null!");

            var jsonInfo = string.Format(
                "{{" +
                "\"AuthType\": \"{0}\"," +
                "\"DisplayName\": \"{1}\"," +
                "\"LoginId\": \"{2}\"," +
                "\"Password\": \"{3}\"" +
                "}}",
                info.AuthType,
                info.DisplayName,
                info.UserName,
                info.Password);

            var request =
                HttpRequestBuilder.CreatePost(this.baseUrl + "/iam/namespaces/{namespace}/users")
                .WithPathParam("namespace", @namespace)
                .WithBearerAuth(clientAccessToken)
                .WithContentType(MediaType.ApplicationJson)
                .WithBody(jsonInfo)
                .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator <ITask> SendPasswordResetCode(string @namespace, string clientId,
                                                         string clientSecret, string userName, ResultCallback callback)
        {
            Assert.IsNotNull(@namespace, "Can't request reset password code! Namespace parameter is null!");
            Assert.IsNotNull(clientId, "Can't reset password! clientId parameter is null!");
            Assert.IsNotNull(clientSecret, "Can't reset password! clientSecret parameter is null!");
            Assert.IsNotNull(userName, "Can't request reset password code! LoginId parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/namespaces/{namespace}/users/forgotPassword")
                          .WithPathParam("namespace", @namespace)
                          .WithBasicAuth(clientId, clientSecret)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(string.Format("{{\"LoginID\": \"{0}\"}}", userName))
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            var result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> UpgradeAndVerify(string @namespace,
                                                    string userAccessToken, string userId, string userName, string password, string verificationCode,
                                                    ResultCallback <UserData> callback)
        {
            Assert.IsNotNull(@namespace, "Can't upgrade headless account! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't upgrade headless account! ClientAccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't upgrade headless account! UserId parameter is null!");
            Assert.IsNotNull(userName, "Can't upgrade headless account! UserName parameter is null!");
            Assert.IsNotNull(password, "Can't upgrade headless account! Password parameter is null!");
            Assert.IsNotNull(verificationCode, "Can't upgrade headless account! Password parameter is null!");

            string requestBody = string.Format("{{\"Code\":\"{0}\", \"LoginID\": \"{1}\", \"Password\": \"{2}\"}}",
                                               verificationCode, userName, password);

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

            HttpWebResponse response = null;

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

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

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

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

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

            var request = HttpRequestBuilder
                          .CreatePost(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 IEnumerator LoginWithDeviceId(ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            DeviceProvider deviceProvider = DeviceProvider.GetFromSystemInfo();

            IHttpRequest request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/platforms/{platformId}/token")
                                   .WithPathParam("platformId", deviceProvider.DeviceType)
                                   .WithBasicAuth(this.clientId, this.clientSecret)
                                   .WithContentType(MediaType.ApplicationForm)
                                   .Accepts(MediaType.ApplicationJson)
                                   .WithFormParam("device_id", deviceProvider.DeviceId)
                                   .WithFormParam("namespace", this.@namespace)
                                   .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        public IEnumerator SendHeartBeat(string name, string accessToken, ResultCallback <MatchRequest> callback)
        {
            Assert.IsNotNull(name, "Deregister failed. name is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/namespaces/{namespace}/servers/heartbeat")
                          .WithPathParam("namespace", this.namespace_)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(string.Format("{{\"name\": \"{0}\"}}", name))
                          .GetResult();

            IHttpResponse response = null;

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

            if (response.BodyBytes == null || response.BodyBytes.Length == 0)
            {
                callback.Try(null);
            }
            else
            {
                var result = response.TryParseJson <MatchRequest>();
                callback.Try(result);
            }
        }
Exemple #18
0
        public IEnumerator FulfillUserItem(string @namespace, string userId, string accessToken,
                                           FulfillmentRequest fulfillmentRequest, ResultCallback <FulfillmentResult> 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(fulfillmentRequest, $"{nameof(fulfillmentRequest)} cannot be null");

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

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator CreateOrder(string @namespace, string userId, string userAccessToken,
                                       OrderRequest orderRequest, ResultCallback <OrderInfo> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't create order! Namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't create order! UserId parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't create order! UserAccessToken parameter is null!");
            Assert.IsNotNull(orderRequest, "Can't create order! OrderRequest parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/orders")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(orderRequest.ToUtf8Json())
                          .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 RedeemCode(string @namespace, string userId, string accessToken, FulFillCodeRequest fulFillCodeRequest,
                                      ResultCallback <FulfillmentResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            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(fulFillCodeRequest, nameof(fulFillCodeRequest) + " cannot be null");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/fulfillment/code")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(fulFillCodeRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator BulkClaimRewards(string @namespace, string accessToken, string userId, ResultCallback <SeasonClaimRewardResponse> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't Claim Rewards! Namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't Claim Rewards! AccessToken parameter is null!");
            Assert.IsNotNull(userId, "Can't Claim Rewards! AccessToken parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/seasons/current/rewards/bulk")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("userId", userId)
                          .WithBearerAuth(accessToken)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator <ITask> GetUserTokenWithAuthorizationCode(string clientId, string clientSecret,
                                                                     string code, string redirectUri, ResultCallback <TokenData> callback)
        {
            Assert.IsNotNull(clientId, "Can't generate token from authorization code! clientId parameter is null!");
            Assert.IsNotNull(clientSecret, "Can't generate token from authorization code! ClientSecret parameter is null!");
            Assert.IsNotNull(code, "Can't generate token from authorization code! Code parameter is null!");
            Assert.IsNotNull(redirectUri, "Can't generate token from authorization code! RedirectUri parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/oauth/token")
                          .WithBasicAuth(clientId, clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("grant_type", "authorization_code")
                          .WithFormParam("code", code)
                          .WithFormParam("redirect_uri", redirectUri)
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #23
0
        public IEnumerator AddUserToSession(string @namespace, string accessToken, string channelName, string matchId, string userId, string partyId, ResultCallback callback)
        {
            Assert.IsFalse(string.IsNullOrEmpty(accessToken), "RemoveUserFromSession failed. accessToken parameter is null or empty!");
            Assert.IsFalse(string.IsNullOrEmpty(matchId), "RemoveUserFromSession failed. accessToken parameter is null or empty!");
            Assert.IsFalse(string.IsNullOrEmpty(channelName), "RemoveUserFromSession failed, channelName is null or empty!");
            Assert.IsFalse(string.IsNullOrEmpty(userId), "RemoveUserFromSession failed, userId is null or empty!");

            AddUserIntoSessionRequest body = new AddUserIntoSessionRequest()
            {
                user_id  = userId,
                party_id = partyId
            };

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/v1/admin/namespaces/{namespace}/channels/{channelName}/sessions/{matchId}")
                          .WithPathParam("namespace", @namespace)
                          .WithPathParam("channelName", channelName)
                          .WithPathParam("matchId", matchId)
                          .WithBody(body.ToUtf8Json())
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse respose = null;

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

            var result = respose.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> GetUserToken(string @namespace, string clientId, string clientSecret, string username,
                                                string password,
                                                ResultCallback <TokenData> callback)
        {
            Assert.IsNotNull(clientId, "Can't generate token! ClientId parameter is null!");
            Assert.IsNotNull(clientSecret, "Can't generate token! ClientSecret parameter is null!");
            Assert.IsNotNull(username, "Can't generate token! UserName parameter is null!");
            Assert.IsNotNull(password, "Can't generate token! Password parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/oauth/token")
                          .WithBasicAuth(clientId, clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("grant_type", "password")
                          .WithFormParam("username", username)
                          .WithFormParam("password", password)
                          .WithFormParam("namespace", @namespace)
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
Exemple #25
0
        public IEnumerator LinkOtherPlatform(PlatformType platformType, string ticket, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(ticket, "Can't link platform account! Password parameter is null!");

            if (platformType == PlatformType.Stadia)
            {
                ticket = ticket.TrimEnd('=');
            }

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/v3/public/namespaces/{namespace}/users/me/platforms/{platformId}")
                          .WithPathParam("namespace", this.@namespace)
                          .WithPathParam("platformId", platformType.ToString().ToLower())
                          .WithFormParam("ticket", ticket)
                          .WithBearerAuth(this.session.AuthorizationToken)
                          .Accepts(MediaType.ApplicationJson)
                          .WithContentType(MediaType.ApplicationForm)
                          .GetResult();

            IHttpResponse response = null;

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

            Result result = response.TryParse();

            callback.Try(result);
        }
        public IEnumerator <ITask> GetUserTokenWithDeviceId(string @namespace, string clientId, string clientSecret,
                                                            string deviceType, string deviceId, ResultCallback <TokenData> callback)
        {
            Assert.IsNotNull(clientId, "Can't generate device token! ClientId parameter is null!");
            Assert.IsNotNull(clientSecret, "Can't generate device token! ClientSecret parameter is null!");
            Assert.IsNotNull(deviceType, "Can't generate device token! DeviceType parameter is null!");
            Assert.IsNotNull(deviceId, "Can't generate device token! DeviceId parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/iam/oauth/platforms/{platformId}/token")
                          .WithPathParam("platformId", deviceType)
                          .WithBasicAuth(clientId, clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("device_id", deviceId)
                          .WithFormParam("namespace", @namespace)
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator GrantUserEntitlement(string @namespace, string userId, string accessToken,
                                                GrantUserEntitlementRequest[] grantUserEntitlementsRequest, ResultCallback <StackableEntitlementInfo[]> 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(grantUserEntitlementsRequest, nameof(grantUserEntitlementsRequest) + " cannot be null");

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

            IHttpResponse response = null;

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

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

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

            DistributionAttributes distributionAttributes = new DistributionAttributes
            {
                attributes = currentAttributes
            };

            var request = HttpRequestBuilder
                          .CreatePost(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);
        }
Exemple #29
0
        public IEnumerator <ITask> CreateUserProfile(string @namespace, string userAccessToken,
                                                     CreateUserProfileRequest createRequest, ResultCallback <UserProfile> callback)
        {
            Assert.IsNotNull(@namespace, "Can't create user profile! Namespace parameter is null!");
            Assert.IsNotNull(userAccessToken, "Can't create user profile! UserAccessToken parameter is null!");
            Assert.IsNotNull(createRequest, "Can't create user profile! CreateRequest parameter is null!");
            Assert.IsNotNull(createRequest.language, "Can't create user profile! CreateRequest.language parameter is null!");

            var request = HttpRequestBuilder
                          .CreatePost(this.baseUrl + "/basic/public/namespaces/{namespace}/users/me/profiles")
                          .WithPathParam("namespace", @namespace)
                          .WithBearerAuth(userAccessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(SimpleJson.SimpleJson.SerializeObject(createRequest))
                          .ToRequest();

            HttpWebResponse response = null;

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

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

            callback.Try(result);
        }
        public IEnumerator CreateGameProfile(string @namespace, string userId, string accessToken,
                                             GameProfileRequest gameProfile, ResultCallback <GameProfile> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't create a game profile! namespace parameter is null!");
            Assert.IsNotNull(userId, "Can't create a game profile! userId parameter is null!");
            Assert.IsNotNull(accessToken, "Can't create a game profile! accessToken parameter is null!");
            Assert.IsNotNull(gameProfile, "Can't create a game profile! gameProfile parameter is null!");

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

            IHttpResponse response = null;

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

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

            callback.Try(result);
        }