private RestRequest GetRequest(PersonListApiActions objectType, IDictionary <string, string> parameters = null, IDictionary <string, string> keys = null) { if (!_methods.ContainsKey(objectType)) { throw new NotImplementedException(); } return(GetRequest(_methods[objectType], parameters, keys)); }
private T Execute <T>(PersonListApiActions objectType, IDictionary <string, string> parameters = null, IDictionary <string, string> keys = null) where T : new() { var response = _client.Execute <T>(GetRequest(objectType, parameters ?? new Dictionary <string, string>(), keys ?? new Dictionary <string, string>())); if (response.ErrorException != null) { throw response.ErrorException; } if (response.ResponseStatus != ResponseStatus.Completed) { throw new Exception(response.ErrorMessage); } return(response.Data); }
private void Request(PersonListApiActions action, Method method, object body) { IRestRequest request = GetRequest(PersonListApiActions.Add); request.Method = method; request.AddJsonBody(body); var response = _client.Execute(request); if (response.StatusCode == HttpStatusCode.BadRequest) { throw JsonConvert.DeserializeObject <ErrorResponse>(response.Content).AsException(); } if (response.StatusCode != HttpStatusCode.OK) { // TODO : craete custom exception. throw new Exception("Error when request for add person."); } }