campaign_monitor_subscriber 0.6.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
- s.name = %q{campaign_monitor_subscriber}
5
- s.version = "0.6.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Gary Greyling"]
9
- s.date = %q{2011-04-05}
5
+ s.name = "campaign_monitor_subscriber"
6
+ s.version = '1.0.0'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Gary Greyling"]
9
+ s.email = ["gary@mpowered.co.za"]
10
+ s.homepage = "https://github.com/mpowered/campaign_monitor_subscriber"
11
+ s.summary = %q{Sync user emails with Campaign Monitor mailing lists}
10
12
  s.description = %q{Sync user emails with Campaign Monitor mailing lists}
11
- s.email = %q{gary@mpowered.co.za}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/campaign_monitor_subscriber.rb"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/campaign_monitor_subscriber.rb", "campaign_monitor_subscriber.gemspec"]
14
- s.homepage = %q{http://github.com/mpowered/campaign_monitor_subscriber}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Campaign_monitor_subscriber", "--main", "README.rdoc"]
13
+
14
+ s.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{campaign_monitor_subscriber}
18
- s.rubygems_version = %q{1.4.1}
19
- s.summary = %q{Sync user emails with Campaign Monitor mailing lists}
20
17
 
21
- if s.respond_to? :specification_version then
22
- s.specification_version = 3
18
+ s.add_dependency 'createsend', '>= 1.0.4'
19
+ s.add_development_dependency 'active_support', '>= 3.0.0'
23
20
 
24
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
- s.add_development_dependency(%q<campaigning>, [">= 0.15.0"])
26
- else
27
- s.add_dependency(%q<campaigning>, [">= 0.15.0"])
28
- end
29
- else
30
- s.add_dependency(%q<campaigning>, [">= 0.15.0"])
31
- end
21
+ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
32
22
  end
@@ -1,31 +1,4 @@
1
- module CampaignMonitorSubscriber
2
- require 'campaigning'
3
- CM_CONFIG = YAML::load_file(File.join(RAILS_ROOT, "config/campaign_monitor_subscriber_config.yml"))
4
- ::CAMPAIGN_MONITOR_API_KEY = CM_CONFIG['api_key']
1
+ require 'campaign_monitor_subscriber/basic_configuration'
2
+ require 'campaign_monitor_subscriber/macro'
5
3
 
6
- def subscribe_me_using(email_field)
7
- return if CM_CONFIG[RAILS_ENV] == false
8
-
9
- after_create do |record|
10
- begin
11
- s = Campaigning::Subscriber.new(record.send(email_field))
12
- s.add!(cm_list_id)
13
- rescue RuntimeError
14
- end
15
- end
16
-
17
- after_destroy do |record|
18
- begin
19
- Campaigning::Subscriber.unsubscribe!(record.send(email_field), cm_list_id)
20
- rescue RuntimeError
21
- end
22
- end
23
- end
24
-
25
- private
26
- def cm_list_id
27
- YAML::load_file(File.join(RAILS_ROOT, "config/campaign_monitor_subscriber_config.yml"))['list_id']
28
- end
29
- end
30
-
31
- ActiveRecord::Base.extend(CampaignMonitorSubscriber)
4
+ ActiveRecord::Base.extend(CampaignMonitorSubscriber::Macro)
@@ -0,0 +1,16 @@
1
+ # These methods become part of all models that call #subscribe_me_using regardless
2
+ # of the environment and other qualifying criteria.
3
+ # We keep this light so that if the current environment fails to qualify for subscription
4
+ # we haven't created a lot of bootstrapping overhead.
5
+ module CampaignMonitorSubscriber
6
+ module BasicConfiguration
7
+ require 'yaml'
8
+
9
+ private
10
+ # All yaml config is namespaced under the environment name (the same way
11
+ # database.yml does it)
12
+ def raw_cms_config
13
+ @raw_cms_config ||= YAML::load_file(File.join("config/campaign_monitor_subscriber.yml"))[::Rails.env]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ # These methods become class methods on a model that calls #subscribe_me_using.
2
+ # They provide config bootstrapping easy access to loaded configuration.
3
+ module CampaignMonitorSubscriber
4
+ module Configuration
5
+ # Load config from yaml and #subscribe_me_using arguments.
6
+ def load_cms_configuration(email_field, options)
7
+ options.stringify_keys!
8
+ # Load the list_id from the yaml file. If a list is specified in #subscribe_me_using
9
+ # then load the id under the '*given_list_name*_id' key.
10
+ # Otherwise use the value as defined under the 'list_id' key.
11
+ cms_config.list_id = raw_cms_config.fetch("#{options.delete('list')}_list_id", raw_cms_config['list_id'])
12
+
13
+ # Load the API key from the yaml file.
14
+ CreateSend.api_key raw_cms_config['api_key']
15
+
16
+ # Extract config from the options supplied to #subscribe_me_using.
17
+ cms_config.email_field = email_field
18
+ cms_config.name_field = options.delete('name')
19
+ cms_config.custom_fields = options
20
+ end
21
+
22
+ def cms_config
23
+ @cms_config ||= CMSConfig.new.config
24
+ end
25
+
26
+ # We namespace the AS::config in case this
27
+ # model already uses AS's configurable. Because we care :)
28
+ class CMSConfig
29
+ include ActiveSupport::Configurable
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # These methosd became instance methods on a model that calls #subscribe_me_using.
2
+ # They provide easy access to parsed CMS config values.
3
+ module CampaignMonitorSubscriber
4
+ module InstanceMethods
5
+ def cms_custom_fields
6
+ cms_config.custom_fields.inject({}) { |h, (k, v)| h[k] = send(v); h }
7
+ end
8
+
9
+ def cms_email
10
+ send(cms_config.email_field)
11
+ end
12
+
13
+ def cms_name
14
+ cms_config.name_field ? send(cms_config.name_field) : cms_email
15
+ end
16
+
17
+ def cms_config
18
+ self.class.cms_config
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module CampaignMonitorSubscriber
2
+ module Macro
3
+ def subscribe_me_using(email_field, options = {})
4
+ extend CampaignMonitorSubscriber::BasicConfiguration
5
+ # Don't active CMS hooks if there is no configuration for the
6
+ # current environment.
7
+ return if raw_cms_config.nil?
8
+
9
+ # Now that we know CMS subscription is relevant we
10
+ # include the required libraries and bootstrap the hooks
11
+ require 'createsend'
12
+ require 'campaign_monitor_subscriber/configuration'
13
+ require 'campaign_monitor_subscriber/instance_methods'
14
+ require 'campaign_monitor_subscriber/subscription_hooks'
15
+
16
+ # Load configuration from the yaml file and this macro's options
17
+ extend CampaignMonitorSubscriber::Configuration
18
+ load_cms_configuration(email_field, options)
19
+
20
+ # Include CMS config accessors to this model
21
+ include CampaignMonitorSubscriber::InstanceMethods
22
+ # Include CMS subscription hooks in this model
23
+ include CampaignMonitorSubscriber::SubscriptionHooks
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ # This module defines the CMS subscription callbacks.
2
+ # The callbacks are included in a model that calls #subscribe_me_using.
3
+ module CampaignMonitorSubscriber
4
+ module SubscriptionHooks
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ require 'logger'
10
+ @@log = Logger.new('log/cm_subscriber.log')
11
+
12
+ after_create do |record|
13
+ @@log.info "\n* Adding '#{record.cms_email}' to CM"
14
+
15
+ begin
16
+ CreateSend::Subscriber.add(
17
+ cms_config.list_id,
18
+ record.cms_email,
19
+ record.cms_name,
20
+ [record.cms_custom_fields],
21
+ true
22
+ )
23
+ rescue CreateSend::CreateSendError => err
24
+ @@log.info err.message
25
+ end
26
+ end
27
+
28
+
29
+ after_destroy do |record|
30
+ @@log.info "\n* Removing '#{record.cms_email}' from CM"
31
+
32
+ begin
33
+ s = CreateSend::Subscriber.new(
34
+ cms_config.list_id,
35
+ record.cms_email
36
+ )
37
+ s.unsubscribe
38
+ rescue CreateSend::CreateSendError => err
39
+ @@log.info err.message
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,93 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: campaign_monitor_subscriber
3
- version: !ruby/object:Gem::Version
4
- hash: 1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 6
9
- - 3
10
- version: 0.6.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Gary Greyling
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-05 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: campaigning
12
+ date: 2012-06-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: createsend
16
+ requirement: &2169567680 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.4
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *2169567680
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_support
27
+ requirement: &2169567200 !ruby/object:Gem::Requirement
25
28
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 35
30
- segments:
31
- - 0
32
- - 15
33
- - 0
34
- version: 0.15.0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
35
33
  type: :development
36
- version_requirements: *id001
34
+ prerelease: false
35
+ version_requirements: *2169567200
37
36
  description: Sync user emails with Campaign Monitor mailing lists
38
- email: gary@mpowered.co.za
37
+ email:
38
+ - gary@mpowered.co.za
39
39
  executables: []
40
-
41
40
  extensions: []
42
-
43
- extra_rdoc_files:
44
- - README.rdoc
45
- - lib/campaign_monitor_subscriber.rb
46
- files:
47
- - Manifest
48
- - README.rdoc
49
- - Rakefile
50
- - lib/campaign_monitor_subscriber.rb
41
+ extra_rdoc_files: []
42
+ files:
51
43
  - campaign_monitor_subscriber.gemspec
52
- has_rdoc: true
53
- homepage: http://github.com/mpowered/campaign_monitor_subscriber
44
+ - lib/campaign_monitor_subscriber.rb
45
+ - lib/campaign_monitor_subscriber/basic_configuration.rb
46
+ - lib/campaign_monitor_subscriber/configuration.rb
47
+ - lib/campaign_monitor_subscriber/instance_methods.rb
48
+ - lib/campaign_monitor_subscriber/macro.rb
49
+ - lib/campaign_monitor_subscriber/subscription_hooks.rb
50
+ homepage: https://github.com/mpowered/campaign_monitor_subscriber
54
51
  licenses: []
55
-
56
52
  post_install_message:
57
- rdoc_options:
58
- - --line-numbers
59
- - --inline-source
60
- - --title
61
- - Campaign_monitor_subscriber
62
- - --main
63
- - README.rdoc
64
- require_paths:
53
+ rdoc_options: []
54
+ require_paths:
65
55
  - lib
66
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
67
57
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
63
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- hash: 11
81
- segments:
82
- - 1
83
- - 2
84
- version: "1.2"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
85
68
  requirements: []
86
-
87
- rubyforge_project: campaign_monitor_subscriber
88
- rubygems_version: 1.4.1
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.6
89
71
  signing_key:
90
72
  specification_version: 3
91
73
  summary: Sync user emails with Campaign Monitor mailing lists
92
74
  test_files: []
93
-
data/Manifest DELETED
@@ -1,4 +0,0 @@
1
- Manifest
2
- README.rdoc
3
- Rakefile
4
- lib/campaign_monitor_subscriber.rb
data/README.rdoc DELETED
@@ -1,59 +0,0 @@
1
- = campaign_monitor_subscriber
2
-
3
- http://github.com/mpowered/campaign_monitor_subscriber
4
-
5
- == DESCRIPTION:
6
-
7
- Automatically push/delete a model's email address to a Campaign Monitor mailing when the model is created or destroyed.
8
-
9
- == FEATURES:
10
-
11
- * Push email addresses to CM on create
12
- * Delete email address from CM on destroy
13
-
14
- == SYNOPSIS:
15
-
16
- Specify the model's email address field name:
17
- Class User < ActiveRecord::Base
18
- subscribe_me_using :email
19
- end
20
-
21
- Set the list id & api key in config/campaign_monitor_subscriber_config.yml:
22
- list_id: 12oeu0089oe8gf9794oe498587o5
23
- api_key: 23rbmoe351sd123d12134hbi1234
24
- development: false # disable in development
25
-
26
- Thats it!
27
-
28
- == REQUIREMENTS:
29
-
30
- * campaigning gem
31
-
32
- == INSTALL:
33
-
34
- gem install campaign_monitor_subscriber
35
-
36
- == LICENSE:
37
-
38
- (The MIT License)
39
-
40
- Copyright (c) 2010 FIX
41
-
42
- Permission is hereby granted, free of charge, to any person obtaining
43
- a copy of this software and associated documentation files (the
44
- 'Software'), to deal in the Software without restriction, including
45
- without limitation the rights to use, copy, modify, merge, publish,
46
- distribute, sublicense, and/or sell copies of the Software, and to
47
- permit persons to whom the Software is furnished to do so, subject to
48
- the following conditions:
49
-
50
- The above copyright notice and this permission notice shall be
51
- included in all copies or substantial portions of the Software.
52
-
53
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
54
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
56
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
57
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
58
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
59
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.st
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- # -*- ruby -*-
2
- require 'rubygems'
3
- require 'rake'
4
- require 'echoe'
5
-
6
- Echoe.new('campaign_monitor_subscriber', '0.6.3') do |p|
7
- p.description = "Sync user emails with Campaign Monitor mailing lists"
8
- p.url = "http://github.com/mpowered/campaign_monitor_subscriber"
9
- p.author = "Gary Greyling"
10
- p.email = "gary@mpowered.co.za"
11
- p.ignore_pattern = ["tmp/*", "script/*"]
12
- p.development_dependencies = [['campaigning', '>= 0.15.0']]
13
- end