public List <Models.GenericElement> GetLists(string apiKey) { List <Models.GenericElement> list = new List <Models.GenericElement>(); Models.GenericElement genericElement; try { var headers = new Dictionary <string, string> { { "X-Mock", "200" } }; var sg = new SendGridClient(apiKey, apiHost, headers); var response = sg.RequestAsync(method: SendGridClient.Method.GET, urlPath: "contactdb/lists").GetAwaiter().GetResult(); var deserializeBody = response.DeserializeResponseBody(response.Body); foreach (var item in deserializeBody) { var arrayJson = (JArray)JsonConvert.DeserializeObject(Convert.ToString(item.Value)); foreach (var element in arrayJson.Children()) { var itemProperties = element.Children <JProperty>(); var id = itemProperties.FirstOrDefault(x => x.Name == "id"); var name = itemProperties.FirstOrDefault(x => x.Name == "name"); genericElement = new Models.GenericElement() { Id = id.Value.ToString(), Name = name.Value.ToString() }; list.Add(genericElement); } } } catch (Exception) { } return(list); }
public List <Models.GenericElement> GetLists(string key) { List <Models.GenericElement> list = new List <Models.GenericElement>(); Models.GenericElement element; var result = MethodGet(key, "campaigns"); dynamic data = JsonConvert.DeserializeObject(result.Data); foreach (var items in data) { element = new Models.GenericElement() { Id = items["campaignId"], Name = items["name"] }; list.Add(element); } return(list); }
public List <Models.GenericElement> GetFromFields(string key) { List <Models.GenericElement> list = new List <Models.GenericElement>(); Models.GenericElement element; var result = MethodGet(key, "from-fields"); dynamic data = JsonConvert.DeserializeObject(result.Data); foreach (var items in data) { if (Convert.ToBoolean(items["isActive"])) { element = new Models.GenericElement() { Id = items["fromFieldId"], Name = items["email"] }; list.Add(element); } } return(list); }
public List <Models.GenericElement> GetSenders(string apiKey) { List <Models.GenericElement> list = new List <Models.GenericElement>(); Models.GenericElement genericElement; try { var headers = new Dictionary <string, string> { { "X-Mock", "200" } }; var sg = new SendGridClient(apiKey, apiHost, headers); var response = sg.RequestAsync(method: SendGridClient.Method.GET, urlPath: "senders").GetAwaiter().GetResult(); var deserializeBody = response.Body.ReadAsStringAsync().GetAwaiter().GetResult(); var arrayJson = (JArray)JsonConvert.DeserializeObject(Convert.ToString(deserializeBody)); foreach (var element in arrayJson.Children()) { var itemProperties = element.Children <JProperty>(); var id = itemProperties.FirstOrDefault(x => x.Name == "id"); var nickname = itemProperties.FirstOrDefault(x => x.Name == "nickname"); var verified = itemProperties.FirstOrDefault(x => x.Name == "verified"); JObject verifiedObject = JObject.Parse(verified.Value.ToString()); string status = (string)verifiedObject["status"]; if (Convert.ToBoolean(status)) { genericElement = new Models.GenericElement() { Id = id.Value.ToString(), Name = nickname.Value.ToString() }; list.Add(genericElement); } } } catch (Exception) { } return(list); }