Chimpactions

Easily move contacts between MailChimp lists in your Rails 3 application.

Requirements

A MailChimp account and API key.

Installation

Base

  1. Gemfilegem "chimpactions", "~> 0.0.1"
  2. rails generate chimpactions:install
  3. Edit config/chimpactions.yml with your information.
  4. add include Chimpactions::Subscriber to your model.
  5. add after_save :chimpactions (if that’s what you want) to your model.

The YourModel.chimpactions method fires the actions to move subscribers as specified.

Generates:

  • config/chimpactions.yml config file

ActiveRecord store

rails generate chimpactions:migration

rake db:migrate

Generates:

  • chimpactions ActiveRecord migration

Customizing Admin

Chimpactions provides a basic scaffold for managing ActiveRecord Actions @ http:yourapp/chimpactions. To override the gem views :

rails generate chimpactions:customize

Generates:

  • chimpactions view files for administrative interface
  • yourapp/app/views/chimpactions

Configuration

See installed config/chimpactions.yml for configuration options

Usage

What’s available

Once defined (in chimpactions.yml) the local Rails model inherits the following methods from the Chimpactions gem :

  • add_to(List)
  • move_to(List)
  • remove_from(List)

A Chimpaction :

WHENN (A model method/attribute) IS (<,>,=) VALUE, ACTION (Chimpactions method) LIST (One of your MailChimp Lists)

ex.

‘When a user has more than 50 posts, move them to the Power Poster list’

in chimpactions.yml

  action:
    -
    action: :move_to,
    list: Power Posters,
    whenn: posts.count,
    is: >,
    value: 50
    -

for ActiveRecord store The admin interface should be a straightforward representation.

Administrative Interface

Direct your browser to http://yourapp.chimpactions for a simple CRUD to build and manage Actions. Available values are set in the forms where applicable, validations will tell you if a value won’t work.

Manual access

You can move subscribers around arbitrarily as well:

user = User.find(123)
user.remove_from("Power Posters") 

Chimpactions Module

All your lists with a ton of info:

@lists = Chimpactions.available_lists
...view
<%= var_dump(@lists) ->

Calling the MailChimp API directly:

Direct access to the gibbon socket :

api_result = Chimpactions.socket.campaigns({:start => 0, :limit => 100})

Webhooks

To register your application with your MailChimp List direct your browser to : http://yourapp/chimpactions/webhooks

The links next to each list will add/delete the webhook http://yourapp/chimpactions/receive to that list.

You must handle the post itself in

 receive_webhook(mc_post_data) 
in your mix-in model for it have an effect.

TODO

  • implement VCR for tests so we don’t have to use a real API key
  • get loading don’t so we don’t have to add include Chimpactions::Subscriber in the model

License

This project released under the MIT-LICENSE.

Thanks

Made possible by the generous support of the MailChimp Integration Fund .

Copyrights

© circuitllc & imgenius 2011 – Released under the MIT license.