From c3cd0bf22ccbd9b50cc163b889c6ee50f0726b7b Mon Sep 17 00:00:00 2001 From: Mark Wandner Date: Mon, 15 Aug 2016 16:25:33 +0930 Subject: [PATCH] Added MailChimp automation models. --- MailChimp/Automations/Automation.cs | 375 ++++++++++++++++++ MailChimp/Automations/AutomationError.cs | 48 +++ MailChimp/Automations/AutomationFilter.cs | 158 ++++++++ MailChimp/Automations/AutomationListResult.cs | 30 ++ .../Automations/AutomationSavedSegment.cs | 30 ++ MailChimp/Automations/AutomationSocialCard.cs | 37 ++ MailChimp/Automations/AutomationTracking.cs | 30 ++ MailChimp/Lists/AddCampaignSegmentOptions.cs | 14 +- MailChimp/Lists/SegmentTestOptions.cs | 25 ++ MailChimp/MailChimp.csproj | 8 + MailChimp/MailChimpManager.cs | 42 +- MailChimp/Reports/Unsubscribes.cs | 1 + 12 files changed, 784 insertions(+), 14 deletions(-) create mode 100644 MailChimp/Automations/Automation.cs create mode 100644 MailChimp/Automations/AutomationError.cs create mode 100644 MailChimp/Automations/AutomationFilter.cs create mode 100644 MailChimp/Automations/AutomationListResult.cs create mode 100644 MailChimp/Automations/AutomationSavedSegment.cs create mode 100644 MailChimp/Automations/AutomationSocialCard.cs create mode 100644 MailChimp/Automations/AutomationTracking.cs create mode 100644 MailChimp/Lists/SegmentTestOptions.cs diff --git a/MailChimp/Automations/Automation.cs b/MailChimp/Automations/Automation.cs new file mode 100644 index 0000000..f094f44 --- /dev/null +++ b/MailChimp/Automations/Automation.cs @@ -0,0 +1,375 @@ +using MailChimp.Campaigns; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class Automation + { + /// + /// Campaign Id (used for all other campaign functions) + /// + [DataMember(Name="id")] + public string Id + { + get; + set; + } + + /// + /// The Campaign id used in our web app, allows you to create a link directly to it + /// + [DataMember(Name = "web_id")] + public int WebId + { + get; + set; + } + + /// + /// The List used for this campaign + /// + [DataMember(Name = "list_id")] + public string ListId + { + get; + set; + } + + /// + /// The Folder this campaign is in + /// + [DataMember(Name = "folder_id")] + public int FolderId + { + get; + set; + } + + /// + /// The Template this campaign uses + /// + [DataMember(Name = "template_id")] + public int TemplateId + { + get; + set; + } + + /// + /// How the campaign's content is put together - one of 'template', 'html', 'url' + /// + [DataMember(Name = "content_type")] + public string ContentType + { + get; + set; + } + + /// + /// Title of the campaign + /// + [DataMember(Name = "title")] + public string Title + { + get; + set; + } + + /// + /// The type of campaign this is (regular,plaintext,absplit,rss,inspection,auto) + /// + [DataMember(Name = "type")] + public string Type + { + get; + set; + } + + /// + /// Creation time for the campaign + /// + [DataMember(Name = "create_time")] + public string CreateTime + { + get; + set; + } + + /// + /// Send time for the campaign - also the scheduled time for scheduled campaigns. + /// + [DataMember(Name = "send_time")] + public string SendTime + { + get; + set; + } + + /// + /// Number of emails email was sent to + /// + [DataMember(Name = "emails_sent")] + public int EmailsSent + { + get; + set; + } + + /// + /// Status of the given campaign (save,paused,schedule,sending,sent) + /// + [DataMember(Name = "status")] + public string Status + { + get; + set; + } + + /// + /// From name of the given campaign + /// + [DataMember(Name = "from_name")] + public string FromName + { + get; + set; + } + + /// + /// Reply-to email of the given campaign + /// + [DataMember(Name = "from_email")] + public string FromEmail + { + get; + set; + } + + /// + /// Subject of the given campaign + /// + [DataMember(Name = "subject")] + public string Subject + { + get; + set; + } + + /// + /// Custom "To:" email string using merge variables + /// + [DataMember(Name = "to_name")] + public string ToName + { + get; + set; + } + + /// + /// Archive link for the given campaign + /// + [DataMember(Name = "archive_url")] + public string ArchiveUrl + { + get; + set; + } + + /// + /// Whether or not the campaign content's css was auto-inlined + /// + [DataMember(Name = "inline_css")] + public bool InlineCSS + { + get; + set; + } + + /// + /// Either "google" if enabled or "N" if disabled + /// + [DataMember(Name = "analytics")] + public string Analytics + { + get; + set; + } + + /// + /// The name/tag the campaign's links were tagged with if analytics were enabled. + /// + [DataMember(Name = "analytics_tag")] + public string AnalyticsTag + { + get; + set; + } + + /// + /// Whether or not the campaign was authenticated + /// + [DataMember(Name = "authenticate")] + public bool Authenticate + { + get; + set; + } + + /// + /// Whether or not ecomm360 tracking was appended to links + /// + [DataMember(Name = "ecomm360")] + public bool Ecomm360 + { + get; + set; + } + + /// + /// Whether or not the campaign was auto tweeted after sending + /// + [DataMember(Name = "auto_tweet")] + public bool AutoTweet + { + get; + set; + } + + /// + /// A comma delimited list of Facebook Profile/Page Ids the + /// campaign was posted to after sending. If not used, blank. + /// + [DataMember(Name = "auto_fb_post")] + public string AutoFacebookPost + { + get; + set; + } + + /// + /// Whether or not the auto_footer was manually turned on + /// + [DataMember(Name = "auto_footer")] + public bool AutoFooter + { + get; + set; + } + + /// + /// Whether or not the campaign used Timewarp + /// + [DataMember(Name = "timewarp")] + public bool Timewarp + { + get; + set; + } + + /// + /// The time, in GMT, that the Timewarp campaign is being sent. + /// For A/B Split campaigns, this is blank and is instead in + /// their schedule_a and schedule_b in the type_opts array + /// + [DataMember(Name = "timewarp_schedule")] + public string TimewarpSchedule + { + get; + set; + } + + /// + /// the unique id of the parent campaign + /// (currently only valid for rss children) + /// + [DataMember(Name = "parent_id")] + public string ParentId + { + get; + set; + } + + [DataMember(Name = "is_child")] + public bool IsChild + { + get; + set; + } + + [DataMember(Name = "tests_sent")] + public string TestsSent + { + get; + set; + } + + [DataMember(Name = "tests_remain")] + public int TestsRemain + { + get; + set; + } + + [DataMember(Name = "tracking")] + public AutomationTracking Tracking + { + get; + set; + } + + /// + /// a string marked-up with HTML explaining the segment + /// used for the campaign in plain English + /// + [DataMember(Name = "segment_text")] + public string SegmentText + { + get; + set; + } + + [DataMember(Name = "segment_opts")] + public CampaignSegmentOptions SegmentOpts + { + get; + set; + } + + [DataMember(Name = "saved_segment")] + public AutomationSavedSegment SavedSegment + { + get; + set; + } + + /// + /// total number of comments left on this campaign + /// + [DataMember(Name = "comments_total")] + public int CommentsTotal + { + get; + set; + } + + /// + /// total number of unread comments for this campaign + /// based on the login the apikey belongs to + /// + [DataMember(Name = "comments_unread")] + public int CommentsUnread + { + get; + set; + } + + [DataMember(Name = "social_card")] + public AutomationSocialCard SocialCard + { + get; + set; + } + } +} diff --git a/MailChimp/Automations/AutomationError.cs b/MailChimp/Automations/AutomationError.cs new file mode 100644 index 0000000..05a83dd --- /dev/null +++ b/MailChimp/Automations/AutomationError.cs @@ -0,0 +1,48 @@ +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationError + { + /// + /// the filter that caused the failure + /// + [DataMember(Name = "filter")] + public string Filter + { + get; + set; + } + + /// + /// the filter value that caused the failure + /// + [DataMember(Name = "value")] + public string Value + { + get; + set; + } + + /// + /// the error code + /// + [DataMember(Name = "code")] + public int Code + { + get; + set; + } + + /// + /// the error message + /// + [DataMember(Name = "msg")] + public string Message + { + get; + set; + } + } +} diff --git a/MailChimp/Automations/AutomationFilter.cs b/MailChimp/Automations/AutomationFilter.cs new file mode 100644 index 0000000..d4e2a33 --- /dev/null +++ b/MailChimp/Automations/AutomationFilter.cs @@ -0,0 +1,158 @@ +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationFilter + { + /// + /// optional - return the campaign using a know campaign_id. Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "campaign_id")] + public string CampaignId + { + get; + set; + } + + /// + /// optional - return the child campaigns using a known parent campaign_id. Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "parent_id")] + public string ParentId + { + get; + set; + } + + /// + /// optional - the list to send this campaign to - get lists using lists(). Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "list_id")] + public string ListId + { + get; + set; + } + + /// + /// optional - only show campaigns from this folder id - get folders using campaignFolders(). Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "folder_id")] + public int? FolderId + { + get; + set; + } + + /// + /// optional - only show campaigns using this template id - get templates using templates(). Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "template_id")] + public int? TemplateId + { + get; + set; + } + + /// + /// optional - return campaigns of a specific status - one of "sent", "save", "paused", "schedule", "sending". Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "status")] + public string Status + { + get; + set; + } + + /// + /// optional - return campaigns of a specific type - one of "regular", "plaintext", "absplit", "rss", "auto". Accepts multiples separated by commas when not using exact matching. + /// + [DataMember(Name = "type")] + public string Type + { + get; + set; + } + + /// + /// optional - only show campaigns that have this "From Name" + /// + [DataMember(Name = "from_name")] + public string FromName + { + get; + set; + } + + /// + /// optional - only show campaigns that have this "Reply-to Email" + /// + [DataMember(Name = "from_email")] + public string FromEmail + { + get; + set; + } + + /// + /// optional - only show campaigns that have this title + /// + [DataMember(Name = "title")] + public string Title + { + get; + set; + } + + /// + /// optional - only show campaigns that have this subject + /// + [DataMember(Name = "subject")] + public string Subject + { + get; + set; + } + + /// + /// optional - only show campaigns that have been sent since this date/time (in GMT) - - 24 hour format in GMT, eg "2013-12-30 20:30:00" - if this is invalid the whole call fails + /// + [DataMember(Name = "sendtime_start")] + public string SendtimeStart + { + get; + set; + } + + /// + /// optional - only show campaigns that have been sent before this date/time (in GMT) - - 24 hour format in GMT, eg "2013-12-30 20:30:00" - if this is invalid the whole call fails + /// + [DataMember(Name = "sendtime_end")] + public string SendtimeEnd + { + get; + set; + } + + /// + /// optional - whether to return just campaigns with or without segments + /// + [DataMember(Name = "uses_segment")] + public bool? UsesSegment + { + get; + set; + } + + /// + /// optional - flag for whether to filter on exact values when filtering, or search within content for filter values - defaults to true. Using this disables the use of any filters that accept multiples. + /// + [DataMember(Name = "exact")] + public bool? Exact + { + get; + set; + } + } +} diff --git a/MailChimp/Automations/AutomationListResult.cs b/MailChimp/Automations/AutomationListResult.cs new file mode 100644 index 0000000..e1dc89a --- /dev/null +++ b/MailChimp/Automations/AutomationListResult.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationListResult + { + [DataMember(Name = "total")] + public int Total + { + get; + set; + } + + [DataMember(Name = "data")] + public List Data + { + get; + set; + } + + [DataMember(Name = "errors")] + public List Errors + { + get; + set; + } + } +} diff --git a/MailChimp/Automations/AutomationSavedSegment.cs b/MailChimp/Automations/AutomationSavedSegment.cs new file mode 100644 index 0000000..b8786fd --- /dev/null +++ b/MailChimp/Automations/AutomationSavedSegment.cs @@ -0,0 +1,30 @@ +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationSavedSegment + { + [DataMember(Name = "id")] + public int Id + { + get; + set; + } + + [DataMember(Name = "type")] + public string Type + { + get; + set; + } + + [DataMember(Name = "name")] + public string Name + { + get; + set; + } + + } +} diff --git a/MailChimp/Automations/AutomationSocialCard.cs b/MailChimp/Automations/AutomationSocialCard.cs new file mode 100644 index 0000000..a70c206 --- /dev/null +++ b/MailChimp/Automations/AutomationSocialCard.cs @@ -0,0 +1,37 @@ +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationSocialCard + { + [DataMember(Name = "title")] + public string Title + { + get; + set; + } + + [DataMember(Name = "description")] + public string Description + { + get; + set; + } + + [DataMember(Name = "image_url")] + public string ImageUrl + { + get; + set; + } + + [DataMember(Name = "enabled")] + public string Enabled + { + get; + set; + } + + } +} diff --git a/MailChimp/Automations/AutomationTracking.cs b/MailChimp/Automations/AutomationTracking.cs new file mode 100644 index 0000000..0e0cb5f --- /dev/null +++ b/MailChimp/Automations/AutomationTracking.cs @@ -0,0 +1,30 @@ +using System.Runtime.Serialization; + +namespace MailChimp.Automations +{ + [DataContract] + public class AutomationTracking + { + [DataMember(Name = "html_clicks")] + public bool HtmlClicks + { + get; + set; + } + + [DataMember(Name = "text_clicks")] + public bool TextClicks + { + get; + set; + } + + [DataMember(Name = "opens")] + public bool Opens + { + get; + set; + } + + } +} diff --git a/MailChimp/Lists/AddCampaignSegmentOptions.cs b/MailChimp/Lists/AddCampaignSegmentOptions.cs index d184d74..6770b9a 100644 --- a/MailChimp/Lists/AddCampaignSegmentOptions.cs +++ b/MailChimp/Lists/AddCampaignSegmentOptions.cs @@ -4,24 +4,12 @@ namespace MailChimp.Lists { [DataContract] - public class AddCampaignSegmentOptions + public class AddCampaignSegmentOptions : SegmentTestOptions { /// /// either "static" or "saved" /// [DataMember(Name = "type")] public string SegmentType { get; set; } - - /// - /// a unique name per list for the segment - 100 byte maximum length, anything longer will throw an error - /// - [DataMember(Name = "name")] - public string Name { get; set; } - - /// - /// various options for the new segment - /// - [DataMember(Name = "segment_opts")] - public CampaignSegmentOptions SegmentOptions { get; set; } } } \ No newline at end of file diff --git a/MailChimp/Lists/SegmentTestOptions.cs b/MailChimp/Lists/SegmentTestOptions.cs new file mode 100644 index 0000000..28f6373 --- /dev/null +++ b/MailChimp/Lists/SegmentTestOptions.cs @@ -0,0 +1,25 @@ +using MailChimp.Campaigns; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; + +namespace MailChimp.Lists +{ + [DataContract] + public class SegmentTestOptions + { + /// + /// a unique name per list for the segment - 100 byte maximum length, anything longer will throw an error + /// + [DataMember(Name = "name")] + public string Name { get; set; } + + /// + /// various options for the new segment + /// + [DataMember(Name = "segment_opts")] + public CampaignSegmentOptions SegmentOptions { get; set; } + } +} \ No newline at end of file diff --git a/MailChimp/MailChimp.csproj b/MailChimp/MailChimp.csproj index 29a8e6d..9bd6972 100644 --- a/MailChimp/MailChimp.csproj +++ b/MailChimp/MailChimp.csproj @@ -45,6 +45,13 @@ + + + + + + + @@ -85,6 +92,7 @@ + diff --git a/MailChimp/MailChimpManager.cs b/MailChimp/MailChimpManager.cs index a3802c4..b2eb295 100644 --- a/MailChimp/MailChimpManager.cs +++ b/MailChimp/MailChimpManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using MailChimp.Automations; using MailChimp.Campaigns; using MailChimp.Ecomm; using MailChimp.Errors; @@ -14,7 +15,6 @@ using ServiceStack.Text; using System.IO; - namespace MailChimp { #region Interface @@ -962,6 +962,30 @@ public static string ConvertDateTimeToMailChimpAPI(DateTime? date) #endregion + #region API: Automations + + public AutomationListResult GetAutomations(AutomationFilter filterParam = null, int start = 0, int limit = 25, string sort_field = "create_time", string sort_dir = "DESC") + { + // Our api action: + string apiAction = "automations/list"; + + // Create our arguments object: + object args = new + { + apikey = this.APIKey, + filters = filterParam, + start = start, + limit = limit, + sort_field = sort_field, + sort_dir = sort_dir + }; + + // Make the call: + return MakeAPICall(apiAction, args); + } + + #endregion + #region API: Campaigns /// @@ -2520,6 +2544,22 @@ public SegmentResult GetSegmentsForList(string listId, string segmentType) return MakeAPICall(apiAction, args); } + public CompleteResult UpdateSegment(string listId, string segmentId, SegmentTestOptions segmentOptions) + { + // our api action: + string apiAction = "lists/segment-update"; + + // create our arguements object: + object args = new + { + apikey = this.APIKey, + id = listId, + seg_id = segmentId, + opts = segmentOptions + }; + return MakeAPICall(apiAction, args); + } + /// /// Return the Webhooks configured for the given list /// diff --git a/MailChimp/Reports/Unsubscribes.cs b/MailChimp/Reports/Unsubscribes.cs index 7516103..f305bbc 100644 --- a/MailChimp/Reports/Unsubscribes.cs +++ b/MailChimp/Reports/Unsubscribes.cs @@ -23,6 +23,7 @@ public class Unsubscribes public List Data { get; set; } } + [DataContract] public class UnsubscribesData { ///