public GetMergeVarsResult GetMergeVars(string apiKey, IEnumerable <string> listIds) { GetMergeVarsResult result = null; var parameters = new Dictionary <string, object>(); parameters.Add("apikey", apiKey); parameters.Add("id", listIds); RestResponse response = RestClient.Post("[VER]/lists/merge-vars.[FORMAT]", parameters.ToJSON()); if (response.HasError) { if (response.HasData) { ErrorResponseInfo e = response.Get <ErrorResponseInfo>(); throw new Exception(string.Format("{0} ({1}) {2}", e.name, e.code, e.error)); } throw new Exception(response.Message); } if (response.HasData) { result = response.Get <GetMergeVarsResult>(); } return(result); }
public void JsonPropertyNamesAreCorrect() { var error = new ErrorResponseInfo { Error = new ErrorInfo { Code = "400.1", Message = new ErrorMessage { Text = "Field cannot be empty", Targets = new[] { "request.name" }, Links = new HelpLinks { Help = new[] { new HelpLink { Href = "the URL", Name = "the name", Title = "the title" } } } } } }; var json = JsonConvert.SerializeObject(error); Assert.NotNull(json); Assert.Equal( "{\"error\":{\"code\":\"400.1\",\"message\":{\"text\":\"Field cannot be empty\",\"targets\":[\"request.name\"],\"_links\":{\"help\":[{\"href\":\"the URL\",\"title\":\"the title\",\"name\":\"the name\"}]}}}}", json); }
public virtual IActionResult Post([FromBody] VehicleInfo vehicle) { if (vehicle == null) { return(BadRequest(ErrorResponseInfo.BadRequestError(1, "missing product", nameof(vehicle)))); } var vehicleId = repository.AddNewVehicle(vehicle.ToVehicle()); vehicle.VehicleIdentifier = vehicleId; return(CreatedAtRoute(GetByIdRouteName, new { id = vehicleId }, vehicle)); }
public virtual ActionResult <VehicleInfo> Get(string id) { if (string.IsNullOrWhiteSpace(id)) { return(BadRequest(ErrorResponseInfo.BadRequestError(1, "missing product id", nameof(id)))); } var vehicle = repository.FindById(id); if (vehicle == null) { return(new NotFoundResult()); } return(Ok(new VehicleInfo(vehicle))); }
public GetListsResult GetLists(string apiKey, ListFilters filters, int?start, int?limit, string sort_field, string sort_dir) { GetListsResult result = null; var parameters = new Dictionary <string, object>(); parameters.Add("apikey", apiKey); parameters.Add("filters", filters); if (start.HasValue) { parameters.Add("start", start.Value); } if (limit.HasValue) { parameters.Add("limit", limit.Value); } if (!string.IsNullOrEmpty(sort_field)) { parameters.Add("sort_field", sort_field); } if (!string.IsNullOrEmpty(sort_dir)) { parameters.Add("sort_dir", sort_dir); } RestResponse response = RestClient.Post("[VER]/lists/list.[FORMAT]", parameters.ToJSON()); if (response.HasError) { if (response.HasData) { ErrorResponseInfo e = response.Get <ErrorResponseInfo>(); throw new Exception(string.Format("{0} ({1}) {2}", e.name, e.code, e.error)); } throw new Exception(response.Message); } if (response.HasData) { result = response.Get <GetListsResult>(); } return(result); }
public EmailInfo SubscribeToList(string apiKey, string listId, EmailInfo email, IDictionary <string, object> merge_vars, string email_type, bool double_optin, bool update_existing, bool replace_interests, bool send_welcome) { EmailInfo result = null; var parameters = new { apikey = apiKey, id = listId, email = email, merge_vars = merge_vars, email_type = email_type, double_optin = double_optin, update_existing = update_existing, replace_interests = replace_interests, send_welcome = send_welcome }; RestResponse response = RestClient.Post("[VER]/lists/subscribe.[FORMAT]", parameters.ToJSON()); if (response.HasError) { if (response.HasData) { ErrorResponseInfo e = response.Get <ErrorResponseInfo>(); throw new Exception(string.Format("{0} ({1}) {2}", e.name, e.code, e.error)); } throw new Exception(response.Message); } if (response.HasData) { result = response.Get <EmailInfo>(); } return(result); }
public List <InterestGroupGroupingInfo> GetInterestGroupings(string apiKey, string listId, bool counts = false) { List <InterestGroupGroupingInfo> interestGroupings = null; var parameters = new { apikey = apiKey, id = listId, counts = counts.ToString() }; RestResponse response = RestClient.Post("[VER]/lists/interest-groupings.[FORMAT]", parameters.ToJSON()); if (response.HasError) { if (response.HasData) { ErrorResponseInfo e = response.Get <ErrorResponseInfo>(); if (e.name == "List_InvalidOption") // List doesn't have interest groups { return(new List <InterestGroupGroupingInfo>()); } throw new Exception(string.Format("{0} ({1}) {2}", e.name, e.code, e.error)); } throw new Exception(response.Message); } if (response.HasData) { interestGroupings = response.Get <List <InterestGroupGroupingInfo> >(); } return(interestGroupings); }