public async Task <PostResponse> SyncUpAsync(object synchronizableModel, ApiBase apiBaseInstance) { try { if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { this.Logger.Debug("No connectivity"); return(null); } string syncableJson = JsonConvert.SerializeObject(synchronizableModel); if (syncableJson == string.Empty) { this.Logger.Debug("Unsyncable model"); return(default(PostResponse)); } ServerResponse <PostResponse> response = await apiBaseInstance.PostJsonAsync <PostResponse>(syncableJson); return(response.GetObject()); } catch (Exception exception) { this.Logger.Error(exception); throw; } }
public async Task <T> GetCommissionDetails <T>(string param, string key) { if (string.IsNullOrEmpty(key)) { throw new Exception("memory caching key cannotbe null"); } // check the object in cache var response = await MemoryCache.Instance.Get <T>(key); if (response != null) { return(response); } if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { this._logger.Debug("No connectivity"); return(default(T)); } ServerResponse <T> serverResponse = await this._commissionApi.MakeGetCallAsync <T>(param); response = serverResponse.GetObject(); // save object in cache if (response != null) { MemoryCache.Instance.Store(key, response); } return(response); }
public async Task <ProductComponentsResponse> GetProductDetails(string productParams, ErrorFilterFlags filterFlags = ErrorFilterFlags.EnableErrorHandling) { Log.Verbose("Get components of a product."); ServerResponse <List <ProductComponent> > response = null; try { response = await MakeGetCallAsync <List <ProductComponent> >(productParams, filterFlags : filterFlags); } catch (Exception e) { Log.Error(e); } Log.Verbose("API call done."); if (response == null) { Log.Verbose("API NOT successfull"); return(new ProductComponentsResponse() { Successful = false, ResponseText = "not_connected", }); } Log.Verbose(response.RawResponse); // try getting the object from JSON List <ProductComponent> components = null; ProductComponentsResponse result = null; try { components = response.GetObject(); result = new ProductComponentsResponse { ProductComponents = components, }; } catch (Exception e) { Log.Error(e); } // got a proper result, return it if (result != null) { result.Successful = true; return(result); } Log.Verbose("Could not parse response."); return(new ProductComponentsResponse() { Successful = false, }); }
public async Task <List <RankingSummarized> > GetSummarizedRankAsync(Period period, SalesAreaHierarchy region) { try { DateTime lastUpdate = await this.GetLastUpdateDateTimeAsync(new CancellationTokenSource().Token); int validityMinutes = Settings.Settings.Instance.RankingSummarizedValidityMinutes; if (lastUpdate > default(DateTime)) { if (lastUpdate.AddMinutes(validityMinutes) > DateTime.Now) { return(new List <RankingSummarized>()); } } string userId = Resolver.Instance.Get <ISalesAppSession>().UserId.ToString(); string urlParams = string.Format("{0}?periodType={1}®ion={2}", userId, (int)period, (int)region); ServerResponse <List <RankingSummarized> > serverResponse = await this.SummarizedRanksApi.MakeGetCallAsync <List <RankingSummarized> >(urlParams, filterFlags : ErrorFilterFlags.AllowEmptyResponses | ErrorFilterFlags.IgnoreNoInternetError); if (serverResponse == null) { return(new List <RankingSummarized>()); } if (serverResponse.IsSuccessStatus) { var result = serverResponse.GetObject(); await this.LocalDsrRanking.SetAsync(result); return(result); } return(new List <RankingSummarized>()); } catch (JsonReaderException jsonReaderException) { this.Logger.Error(jsonReaderException); } catch (NotConnectedToInternetException nctiex) { this.Logger.Error(nctiex); } catch (TaskCanceledException taskCanceled) { this.Logger.Error(taskCanceled); } catch (Exception exception) { this.Logger.Error(exception); } return(new List <RankingSummarized>()); }
public async Task <T> Search(string searchParams, ErrorFilterFlags filterFlags, ApiTimeoutEnum timeOut = ApiTimeoutEnum.Normal) { ServerResponse <T> response = await this.MakeGetCallAsync <T>(searchParams, null, filterFlags, timeOut); if (response == null || !response.IsSuccessStatus) { return(null); } return(response.GetObject()); }
public virtual async Task <ManageStockPostApiResponse> AllocateUnitsToDsr(SelectedProduct selectedProduct) { ServerResponse <ManageStockPostApiResponse> result = await this._stockAllocationApi.PostObjectAsync <ManageStockPostApiResponse, SelectedProduct>(selectedProduct); if (result == null) { return(null); } return(result.GetObject()); }
public virtual async Task <ManageStockPostApiResponse> ReceiveStockFromDsr(SelectedProduct selectedProducts) { ServerResponse <ManageStockPostApiResponse> result = await this._recieveAllocatedStockApi.PostObjectAsync <ManageStockPostApiResponse, SelectedProduct>(selectedProducts); if (result == null) { return(null); } return(result.GetObject()); }
public async Task <List <Row> > GetListAsync(Period period, SalesAreaHierarchy region) { string jsonString = string.Empty; try { string userId = Resolver.Instance.Get <ISalesAppSession>().UserId.ToString(); string urlParams = string.Format("{0}?periodType={1}®ion={2}", userId, (int)period, (int)region); ServerResponse <DsrRankingList> serverResponse = await this.RankingListApi.MakeGetCallAsync <DsrRankingList>(urlParams, filterFlags : ErrorFilterFlags.AllowEmptyResponses | ErrorFilterFlags.IgnoreNoInternetError); if (serverResponse == null) { return(new List <Row>()); } if (serverResponse.IsSuccessStatus) { jsonString = serverResponse.RawResponse; DsrRankingList rankingList = serverResponse.GetObject(); foreach (var rankInfo in rankingList.Dsrs) { rankInfo.TimeStamp = rankingList.TimeStamp; rankInfo.Period = period; rankInfo.Region = region; } await this.RankingService.SetAsync(rankingList.Dsrs, period, region); return(await new RankingsRowService().GetRankingRows(period, region)); } return(new List <Row>()); } catch (JsonReaderException jsonReaderException) { this.HandleException(jsonReaderException, "Attempt to parse invalid JSON may have been made." + " JSON: " + jsonString); } catch (NotConnectedToInternetException notConnectedToInternetException) { this.HandleException(notConnectedToInternetException, "Unable to connect internet. Could connection have dropped?"); } catch (TaskCanceledException taskCanceled) { this.HandleException(taskCanceled, "Timeout may have occured or task may have been explicitly canceled by user."); } catch (Exception exception) { this.HandleException(exception, string.Empty); } return(new List <Row>()); }
public async Task <CustomerStatus> GetAsync(string phone) { if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { return(null); } ServerResponse <CustomerStatus> serverResponse = await this.MakeGetCallAsync <CustomerStatus>("/Get?phoneNumber=" + phone); if (serverResponse.IsSuccessStatus) { return(serverResponse.GetObject()); } return(null); }
public async Task <CommissionSummaryResponse> GetCommissionSummary(string param, string key) { if (string.IsNullOrEmpty(key)) { throw new Exception("memory caching key cannot be null"); } // check the object in cache var response = await MemoryCache.Instance.Get <CommissionSummaryResponse>(key); if (response != null) { return(response); } if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { this._logger.Debug("No connectivity"); throw new NotConnectedToInternetException(); } ServerResponse <CommissionSummaryResponse> serverResponse = await this._commissionApi.MakeGetCallAsync <CommissionSummaryResponse>(param); if (serverResponse.RequestException != null) { // check for 401, and throw unauthorized exception UnauthorizedHttpException uex = serverResponse.RequestException as UnauthorizedHttpException; if (uex != null) { throw uex; } } response = serverResponse.GetObject(); // save in cache if (response != null) { MemoryCache.Instance.Store(key, response); } return(response); }
private async Task RefreshGroups() { this.ProgressDialogMessage = this._deviceResource.UpdatingListPleaseWait; string urlParams = string.Format("?serverTimestamp={0}", this._serverTimeStamp.ToString("s")); this.IsBusy = true; try { ServerResponse <GroupInfo> response = await this._chamaApi.MakeGetCallAsync <GroupInfo>(urlParams); if (response.IsSuccessStatus) { await this.ApplyUpdate(response.GetObject()); } } finally { this.IsBusy = false; } }
public virtual async Task <List <BL.Product> > GetProducts(string urlParams = null) { try { this.Logger.Debug("Fetching products data from server"); ServerResponse <List <BL.Product> > serverResponse = await this.ProductApi.GetAsync(urlParams, ErrorFilterFlags.AllowEmptyResponses | ErrorFilterFlags.IgnoreNoInternetError); if (serverResponse == null) { this.Logger.Verbose("No results."); } else if (serverResponse.IsSuccessStatus) { List <BL.Product> products = serverResponse.GetObject(); await this.LocalProductService.SetAsync(products); return(products); } } catch (JsonReaderException jsonReaderException) { this.Logger.Error(jsonReaderException); } catch (NotConnectedToInternetException nctiex) { this.Logger.Error(nctiex); } catch (TaskCanceledException taskCanceled) { this.Logger.Error(taskCanceled); } catch (Exception exception) { this.Logger.Error(exception); throw; } return(new List <BL.Product>()); }
/// <summary> /// Attempts to perform an online login /// </summary> /// <param name="phone">The phone number of the individual logging in</param> /// <param name="pin">The associated pin</param> /// <param name="isFirstTime">Flag for whether it is the first time the individual is log</param> /// <param name="filterFlags">Flags to help ignore some API errors</param> /// <returns>Null if login failed or on success a DsrProfile object containing details of user who's logged in</returns> public async Task <LoginResponse> Login(string phone, string pin, bool isFirstTime, ErrorFilterFlags filterFlags) { try { if (pin == null) { return(new LoginResponse { Code = LoginResponseCode.WrongParameters }); } if (phone == null) { return(new LoginResponse { Code = LoginResponseCode.WrongParameters }); } IHashing hashing = Resolver.Instance.Get <IHashing>(); string hash = hashing.HashPassword(phone, pin); string credentials = string.Format("{0}:{1}", phone, hash); byte[] bytes = hashing.GetBytes(credentials); string base64 = Convert.ToBase64String(bytes); this.RemoveHeader("Authorization"); this.AddHeader("Authorization", " Basic " + base64); ServerResponse <LoginResponse> response = await PostObjectAsync <LoginResponse, LoginDto>( new LoginDto { Hash = hash, IsFirstLogin = isFirstTime, DeviceInformation = Resolver.Instance.Get <IInformation>() }, null, filterFlags); this.Logger.Debug("Call to login api completed"); if (response == null) { this.Logger.Debug("Response is null"); return(new LoginResponse() { Code = LoginResponseCode.HttpError }); } if (response.StatusCode == HttpStatusCode.Unauthorized) { this.Logger.Debug("HttpStatusCode.Unauthorized"); return(new LoginResponse() { Code = LoginResponseCode.Unauthorized }); } if (!response.IsSuccessStatus) { this.Logger.Debug("IsSuccessStatus = false"); return(new LoginResponse() { Code = LoginResponseCode.HttpError }); } this.Logger.Debug("Persisting user hash"); Resolver.Instance.Get <ISalesAppSession>().UserHash = base64; this.Logger.Debug("deserializing response text to object"); LoginResponse loginResponse = response.GetObject(); if (loginResponse.Permissions == null || !loginResponse.Permissions.Any()) { this.Logger.Debug("Looks like we don't yet support permissions. Lets fake some."); var vals = Enum.GetNames(typeof(Permissions)); loginResponse.Permissions = new List <Permission>(); foreach (string value in vals) { this.Logger.Debug(string.Format("Faking permission: {0}", value)); loginResponse.Permissions.Add( new Permission { Name = value, PermissionId = (uint)Enum.Parse(typeof(Permissions), value) }); } } this.Logger.Debug(string.Format("Updating permissions total permissions count {0}", loginResponse.Permissions.Count)); await PermissionsController.Instance.UpdatePermissionsAsync(loginResponse.Permissions); this.Logger.Debug("Login went smoothly... Exiting method and returning result"); loginResponse.Code = LoginResponseCode.Success; return(loginResponse); } catch (Exception ex) { this.Logger.Error(ex); return(new LoginResponse() { Code = LoginResponseCode.Unknown }); } }
/// <summary> /// This is a generic down sync method for syncing both prospects and customers /// </summary> /// <typeparam name="TResponse">Specifies the type of sync to perform</typeparam> /// <typeparam name = "TModel" > Specifies the type of model for which to do the sync</typeparam> /// <returns>A server response representing new and updated methods</returns> public async Task SyncDownAsync <TResponse, TModel>() where TModel : BusinessEntityBase { Type t = typeof(TModel); var api = this.GetDownSyncApi(t); if (api == null) { var error = string.Format("We dont know how to down sync type {0} yet!", typeof(TModel)); throw new InvalidOperationException(error); } try { if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { this.Logger.Debug("No connectivity"); return; } string userId = Resolver.Instance.Get <ISalesAppSession>().UserId.ToString(); string serverTimestamp = string.Empty; DownSyncTracker tracker = await this.DownSyncService.Get(t.FullName); if (tracker != default(DownSyncTracker)) { serverTimestamp = tracker.ServerTimestamp; } DateTime result; DateTime.TryParse(serverTimestamp, out result); if (result != default(DateTime)) { serverTimestamp = result.ToString("s"); } string urlParams = string.Format("?servertimestamp={0}&userId={1}", serverTimestamp, userId); if (t == typeof(DsrTicket)) { urlParams += "&requestType=Dsr"; } if (t == typeof(CustomerTicket)) { urlParams += "&requestType=Customer"; } if (this.SyncStarted != null) { this.SyncStarted.Invoke(this, new SyncStartedEventArgs()); } ServerResponse <TResponse> serverResponse = await api.MakeGetCallAsync <TResponse>(urlParams); var downSyncServerResponse = serverResponse.GetObject() as DownSyncServerResponse <TModel>; Logger.Debug("Down sync response = " + serverResponse.RawResponse); await this.HandleDownSyncResponse(downSyncServerResponse); if (downSyncServerResponse != null) { await this.DownSyncService.Save(new DownSyncTracker { ServerTimestamp = downSyncServerResponse.ServerTimeStamp == null ? TimeService.Get().Now.ToString() : downSyncServerResponse.ServerTimeStamp, Entity = t.FullName, IsInitial = true }); } if (this.SyncCompleted != null) { this.SyncCompleted.Invoke(this, new SyncCompleteEventArgs()); } } catch (Exception ex) { if (this.SyncErrored != null) { this.SyncErrored.Invoke(this, new SyncErrorEventArgs { Error = ex }); } this.Logger.Error(ex); throw; } }
public async Task <CustomerDetailsResponse> GetCustomerDetails(string customerParams, ErrorFilterFlags filterFlags = ErrorFilterFlags.EnableErrorHandling) { Log.Verbose("Get details of a customer."); ServerResponse <CustomerDetailsResponse> response = null; try { response = await MakeGetCallAsync <CustomerDetailsResponse>(customerParams, filterFlags : filterFlags); } catch (Exception e) { Log.Verbose("Error during API call."); Log.Error(e); return(new CustomerDetailsResponse() { Successful = false, Status = ServiceReturnStatus.NoInternet, }); } Log.Verbose("API call done."); if (response == null || response.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(response.RawResponse)) { Log.Verbose("API call not successfull"); return(new CustomerDetailsResponse() { Successful = false, Status = ServiceReturnStatus.NoInternet, }); } Log.Verbose(response.RawResponse); // try getting the object from JSON CustomerDetailsResponse result = null; try { result = response.GetObject(); } catch (Exception e) { Log.Verbose("Error try getting the object from JSON."); Log.Error(e); return(new CustomerDetailsResponse() { Successful = false, Status = ServiceReturnStatus.ParseError }); } // got a proper result, return it if (result != null) { result.Successful = true; if (result.CustomerFound) { if (result.Surname != null) { result.Surname = result.Surname.Trim(); } if (result.OtherNames != null) { result.OtherNames = result.OtherNames.Trim(); } } return(result); } return(new CustomerDetailsResponse() { Successful = false, CustomerFound = false }); }
public async Task <TicketSubmissionResponse> SubmitTicket(Ticket ticket) { Logger.Verbose("Submit Ticket."); string jsonString = JsonConvert.SerializeObject(ticket); Logger.Verbose(jsonString); ServerResponse <TicketSubmissionResponse> response = await PostJsonAsync <TicketSubmissionResponse>(jsonString); Logger.Verbose("API call done."); if (response == null) { Logger.Verbose("API NOT successfull"); return(new TicketSubmissionResponse() { Success = false, Text = null }); } Logger.Verbose("API result: " + response.IsSuccessStatus); Logger.Verbose(response.RawResponse); // try getting the object from JSON TicketSubmissionResponse result = null; try { result = response.GetObject(); } catch (Exception e) { Logger.Error(e); } // got a proper result, return it if (result != null) { result.Success = true; return(result); } Logger.Verbose("Could not parse response."); // if exception was thrown, return the exception as text if (response.RequestException != null) { return(new TicketSubmissionResponse() { Success = false, Text = response.RequestException.ToString() }); } return(new TicketSubmissionResponse() { Success = false, Text = "Unknown Error." }); }
public async override Task ApiCallsOnline() { List <RankingSummarized> responseList = new List <RankingSummarized> { new RankingSummarized { Area = "Service Centre" , DsrRank = 3 , TotalDsrs = 10 , Level = 0 } , new RankingSummarized { Area = "Area" , DsrRank = 10 , TotalDsrs = 90 , Level = 1 } , new RankingSummarized { Area = "All" , DsrRank = 80 , TotalDsrs = 600 , Level = 2 } }; responseList = responseList.OrderBy(item => item.Level).ToList(); DefineResponse ( new ServerResponse <List <RankingSummarized> > { IsSuccessStatus = true , RawResponse = GetRawResponseString ( responseList ) , StatusCode = HttpStatusCode.OK } ); ServerResponse <List <RankingSummarized> > serverResponse = await StandardFetch(default(CancellationToken)); Assert.AreEqual((double)HttpStatusCode.OK, (double)serverResponse.StatusCode, "Invalid server response code"); List <RankingSummarized> serverList = serverResponse.GetObject().OrderBy(item => item.Level).ToList(); Assert.AreEqual((double)responseList.Count, (double)serverList.Count, "Wrong number of results returned"); for (int i = 0; i < serverList.Count; i++) { Assert.IsTrue(responseList[i].Area == serverList[i].Area, "Area name returned by server does not match with area provided"); } }
public async Task <CustomerRegistrationResponse> RegisterCustomer(Customer customer, ApiTimeoutEnum timeOut) { // register custom error handler for 500 error, we want to show toast and continue var errorDescriber500 = new ErrorDescriber( typeof(HttpResponse500Exception), typeof(BackgroundNotifier), ErrorFilterFlags.Ignore500Family); ApiErrorHandler.RegisterExpectedError(this, errorDescriber500); Log.Verbose("Register Customer."); ServerResponse <CustomerRegistrationResponse> response = await this.PostObjectAsync <CustomerRegistrationResponse, Customer>(customer, timeOut : timeOut); Log.Verbose("API call done."); if (response == null) { Log.Verbose("API NOT successfull"); return(new CustomerRegistrationResponse() { Customer = null, RequestId = customer.RequestId, Successful = false, ResponseText = null }); } Log.Verbose("API result: " + response.IsSuccessStatus); Log.Verbose(response.RawResponse); // try getting the object from JSON CustomerRegistrationResponse result = null; try { result = response.GetObject(); } catch (Exception e) { Log.Error(e); } // got a proper result, return it if (result != null) { result.Successful = true; return(result); } Log.Verbose("Could not parse response."); // 500 error occured, special case if (response.RequestException.GetType().IsAssignableFrom(typeof(HttpResponse500Exception))) { return(new CustomerRegistrationResponse { Customer = null, RequestId = customer.RequestId, Successful = false, ResponseText = "HttpResponse500Exception" }); } // if exception was thrown, return the exception as text if (response.RequestException != null) { return(new CustomerRegistrationResponse { Customer = null, RequestId = customer.RequestId, Successful = false, ResponseText = response.RequestException.ToString() }); } // unknown error returned return(new CustomerRegistrationResponse { Customer = null, RequestId = customer.RequestId, Successful = false, ResponseText = "Unknown Error." }); }
/// <summary> /// Request new settings from the server /// </summary> /// <param name="requestParams">The request parameters</param> /// <returns>An empty task</returns> public async Task FetchOtaSettingsAsync(string requestParams) { string jsonString = string.Empty; try { this.Logger.Debug("Reqesting OTA Settings in a few."); ServerResponse <OtaServerResponse> serverResponse = await this.otaSettingsApi.MakeGetCallAsync <OtaServerResponse>(requestParams, null, ErrorFilterFlags.AllowEmptyResponses, ApiTimeoutEnum.VeryLong); this.Logger.Debug("OTA Settings Request Done."); if (serverResponse == null) { this.Logger.Debug("Empty response!"); } else if (serverResponse.IsSuccessStatus) { jsonString = serverResponse.RawResponse; this.Logger.Debug("Raw Json : " + jsonString); OtaServerResponse otaServerResponse = serverResponse.GetObject(); string serverTimeStamp = otaServerResponse.ServerTimestamp; // Save the header settings OtaSetting serverTimeStampSetting = new OtaSetting { GroupName = LocalOtaService.Communication, Name = "ServerTimeStamp", Value = serverTimeStamp }; List <SettingsGroup> settingGroups = otaServerResponse.SettingsGroups; await this.localOtaService.SetSettingsValue(serverTimeStampSetting); foreach (var settingsGroup in settingGroups) { List <OtaSetting> settings = settingsGroup.Settings; foreach (var s in settings) { s.GroupName = settingsGroup.Name; await this.localOtaService.SetSettingsValue(s); } } } } catch (JsonReaderException jsonReaderException) { this.Logger.Error("Invalid JSON could not be parsed!"); this.Logger.Error("JSON: " + jsonString); this.Logger.Error(jsonReaderException); } catch (NotConnectedToInternetException notConnectedToInternetException) { this.Logger.Error("Unable to connect internet. Could connection have dropped?"); this.Logger.Error(notConnectedToInternetException); } catch (TaskCanceledException taskCanceled) { this.Logger.Error("Timeout may have occured or task may have been explicitly canceled by user."); this.Logger.Error(taskCanceled); } catch (Exception exception) { this.Logger.Error(exception); } }
public async Task <CustomerRegistrationResponse> RegisterAdditionalProduct(Customer customer) { Log.Verbose("Requesting additonal product"); ServerResponse <CustomerRegistrationResponse> responseObj = await PostObjectAsync <CustomerRegistrationResponse, Customer>(customer); if (responseObj == null) { Log.Verbose("API CALL NOT successfull"); return(new CustomerRegistrationResponse() { Customer = null, RequestId = customer.RequestId, Successful = false, RegistrationSuccessful = false, ResponseText = null }); } Log.Verbose("API Response " + responseObj.IsSuccessStatus); Log.Verbose(responseObj.RawResponse); // try getting the object from JSON CustomerRegistrationResponse response = null; try { response = responseObj.GetObject(); } catch (Exception e) { Log.Error(e); } // got a proper result, return it if (response != null) { response.Successful = true; return(response); } Log.Verbose("Could not parse response."); // if exception was thrown, return the exception as text if (responseObj.RequestException != null) { return(new CustomerRegistrationResponse() { Customer = null, RequestId = customer.RequestId, Successful = false, RegistrationSuccessful = false, ResponseText = responseObj.RequestException.ToString() }); } return(new CustomerRegistrationResponse() { Customer = null, RequestId = customer.RequestId, Successful = false, RegistrationSuccessful = false, ResponseText = "Unknown Error." }); }
public async Task <SwapComponentResponse> SwapComponent(SwapComponentRequest request, ErrorFilterFlags filterFlags = ErrorFilterFlags.EnableErrorHandling, ApiTimeoutEnum timeout = ApiTimeoutEnum.Long) { Log.Verbose("Swapping component."); ServerResponse <SwapComponentResponse> response = null; try { response = await PostObjectAsync <SwapComponentResponse, SwapComponentRequest>(request, filterFlags : filterFlags, timeOut : timeout); } catch (Exception e) { Log.Error(e); return(new SwapComponentResponse() { Success = false, Status = ServiceReturnStatus.NoInternet, Message = "A connection error has occurred. Check your internet settings." }); } Log.Verbose("API call done."); if (response == null) { Log.Verbose("API NOT successfull"); return(new SwapComponentResponse() { Success = false, Status = ServiceReturnStatus.NoInternet, Message = "A connection error has occurred. Check your internet settings." }); } Log.Verbose("API result:"); Log.Verbose(response.RawResponse); // try getting the object from JSON SwapComponentResponse result = null; try { result = response.GetObject(); } catch (Exception e) { Log.Error(e); return(new SwapComponentResponse() { Success = false, Status = ServiceReturnStatus.ParseError, Message = "An error has occurred when getting the server response." }); } // got a proper result, return it if (result != null) { return(result); } Log.Verbose("Could not parse response."); return(new SwapComponentResponse() { Success = false, Status = ServiceReturnStatus.ParseError, Message = "An error has occurred when getting the server response." }); }