Exemple #1
0
        private async Task <T> GetResponse <T>(HttpResponseMessage response)
        {
            IEnumerable <String> tokens;

            if (response.Headers.TryGetValues(_Configuration.AuthToken, out tokens))
            {
                if (!string.IsNullOrEmpty(tokens.First()))
                {
                    //  save in local storage
                    _StorageService.Put(_Configuration.AuthToken, tokens.First());
                }
            }

            if (!response.IsSuccessStatusCode && (response.StatusCode == System.Net.HttpStatusCode.Unauthorized))
            {
                throw new DeniedException();
            }
            else if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.ReasonPhrase);
            }

            var stream = await response.Content.ReadAsStringAsync();

            return(Serializer.Deserialize <T>(stream));
        }
Exemple #2
0
        private async Task <object> GetResponse(Type returnType, HttpResponseMessage response)
        {
            //  get the security token from the response
            string token = string.Empty;

            if (response.Headers.TryGetValue(_Configuration.AuthToken, out token))
            {
                //  save in local storage
                _LocalStorage.Put(_Configuration.AuthToken, token);
            }
            //  get the response data
            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.ReasonPhrase);
            }
            var content = await response.Content.ReadAsStringAsync();

            return(Serializer.Deserialize(returnType, content));
        }