Code Monkey home page Code Monkey logo

mailchimp_api_v3's Introduction

Mailchimp API v3

Gem Version Gem downloads Build status Code quality Coverage Dependency Status

A simple gem to interact with Mailchimp through the Mailchimp API v3

Project status

This gem currently does everything I need for my project but it is far from complete. I will willingly accept good quality pull requests to complete the feature set.

My own requirements are for subscription management for my mailing list, so the gem can add and remove members from a list and manage their interests.

Installation

Add this line to your application's Gemfile:

gem 'mailchimp_api_v3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mailchimp_api_v3

Usage

The Mailchimp API documentation is here: http://kb.mailchimp.com/api. Their suggestions for subscriber management are here: http://kb.mailchimp.com/api/article/how-to-manage-subscribers.

To connect to the Mailchimp API you need to supply an API key. You can do this explicitly when you connect, or you can set an environment variable MAILCHIMP_API_KEY.

Examples:

Mailchimp.connect(my_api_key) # Uses the API key in my_api_key
Mailchimp.connect # Uses ENV['MAILCHIMP_API_KEY']
Mailchimp.connect.lists
mailchimp = Mailchimp.connect
list = mailchimp.lists.find_by name: 'My first list'
mailchimp = Mailchimp.connect
member = mailchimp.lists('e73f5910ca').members('[email protected]')
member.name # => "Ann Example"
member.update last_name: 'Williams'
# ActiveRecord-like methods
mailchimp = Mailchimp.connect
members = mailchimp.lists('e73f5910ca').where last_name: 'Example'
members.count # => 3
member = mailchimp.lists('e73f5910ca').members.first_or_create(
  email_address: '[email protected]', 
  name: 'Ann Example', 
  status: 'subscribed'
)
# Dealing with big lists
mailchimp = Mailchimp.connect
list = mailchimp.lists('e73f5910ca')

list.members.find_each do |member|
  # Do something
end

list.members.find_in_pages do |members|
  # Do something to a page of members
end

Contributing

Developer

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Testing

The tests use Rspec and VCR. To avoid including my test API key in the VCR cassettes the tests use Erb to insert an api key at runtime. Whatever API key is available will allow the tests to pass.

If you need to add more cassettes you can use your own test API key then edit the VCR cassette in the same way before you issue the pull request.

Acknowledgements

I used the sample code in https://github.com/mailchimp/APIv3-examples as my starting point for this gem. Thanks to the Mailchimp developers for the head start.

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.