/// <inheritdoc/> public IEnumerable <MailchimpList> GetLists() { string url = string.Format( CultureInfo.InvariantCulture, "/{0}/{1}", MailchimpListClient.ApiVersion, MailchimpListClient.ListsApiUrlSegment); HttpResponseMessage httpResponseMessage = this.httpClient.GetAsync(url).Result; httpResponseMessage.EnsureSuccessStatusCode(); string responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result; GetListsResult result = JsonConvert.DeserializeObject <GetListsResult>(responseContent); return(result.Lists); }
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 async Task <GetListsResult> GetLists(string sessionId, int?accountId = null, string language = null, int?page = null, int retryCount = 0, int delayMilliseconds = 1000) { // no mistake here: missing "account_id" parameter add the string literal "{account_id}" as paths segment string baseUrl = BASE_Address + BASE_Path + ACCOUNT_DETAILS_Path + "/" + (accountId.HasValue ? accountId.Value.ToString() : "{account_id}") + LISTS_path; var query = new Dictionary <string, string>(); query.Add(API_KEY_Key, ApiKey); if (!string.IsNullOrEmpty(language)) { query.Add(LANGUAGE_Key, language); } if (page > 0) { query.Add(PAGE_Key, page.Value.ToString()); } query.Add(SESSION_ID_Key, sessionId); string requestUri = QueryHelpers.AddQueryString(baseUrl, query); GetListsResult result = await GetResponse <GetListsResult>(retryCount, delayMilliseconds, requestUri); return(result); }
private void button3_Click(object sender, EventArgs e) { GetListsResult resutl = _api.GetLists(null, null, null, string.Empty, string.Empty); }