Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<T> ExecuteAsync<T>(RestRequest request)
- {
- var tcs = new TaskCompletionSource<T>();
- App.Client.ExecuteAsync(request, resp =>
- {
- //has there been an error?
- if (resp.StatusCode != System.Net.HttpStatusCode.OK)
- {
- tcs.SetException(new Exception("oh no"));
- }
- else
- {
- var result = JsonConvert.DeserializeObject<T>(resp.Content);
- tcs.TrySetResult(result);
- }
- });
- return await tcs.Task;
- }
- public async Task<bool> doLogin(string email, string password)
- {
- RestRequest loginRequest = new RestRequest("/login");
- setupHeaders(loginRequest, true);
- loginRequest.Method = Method.POST;
- loginRequest.AddParameter("email",email);
- loginRequest.AddParameter("password", password);
- MyLoginObject loginResult;
- //following is used it lots of other methods that need to make web requests, uses REST Sharp
- try
- {
- //make the request
- loginResult = await ExecuteAsync<CannesConnectLoginDetails>(loginRequest);
- }
- catch (Exception ex)
- {
- return false;
- }
- //check the result
- if (loginResult == null)
- return false;
- //save login details and return
- App.Settings[USER_ID_SETTINGS_KEY] = loginResult.USERID;
- App.Settings[USER_TOKEN_KEY] = loginResult.USERTOKEN;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement