Exemple #1
0
        /// <summary>
        /// Get information about a specific list
        /// <param name="list_id">Unique id for the list</param>
        /// </summary>
        internal async Task <MCLists> GetListAsync(string list_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.not_applicable,
                                                    SubTargetType.not_applicable, list_id);

            string content;

            using (var client = new HttpClient())
            {
                Authenticate.ClientAuthentication(client);

                content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
            }

            return(JsonConvert.DeserializeObject <MCLists>(content));
        }
Exemple #2
0
        /// <summary>
        /// Get information about members in a list
        /// <param name="list_id">Unique id for the list</param>
        /// </summary>
        internal async Task <RootMember> GetMemberInfoOfAListAsync(string list_id, int offset = 0, int count = 10)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.members, SubTargetType.not_applicable, list_id);

            endpoint = String.Format("{0}?offset={1}&count={2}", endpoint, offset, count);

            string content;

            using (var client = new HttpClient())
            {
                Authenticate.ClientAuthentication(client);

                content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
            }

            return(JsonConvert.DeserializeObject <RootMember>(content));
        }
        /// <summary>
        /// Get interests in a specific category
        /// <param name="list_id">Unique id for the list</param>
        /// <param name="interest_category_id">Unique id for the interest category</param>
        /// <param name="interest_id">The specific interest or ‘group name</param>
        /// </summary>
        internal async Task <RootInterest> GetInterestCategoryInterestAsync(string list_id, string interest_category_id, string interest_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.interest_categories,
                                                    SubTargetType.interests, list_id, interest_category_id);

            endpoint = String.Format("{0}/{1}", endpoint, interest_id);
            string content;

            using (var client = new HttpClient())
            {
                Authenticate.ClientAuthentication(client);

                content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
            }

            return(JsonConvert.DeserializeObject <RootInterest>(content));
        }
Exemple #4
0
        /// <summary>
        /// Get a specific note for a specific list member
        /// <param name="list_id">Unique id for the list</param>
        /// <param name="subscriber_hash">The MD5 hash of the lowercase version of the list member’s email address</param>
        /// <param name="note_id">The id for the note.</param>
        /// </summary>
        internal async Task <Note> GetSpecificNoteAsync(string list_id, string subscriber_hash, string note_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.members, SubTargetType.notes, list_id, subscriber_hash);

            endpoint = String.Format("{0}/{1}", endpoint, note_id);

            string content;

            using (var client = new HttpClient())
            {
                Authenticate.ClientAuthentication(client);

                content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
            }

            return(JsonConvert.DeserializeObject <Note>(content));
        }
Exemple #5
0
        PutAsync <T>(string endpoint, T myContent) where T : class
        {
            HttpResponseMessage response;

            ResultWrapper <T> wrapper;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    };

                    var myContentJson = JsonConvert.SerializeObject(myContent, settings);

                    response = await client.PutAsync(endpoint,
                                                     new StringContent(myContentJson.ToString(),
                                                                       Encoding.UTF8, "application/json"));

                    if (response.IsSuccessStatusCode == true)
                    {
                        var responseContent = response.Content.ReadAsStringAsync();

                        var responseMapped = JsonConvert.DeserializeObject <T>(responseContent.Result);

                        wrapper = new ResultWrapper <T>(responseMapped, false);

                        return(wrapper);
                    }
                    else
                    {
                        wrapper = new ResultWrapper <T>(response, true);

                        return(wrapper);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Delete something
        /// <param name="endpoint">The url where we want to hit to get result</param>
        /// </summary>
        public static async Task <HttpResponseMessage> DeleteAsync(string endpoint)
        {
            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    result = await client.DeleteAsync(endpoint);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Get some result
        /// <param name="endpoint">The url where we want to hit to get result</param>
        /// </summary>
        public static async Task <T> GetAsync <T>(string endpoint) where T : class
        {
            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <T>(content));
        }
        /// <summary>
        /// Delete a list
        /// <param name="list_id">Unique id for the list</param>
        /// </summary>
        internal async Task <HttpResponseMessage> DeleteTemplateByIdAsync(string list_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.not_applicable, SubTargetType.not_applicable, list_id);

            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    result = await client.DeleteAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }
Exemple #9
0
        /// <summary>
        /// Get a specific campaign report
        /// <param name="campaignId">Campaign Id</param>
        /// </summary>
        internal async Task <ReportOverview_CampaignSpecific> CampaignSpecificOverviewAsync(string campaignId)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.not_applicable, SubTargetType.not_applicable, campaignId);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(JsonConvert.DeserializeObject <ReportOverview_CampaignSpecific>(content));
        }
Exemple #10
0
        /// <summary>
        /// Create something
        /// <param name="endpoint">The url where we want to hit to get result</param>
        /// </summary>
        public static async Task <ResultWrapper> PostAsync(string endpoint)
        {
            HttpResponseMessage response;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        Converters        = new List <JsonConverter>
                        {
                            new StringEnumConverter()
                        }
                    };

                    response = await client.PostAsync(endpoint,
                                                      new StringContent(String.Empty,
                                                                        Encoding.UTF8, "application/json"));

                    if (response.IsSuccessStatusCode == true)
                    {
                        return(new ResultWrapper(false));
                    }
                    else
                    {
                        var wrappedResult = new ResultWrapper(response, true);

                        return(wrappedResult);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        /// <summary>
        /// Return click details for a specific link
        /// <param name="campaignId">Campaign Id</param>
        /// <param name="linkId">The id for the link</param>
        /// </summary>
        internal async Task <ClickReports> GetAlllSubscribersInfoAsync(string campaignId, string linkId)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.click_details, SubTargetType.members, campaignId, linkId);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <ClickReports>(content));
        }
        /// <summary>
        /// Return statistics for the top-performing domains from a campaign.
        /// <param name="campaignId">Unique id for campaign</param>
        /// </summary>
        internal async Task <RootUnsubscribe> GetUnsubscriberListAsync(string campaignId)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.unsubscribed, SubTargetType.not_applicable, campaignId);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return(JsonConvert.DeserializeObject <RootUnsubscribe>(content));
        }
Exemple #13
0
        /// <summary>
        /// Delete a note
        /// <param name="list_id">Unique id for the list</param>
        /// <param name="subscriber_hash">The MD5 hash of the lowercase version of the list member’s email address</param>
        /// <param name="note_id">The id for the note.</param>
        /// </summary>
        internal async Task <HttpResponseMessage> DeleteListMemberAsync(string list_id, string subscriber_hash, string note_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.members, SubTargetType.notes, list_id, subscriber_hash);

            endpoint = String.Format("{0}/{1}", endpoint, note_id);
            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    result = await client.DeleteAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }
Exemple #14
0
        /// <summary>
        /// Get information about a specific template
        /// <param name="template_id">The unique id for the template.</param>
        /// </summary>
        public async Task <Template> GetTemplateByIdAsync(string template_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.templates, SubTargetType.not_applicable, SubTargetType.not_applicable, template_id);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <Template>(content));
        }
Exemple #15
0
        /// <summary>
        /// Return list member activity for a specific campaign
        /// <param name="campaignId">Unique id for the campaign</param>
        /// <param name="subscriber_hash">The MD5 hash of the lowercase version of the list member’s email address</param>
        /// </summary>
        internal async Task <EmailActivity> GetSubscriberSpecificEmailActivityAsync(string campaignId, string subscriber_hash)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.email_activity, SubTargetType.not_applicable, campaignId, subscriber_hash);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return(JsonConvert.DeserializeObject <EmailActivity>(content));
        }
Exemple #16
0
        /// <summary>
        /// Get all campaigns
        /// </summary>
        internal async Task <RootCampaign> GetCampaignsAsync()
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.campaigns, SubTargetType.not_applicable, SubTargetType.not_applicable);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <RootCampaign>(content));
        }
        /// <summary>
        /// Get feedback about a campaign
        /// <param name="campaignId">Unique id for the campaign</param>
        /// <param name="feedback_id">Unique id for the feedback message.</param>
        /// </summary>
        internal async Task <Feedback> GetSpecificFeedbackAsync(string campaignId, string feedback_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.campaigns, SubTargetType.feedback, SubTargetType.not_applicable, campaignId, feedback_id);

            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <Feedback>(content));
        }
        /// <summary>
        /// Delete a campaign feedback message
        /// <param name="campaignId">Unique id for the campaign</param>
        /// <param name="feedback_id">Unique id for the feedback message.</param>
        /// </summary>
        internal async Task <HttpResponseMessage> DeleteSpecificFeedbackAsync(string campaignId, string feedback_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.campaigns, SubTargetType.feedback, SubTargetType.not_applicable, campaignId, feedback_id);

            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    result = await client.DeleteAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(result);
        }
Exemple #19
0
        /// <summary>
        /// Delete interests in a specific category
        /// <param name="list_id">Unique id for the list</param>
        /// <param name="interest_category_id">Unique id for the interest category</param>
        /// <param name="interest_id">The specific interest or ‘group name</param>
        /// </summary>
        internal async Task <HttpResponseMessage> DeleteInterestInSpecificCategoryAsync(string list_id, string interest_category_id, string interest_id)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.lists, SubTargetType.interest_categories, SubTargetType.interests, list_id, interest_category_id);

            endpoint = String.Format("{0}/{1}", endpoint, interest_id);

            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    result = await client.DeleteAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }
Exemple #20
0
        /// <summary>
        /// Get campaign reports
        /// <param name="campaignId">Campaign Id</param>
        /// </summary>
        internal async Task <ReportOverview> OverviewAsync()
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.not_applicable, SubTargetType.not_applicable);

            //string content = MailChimpWorker.Execute(Method.Get, endpoint).Result;
            string content;

            using (var client = new HttpClient())
            {
                try
                {
                    Authenticate.ClientAuthentication(client);

                    content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(JsonConvert.DeserializeObject <ReportOverview>(content));
        }