예제 #1
0
 private async Task <HttpResult <AccessTokenResponse> > GetTokenAsync(IEnumerable <KeyValuePair <string, string> > values)
 {
     try
     {
         using (HttpResponseMessage response = await HttpClient.PostAsync(TokenUri, new FormUrlEncodedContent(values)))
         {
             HttpResult <AccessTokenResponse> result = new HttpResult <AccessTokenResponse>()
             {
                 StatusCode = response.StatusCode
             };
             if (response.Content != null)
             {
                 result.Content = await response.Content.ReadAsAsync <AccessTokenResponse>();
             }
             AccessTokenResponse tokenResponse = result.Content;
             if (tokenResponse != null && tokenResponse.Error != null)
             {
                 result.Errors.Add(tokenResponse.ErrorDescription);
             }
             return(result);
         }
     }
     catch (HttpRequestException ex)
     {
         return(HttpResult <AccessTokenResponse> .Failure(ex.Message));
     }
 }
예제 #2
0
        public async Task <HttpResult <TodoList[]> > GetTodoListsAsync()
        {
            HttpResult <Wrapped <TodoList[]> > wrappedResult = await HttpClient.GetAsync <Wrapped <TodoList[]> >(TodoListsUri + "?$expand=Todos");

            HttpResult <TodoList[]> result = wrappedResult.Succeeded ? new HttpResult <TodoList[]>(wrappedResult.Content.Value) : HttpResult <TodoList[]> .Failure(wrappedResult.Errors);

            result.StatusCode = wrappedResult.StatusCode;
            return(result);
        }