Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from anwajler/rails3

Rails3
  • Loading branch information...
commit 4fcdc522235b2dadf057b9270373144b66fca42d 2 parents 494cc82 + 5621003
mpowered authored
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in campaign_monitor_subscriber.gemspec
+gemspec
View
20 README.rdoc
@@ -1,23 +1,22 @@
-= campaign_monitor_subscriber
-
-http://github.com/mpowered/campaign_monitor_subscriber
-
== DESCRIPTION:
-Automatically push/delete a model's email address to a Campaign Monitor mailing when the model is created or destroyed.
+Automatically push/delete a model's email address and custom-fields to a Campaign Monitor mailing when the model is created or destroyed.
== FEATURES:
-* Push email addresses to CM on create
+* Push email addresses and custom fields to CM on create
* Delete email address from CM on destroy
== SYNOPSIS:
-Specify the model's email address field name:
+Specify the model's email address field name. You can also pass additional custom fields:
+
Class User < ActiveRecord::Base
- subscribe_me_using :email
+ subscribe_me_using :email, {"name" => "full_name", "UserStatus" => "get_status"}
end
+This will call `full_name` and `get_status` methods on record which was created using `send`.
+
Set the list id & api key in config/campaign_monitor_subscriber_config.yml:
list_id: 12oeu0089oe8gf9794oe498587o5
api_key: 23rbmoe351sd123d12134hbi1234
@@ -31,7 +30,10 @@ Thats it!
== INSTALL:
- gem install campaign_monitor_subscriber
+Just add this to your Gemfile:
+ gem 'campaigning', '0.15.0'
+ gem 'campaign_monitor_subscriber', :git => "git@github.com:anwajler/campaign_monitor_subscriber.git", :branch => "rails3"
+
== LICENSE:
View
2  Rakefile
@@ -3,7 +3,7 @@ require 'rubygems'
require 'rake'
require 'echoe'
-Echoe.new('campaign_monitor_subscriber', '0.6.3') do |p|
+Echoe.new('campaign_monitor_subscriber', '0.6.4') do |p|
p.description = "Sync user emails with Campaign Monitor mailing lists"
p.url = "http://github.com/mpowered/campaign_monitor_subscriber"
p.author = "Gary Greyling"
View
22 campaign_monitor_subscriber.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "campaign_monitor_subscriber"
+ s.version = '0.6.4'
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Gary Greyling"]
+ s.email = ["gary@mpowered.co.za"]
+ s.homepage = "https://github.com/mpowered/campaign_monitor_subscriber"
+ s.summary = %q{Sync user emails with Campaign Monitor mailing lists}
+ s.description = %q{Sync user emails with Campaign Monitor mailing lists}
+
+ s.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_development_dependency 'rails', '>= 3.0.0'
+ s.add_development_dependency 'campaigning', '>= 0.15.0'
+
+ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
+end
View
19 lib/campaign_monitor_subscriber.rb
@@ -1,31 +1,26 @@
module CampaignMonitorSubscriber
require 'campaigning'
- CM_CONFIG = YAML::load_file(File.join(RAILS_ROOT, "config/campaign_monitor_subscriber_config.yml"))
+ CM_CONFIG = YAML::load_file(File.join("config/campaign_monitor_subscriber_config.yml"))
::CAMPAIGN_MONITOR_API_KEY = CM_CONFIG['api_key']
- def subscribe_me_using(email_field)
- return if CM_CONFIG[RAILS_ENV] == false
-
+ def subscribe_me_using(email_field, custom_fields={})
+ return if CM_CONFIG[::Rails.env] == false
after_create do |record|
begin
- s = Campaigning::Subscriber.new(record.send(email_field))
- s.add!(cm_list_id)
+ custom_fields = custom_fields.inject({}) { |h, (k, v)| h[k] = record.send(v); h }
+ s = Campaigning::Subscriber.new(record.send(email_field), custom_fields["name"])
+ s.add!(CM_CONFIG['list_id'], custom_fields)
rescue RuntimeError
end
end
after_destroy do |record|
begin
- Campaigning::Subscriber.unsubscribe!(record.send(email_field), cm_list_id)
+ Campaigning::Subscriber.unsubscribe!(record.send(email_field), CM_CONFIG['list_id'])
rescue RuntimeError
end
end
end
-
- private
- def cm_list_id
- YAML::load_file(File.join(RAILS_ROOT, "config/campaign_monitor_subscriber_config.yml"))['list_id']
- end
end
ActiveRecord::Base.extend(CampaignMonitorSubscriber)
Please sign in to comment.
Something went wrong with that request. Please try again.