4 | <%= render :partial => "/shared/admin/sortable_list", :locals => {:continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)} %>
5 |
--------------------------------------------------------------------------------
/lib/tasks/mailchimp.rake:
--------------------------------------------------------------------------------
1 | namespace :refinery do
2 |
3 | namespace :mailchimp do
4 |
5 | # call this task my running: rake refinery:campaigns:my_task
6 | # desc "Description of my task below"
7 | # task :my_task => :environment do
8 | # # add your logic here
9 | # end
10 |
11 | end
12 |
13 | end
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Refinery::Application.routes.draw do
2 | scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
3 | resources :campaigns do
4 | member do
5 | get :send_options
6 | post :send_test
7 | post :send_now
8 | post :schedule
9 | post :unschedule
10 | end
11 | end
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/features/campaigns.feature_brainstorm:
--------------------------------------------------------------------------------
1 | @campaign
2 | Feature: Campaigns
3 | Campaigns can be created through the given user model
4 | current_user is assumed through admin screens
5 |
6 | Scenario: Saving a campaign is successful
7 | Given I am a logged in refinery user
8 |
9 | When I am on the new campaign form
10 | And I fill in "Subject" with "This is my campaign"
11 | And I fill in "Body" with "And I love it"
12 | And I press "Save"
13 |
14 | Then there should be 1 campaign
15 | And the campaign should belong to me
--------------------------------------------------------------------------------
/features/support/paths.rb:
--------------------------------------------------------------------------------
1 | module NavigationHelpers
2 | module Refinery
3 | module Mailchimp
4 | def path_to(page_name)
5 | case page_name
6 | when /the list of campaigns/
7 | admin_campaigns_path
8 | when /the new campaigns? form/
9 | new_admin_campaign_path
10 | else
11 | begin
12 | if page_name =~ /the campaign subjectd "?([^\"]*)"?/ and (page = Campaign.find_by_subject($1)).present?
13 | self.url_for(page.url)
14 | else
15 | nil
16 | end
17 | rescue
18 | nil
19 | end
20 | end
21 | end
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/spec/controllers/admin/campaigns_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | Dir[File.expand_path('../../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
3 |
4 | describe Admin::CampaignsController do
5 | describe "getting lists and templates" do
6 | it "should get lists and templates on new"
7 | it "should get lists and templates on create"
8 | end
9 |
10 | describe "creating a campaign" do
11 | it "should redirect to index with flash message if API is not set up"
12 | end
13 |
14 | describe "sending the campaign" do
15 | it "should send a test email"
16 | it "should send the campaign now"
17 | it "should schedule the campaign to send in the future"
18 | end
19 | end
--------------------------------------------------------------------------------
/db/migrate/1_create_campaigns.rb:
--------------------------------------------------------------------------------
1 | class CreateCampaigns < ActiveRecord::Migration
2 |
3 | def self.up
4 | create_table :campaigns do |t|
5 | t.string :subject, :mailchimp_campaign_id, :mailchimp_list_id, :mailchimp_template_id, :from_email, :from_name, :to_name
6 | t.text :body
7 | t.datetime :sent_at, :scheduled_at
8 | t.boolean :auto_tweet, :default => false
9 | t.timestamps
10 | end
11 |
12 | add_index :campaigns, :id
13 |
14 | load(Rails.root.join('db', 'seeds', 'campaigns.rb'))
15 | end
16 |
17 | def self.down
18 | UserPlugin.destroy_all({:name => "Campaigns"})
19 |
20 | Page.delete_all({:link_url => "/campaigns"})
21 |
22 | drop_table :campaigns
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/config/locales/nb.yml:
--------------------------------------------------------------------------------
1 | nb:
2 | plugins:
3 | refinerycms_mailchimp:
4 | title: Campaigns
5 | admin:
6 | campaigns:
7 | index:
8 | create_new: Lag en ny Campaign
9 | reorder: Endre rekkefølgen på Campaigns
10 | reorder_done: Ferdig å endre rekkefølgen Campaigns
11 | sorry_no_results: Beklager! Vi fant ikke noen resultater.
12 | no_items_yet: Det er ingen Campaigns enda. Klikk på "Lag en ny Campaign" for å legge til din første campaign.
13 | campaign:
14 | view_live: Vis hvordan denne campaign ser ut offentlig (åpner i et nytt vindu)
15 | edit: Rediger denne campaign
16 | delete: Fjern denne campaign permanent
17 | campaigns:
18 | show:
19 | other: Andre Campaigns
20 |
--------------------------------------------------------------------------------
/config/locales/nl.yml:
--------------------------------------------------------------------------------
1 | nl:
2 | plugins:
3 | refinerycms_mailchimp:
4 | title: Campaigns
5 | admin:
6 | campaigns:
7 | index:
8 | create_new: Maak een nieuwe Campaign
9 | reorder: Wijzig de volgorde van de Campaigns
10 | reorder_done: Klaar met het wijzingen van de volgorde van de Campaigns
11 | sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
12 | no_items_yet: Er zijn nog geen Campaigns. Druk op 'Maak een nieuwe Campaign' om de eerste aan te maken.
13 | campaign:
14 | view_live: Bekijk deze campaign op de website (opent een nieuw venster)
15 | edit: Bewerk deze campaign
16 | delete: Verwijder deze campaign voor eeuwig
17 | campaigns:
18 | show:
19 | other: Andere Campaigns
20 |
--------------------------------------------------------------------------------
/refinerycms-mailchimp.gemspec:
--------------------------------------------------------------------------------
1 | Gem::Specification.new do |s|
2 | s.platform = Gem::Platform::RUBY
3 | s.name = 'refinerycms-mailchimp'
4 | s.author = 'Ian Terrell'
5 | s.email = 'ian.terrell@gmail.com'
6 | s.homepage = 'https://github.com/ianterrell/refinerycms-mailchimp'
7 | s.version = '0.0.2'
8 | s.description = 'Ruby on Rails Mailchimp engine for Refinery CMS. Manage your campaigns right from the admin!'
9 | s.date = '2011-04-04'
10 | s.summary = 'Ruby on Rails Mailchimp engine for Refinery CMS'
11 | s.require_paths = %w(lib)
12 | s.files = Dir['lib/**/*', 'config/**/*', 'app/**/*', 'spec/**/*', 'features/**/*', 'db/**/*']
13 | s.add_dependency 'hominid', '~> 3.0'
14 | end
15 |
--------------------------------------------------------------------------------
/db/seeds/campaigns.rb:
--------------------------------------------------------------------------------
1 | User.find(:all).each do |user|
2 | user.plugins.create(:name => "campaigns",
3 | :position => (user.plugins.maximum(:position) || -1) +1)
4 | end
5 |
6 | RefinerySetting.create :name => Refinery::Mailchimp::API::KeySetting[:name], :value => Refinery::Mailchimp::API::KeySetting[:default], :restricted => true
7 | RefinerySetting.create :name => Refinery::Mailchimp::API::DefaultFromNameSetting[:name], :value => Refinery::Mailchimp::API::DefaultFromNameSetting[:default], :restricted => true
8 | RefinerySetting.create :name => Refinery::Mailchimp::API::DefaultFromEmailSetting[:name], :value => Refinery::Mailchimp::API::DefaultFromEmailSetting[:default], :restricted => true
9 | RefinerySetting.create :name => Refinery::Mailchimp::API::DefaultToNameSetting[:name], :value => Refinery::Mailchimp::API::DefaultToNameSetting[:default], :restricted => true
10 |
11 |
--------------------------------------------------------------------------------
/spec/models/api_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | require 'hominid'
3 |
4 | Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
5 |
6 | describe Refinery::Mailchimp::API do
7 | describe "the client" do
8 | before do
9 | RefinerySetting.find_by_name(Refinery::Mailchimp::API::KeySetting[:name]).try :destroy
10 | RefinerySetting.rewrite_cache
11 | end
12 |
13 | it "should give a properly setup client if the API key is set" do
14 | RefinerySetting.set Refinery::Mailchimp::API::KeySetting[:name], 'abcdefg-us1'
15 | Refinery::Mailchimp::API.new
16 | end
17 |
18 | it "should raise an error if the API key is not set" do
19 | begin
20 | client = Refinery::Mailchimp::API.new
21 | fail
22 | rescue Refinery::Mailchimp::API::BadAPIKeyError
23 | end
24 | end
25 |
26 | it "should raise an error if the API key is malformed" do
27 | begin
28 | RefinerySetting.set Refinery::Mailchimp::API::KeySetting[:name], 'abcdefg'
29 | client = Refinery::Mailchimp::API.new
30 | fail
31 | rescue Refinery::Mailchimp::API::BadAPIKeyError
32 | end
33 | end
34 | end
35 | end
--------------------------------------------------------------------------------
/app/views/admin/campaigns/_campaign.html.erb:
--------------------------------------------------------------------------------
1 |
This will schedule the campaign to be sent automatically at a future date.
34 | <%= form_tag schedule_admin_campaign_path(@campaign) do -%>
35 | <%= render :partial => "modal_fields" %>
36 | <%= label_tag :send_at %>
37 | <%= select_datetime %>
38 | <%= submit_tag "Schedule Campaign"%>
39 | <% end %>
40 | <% end %>
--------------------------------------------------------------------------------
/spec/models/campaign_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}
3 |
4 | describe Campaign do
5 | describe "validations" do
6 | it "should be valid with valid attributes" do
7 | Factory.build(:campaign).should be_valid
8 | end
9 |
10 | it "requires subject" do
11 | Factory.build(:campaign, :subject => "").should_not be_valid
12 | end
13 |
14 | it "requires a body" do
15 | Factory.build(:campaign, :body => "").should_not be_valid
16 | end
17 | end
18 |
19 | describe "integrating with Mailchimp" do
20 | it "should save to mailchimp before create" do
21 | campaign = Factory.build(:campaign)
22 | campaign.mailchimp_campaign_id.should be_nil
23 |
24 | Refinery::Mailchimp::API.should_receive(:new).and_return(mock('api', :campaign_create => 'abcdef'))
25 | campaign.save
26 | campaign.reload.mailchimp_campaign_id.should == 'abcdef'
27 | end
28 |
29 | it "should not create and add error if mailchimp create fails" do
30 | campaign = Factory.build(:campaign)
31 | mock_api = mock('api')
32 | mock_api.stub(:campaign_create) { |*args| raise Hominid::APIError.new(mock('xmlerror', :faultCode => -32602, :message => "server error. invalid method parameters")) }
33 | Refinery::Mailchimp::API.should_receive(:new).and_return(mock_api)
34 | campaign.save.should be_false
35 | campaign.errors[:base].should include(I18n.t('admin.campaigns.campaign.mailchimp_error'))
36 | end
37 |
38 | it "should update mailchimp before save"
39 | it "should not save if mailchimp update fails"
40 | it "should know if it's been sent or scheduled"
41 | it "should know where it was sent to"
42 | end
43 | end
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Mailchimp engine for Refinery CMS
2 |
3 | This project was originally sponsored by Mailchimp! Many thanks to them for supporting open source development.
4 |
5 | ## How to use this engine with a Refinery CMS project
6 |
7 | To set up a Refinery app from scratch, you'll need to install Refinery and create a new app:
8 |
9 | gem install refinerycms
10 | refinerycms new_project
11 | cd new_project
12 |
13 | Once you have a Refinery app created, add this engine to your Gemfile in the `USER DEFINED` area:
14 |
15 | gem 'refinerycms-mailchimp'
16 |
17 | Then, from the command line:
18 |
19 | bundle install
20 | rails generate refinerycms_mailchimp
21 | rake db:migrate
22 |
23 | ## Settings
24 |
25 | You'll need to set up your Mailchimp API key in the Settings area. [Get your API key here.](https://admin.mailchimp.com/account/api-key-popup)
26 |
27 | All available settings are:
28 |
29 | * `mailchimp_api_key` The API key of the Mailchimp account you wish to send campaigns from.
30 | * `mailchimp_default_to_name` The default To: name recipients will see (not email address). This can be changed for each campaign.
31 | * `mailchimp_default_from_name` The default From: name for your campaign message (not an email address). This can be changed for each campaign.
32 | * `mailchimp_default_from_email` The default From: email address for your campaign message. This can be changed for each campaign.
33 |
34 | ## Using Templates
35 |
36 | This plugin currently only supports one editable text area per campaign. If you use a template, the body will replace the template's MAIN area (see [the Mailchimp docs on editable content areas](http://kb.mailchimp.com/article/template-language-creating-editable-content-areas)).
37 |
38 | ## How to run the test suite
39 |
40 | Uncomment the following line in your Gemfile:
41 |
42 | gem 'refinerycms-testing', '~> 0.9.9.9'
43 |
44 | Then install the testing functionality with
45 |
46 | rails generate refinerycms_testing
47 |
48 | You can now run all engine specs and features with `rake`, or run them separately with `rake spec` and `rake cucumber`.
--------------------------------------------------------------------------------
/app/views/admin/campaigns/_form.html.erb:
--------------------------------------------------------------------------------
1 | <% form_for [:admin, @campaign] do |f| -%>
2 | <%= render :partial => "/shared/admin/error_messages", :locals => {
3 | :object => @campaign,
4 | :include_object_name => true
5 | } %>
6 |
7 |