Giter VIP home page Giter VIP logo

mailchimp-net's Introduction

=============================== MailChimp.NET

This project is a complete wrapper for the MailChimp API V2 (link), it was orignally forked from Spyros' (https://github.com/sdesyllas) library, and was refactored to include many concepts and snippets from the Jayme Davis' amazing Stripe.Net library. A big shout out to MailChimp for documenting their API so well, I was able to write 95% off this code without running a single request.

It includes:

  • Full Service MailChimp API Client
  • Async & Await Compatible
  • Webhooks Controller / Handler

This API was written to faciliate clean and concise code at all levels.

Installation

You can install via NuGet, or download a build from the releases page.

Configuration

You can instanciate a class using your APIKey and/or Datacentre, if these are omited the values from the config section are used:

  • Dynamic Runtime DataCentre & APIKey
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MailChimpServiceSettings" type="MailChimp.Net.Settings.MailChimpServiceConfiguration, MailChimp.Net.Settings" />
  </configSections>
  <MailChimpServiceSettings
    apiKey="testapikey-us7"
    subscriberListId="testlistid"
    serviceUrl="https://us7.api.mailchimp.com/2.0/"
    listsRelatedSection="lists"
    helperRelatedSection="helper"/>
</configuration>
Sample Services

Ping, Subscribe, ECommerce Tranaction

Webhooks

WebHooks are implemented for ASP.NET MVC projects via an abstact "WebhookController", this will natively call the virtual functions for each type of event with the parameters already mapped to input variables.

You're expected to catch any exceptions in your webhook overrides, otherwise the webhook will return a 500 error code and MailChimp will retry the request according to their backoff strategy.

Return Objects

Whenever possible the API will return a native object mapped with the values of the response, however a number of API calls in MailChimp result in specific structures to each account. To handle these cases the response always contains the raw JSON and a JSON.net JToken to allow for easy traversal of any response. If an error has occured the raw JSON will contain the JSON for the error.

Errors

Whenever possible we will map the error returned from the API to a native MailChimpException.

  1. Code example to subscribe a newsletter with the given groupings and merge vars
 IMailChimpApiService mailChimpApiService = new MailChimpApiService(MailChimpServiceConfiguration.Settings.ApiKey);
 
 var subscribeSources = new Grouping {Name = "Subscribe Source"};
 subscribeSources.Groups.Add("Site");

 var couponsGained = new Grouping {Name = "Coupons Gained"};
 couponsGained.Groups.Add("Coupon1");

 var interests = new Grouping {Name = "Interests"};
 interests.Groups.Add("Extreme Games");


 var fields = new Dictionary<string, string>
 {
     {"GENDER", "Male"},
     {"DATEBORN", DateTime.Now.ToString(CultureInfo.InvariantCulture)},
     {"CITY", "Athens"},
     {"COUNTRY", "Greece"}
 };

 var response = mailChimpApiService.Subscribe("[email protected]", new List() { subscribeSources, couponsGained, interests }, fields, true);

mailchimp-net's People

Contributors

andrewkalashnikov avatar james-andrewsmith avatar rivethead avatar sdesyllas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.