Esempio n. 1
0
        public async Task <Client> CreateClientAsync(string clientName, Dictionary <string, string> data = null)
        {
            // Convert data to JsonDict.
            if (data == null)
            {
                data = new Dictionary <string, string>();
            }
            JsonDict objData = new JsonDict();

            foreach (KeyValuePair <string, string> pair in data)
            {
                objData.Add(pair.Key, pair.Value);
            }

            string       callee   = Callee(clientName);
            JsonResponse response = await _json.PostAsync(callee, objData);

            switch (response.StatusCode)
            {
            case HttpStatusCode.Conflict:
                throw new IdentityException(response.StatusCode, "The client name is not available");

            case HttpStatusCode.NoContent:
                return(new Client(_json, callee, clientName, data));

            default:
                response.StatusCode.Throw();
                return(null);
            }
        }
Esempio n. 2
0
        protected async Task <IClientBaseResponse <T2> > PostAsync <T2>(string url, object entity)
        {
            if (_cache != null)
            {
                _cache.Remove(url);
            }

            var requestUri = Client.BuildUri(url);

            return(await Client.PostAsync <T2>(requestUri, entity));
        }
Esempio n. 3
0
        public async Task <Alias> CreateAliasAsync(string emailAddress, string password)
        {
            string       callee   = Callee(emailAddress);
            JsonResponse response = await _json.PostAsync(callee, new JsonDict
            {
                ["password"] = password
            });

            switch (response.StatusCode)
            {
            case HttpStatusCode.Conflict:
                throw new IdentityException(response.StatusCode, "The email address is not available");

            case HttpStatusCode.NoContent:
                return(new Alias(_json, callee, emailAddress));

            default:
                response.StatusCode.Throw();
                return(null);
            }
        }
Esempio n. 4
0
        public async Task LogInAsync(string password)
        {
            JsonResponse response = await _json.PostAsync(_url + "/login", new JsonDict
            {
                ["password"] = password
            });

            switch (response.StatusCode)
            {
            case HttpStatusCode.ServiceUnavailable:
                throw new IdentityException(response.StatusCode, "The account is locked - please try again later");

            case HttpStatusCode.Unauthorized:
                throw new IdentityException(response.StatusCode, "The password does not match");

            case HttpStatusCode.NoContent:
                return;

            default:
                response.StatusCode.Throw();
                return;
            }
        }