Beispiel #1
0
        public async Task <Models.Accounts.AccountModel> CreateAsync(Models.Accounts.AccountModel account, int?validityInHours = null)
        {
            using (var dclient = this.CreateClient())
            {
                var client  = dclient.Client;
                var content = this.GetContent(account);
                var url     = ApiUrls.AccountUrl;
                if (validityInHours.HasValue)
                {
                    url = ApiUrls.AccountUrl + "?validityInHours=" + validityInHours;
                }
                var response = await client.PostAsync(this.GetUri(url), content).ConfigureAwait(false);

                if (response.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    await this.AddErrorsAsync(response).ConfigureAwait(false);

                    return(null);
                }

                var model = await this.GetObjectAsync <AccountModel>(response.Content).ConfigureAwait(false);

                var tokenValue = response.Headers.GetValues("YS-AUTH");
                model.YsAuthToken = tokenValue.FirstOrDefault();
                return(model);
            }
        }
Beispiel #2
0
        public async Task <bool> UpdateAsync(Models.Accounts.AccountModel account)
        {
            using (var dclient = this.CreateClient())
            {
                var client   = dclient.Client;
                var content  = this.GetContent(account);
                var response = await client.PutAsync(this.GetUri(ApiUrls.AccountUrl), content).ConfigureAwait(false);

                return(await this.HandleResponseAsync(response).ConfigureAwait(false));
            }
        }
Beispiel #3
0
        public async Task <bool> ChangeEmailAsync(Models.Accounts.AccountModel account)
        {
            using (var dclient = this.CreateClient())
            {
                var client   = dclient.Client;
                var content  = this.GetContent(account);
                var response = await client.PutAsync(this.GetUri("api/v1/accounts/change-email"), content).ConfigureAwait(false);

                return(await this.HandleResponseAsync(response).ConfigureAwait(false));
            }
        }