marnen-catarse_mailchimp 0.0.1.pre.2ed4f3931dfa292e5c1c62619772f04e41c68629z

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bae638129c3dd6ff742fe1dcd94dfc2619a52df8
4
+ data.tar.gz: 501149faa7ed346a4a931a99aa1f093f30e921cb
5
+ SHA512:
6
+ metadata.gz: 3d96560dacca8d69b09914a0a5cfe960436493f69d5859d32947ea49def0cffb595a4b973f71c8fb1aa3e17e5ac0e86b72c01a69b8c3f31d5e15696d391707cb
7
+ data.tar.gz: d31e6ad3951b2174a342e4c250ede1c806996a8c1cbf6da1d304d1a3e198cdff326fdc5c6db6848a5abf4760652e6c24939f1b954f8f0f22e97c4b3c66428053
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
8
+ test/dummy
9
+ test/dummy/
10
+ test/dummy/**/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in catarse_mailchimp.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ marnen-catarse_mailchimp (0.0.1.pre.2ed4f3931dfa292e5c1c62619772f04e41c68629z)
5
+ mailchimp
6
+ supermodel
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activemodel (3.0.20)
12
+ activesupport (= 3.0.20)
13
+ builder (~> 2.1.2)
14
+ i18n (~> 0.5.0)
15
+ activesupport (3.0.20)
16
+ builder (2.1.2)
17
+ diff-lcs (1.1.3)
18
+ httparty (0.13.1)
19
+ json (~> 1.8)
20
+ multi_xml (>= 0.5.2)
21
+ i18n (0.5.4)
22
+ json (1.8.1)
23
+ mailchimp (0.0.9)
24
+ httparty
25
+ metaclass (0.0.1)
26
+ mocha (0.11.4)
27
+ metaclass (~> 0.0.1)
28
+ multi_xml (0.5.5)
29
+ rspec (2.10.0)
30
+ rspec-core (~> 2.10.0)
31
+ rspec-expectations (~> 2.10.0)
32
+ rspec-mocks (~> 2.10.0)
33
+ rspec-core (2.10.1)
34
+ rspec-expectations (2.10.0)
35
+ diff-lcs (~> 1.1.3)
36
+ rspec-mocks (2.10.1)
37
+ supermodel (0.1.6)
38
+ activemodel (~> 3.0.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ marnen-catarse_mailchimp!
45
+ mocha
46
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # CatarseMailchimp
2
+
3
+ Catarse mailchimp integration with [Catarse](http://github.com/danielweinmann/catarse) crowdfunding platform
4
+
5
+ ## Instalation
6
+
7
+ Add this lines to your Catarse application's Gemfile:
8
+
9
+ gem 'catarse_mailchimp', git: 'git://github.com/catarse/catarse_mailchimp.git', branch: 'master'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Add on user model app/models/user.br
18
+
19
+ class User < ActiveRecord::Base
20
+ ...
21
+
22
+ sync_with_mailchimp subscribe_data: ->(user) { { EMAIL: user.email, NAME: user.name } },
23
+ list_id: 'listID',
24
+ subscribe_when: ->(user) { user.newsletter_changed? && user.newsletter },
25
+ unsubscribe_when: ->(user) { user.newsletter_changed? && !user.newsletter },
26
+ ubsubscribe_email: ->(user) { user.email }
27
+
28
+ ...
29
+ end
30
+
31
+ ### Configurations
32
+
33
+ Create this configurations into Catarse database:
34
+
35
+ mailchimp_api_key, mailchimp_list_id
36
+
37
+ In Rails console, run this:
38
+
39
+ Configuration.create!(name: "mailchimp_api_key", value: "API_KEY")
40
+ Configuration.create!(name: "mailchimp_list_id", value: "LIST_ID")
41
+
42
+ Create a mailchimp configuration file on config/initilazers/mailchimp.rb and add:
43
+
44
+ MAILCHIMP_API_KEY = Configuration[:mailchimp_api_key]
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
53
+
54
+
55
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CatarseMailchimp'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,24 @@
1
+ #encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ # Maintain your gem's version:
5
+ require "catarse_mailchimp/version"
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |s|
9
+ s.name = "marnen-catarse_mailchimp"
10
+ s.version = CatarseMailchimp::VERSION
11
+ s.authors = ["Antônio Roberto Silva", 'Marnen Laibow-Koser']
12
+ s.email = ["forevertonny@gmail.com", 'marnen@marnen.org']
13
+ s.homepage = "http://github.com/marnen/catarse_mailchimp"
14
+ s.summary = "MailChimp integration with Catarse"
15
+ s.description = "MailChimp integration with Catarse crowdfunding platform"
16
+
17
+ s.files = `git ls-files`.split($\)
18
+
19
+ s.add_dependency "mailchimp"
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "mocha"
23
+ s.add_runtime_dependency "supermodel"
24
+ end
@@ -0,0 +1,8 @@
1
+ require "catarse_mailchimp/api"
2
+ require "catarse_mailchimp/active_record"
3
+ require "catarse_mailchimp/railtie" if defined? Rails
4
+
5
+ require 'mailchimp'
6
+
7
+ module CatarseMailchimp
8
+ end
@@ -0,0 +1,30 @@
1
+ module CatarseMailchimp
2
+ module ActiveRecord
3
+ # USAGE
4
+ #
5
+ # class User < ActiveRecord::Base
6
+ # sync_with_mailchimp subscribe_data: ->(user) { { EMAIL: user.email, NAME: user.name } },
7
+ # list_id: 'listID',
8
+ # subscribe_when: ->(user) { user.newsletter_changed? && user.newsletter },
9
+ # unsubscribe_when: ->(user) { user.newsletter_changed? && !user.newsletter },
10
+ # ubsubscribe_email: ->(user) { user.email }
11
+ #
12
+ # end
13
+ #
14
+ def sync_with_mailchimp options
15
+ self.class_eval <<-RUBY
16
+ before_save do
17
+
18
+ if options[:subscribe_when].call(self)
19
+ CatarseMailchimp::API.subscribe(options[:subscribe_data].call(self), options[:list_id])
20
+ end
21
+
22
+ if options[:unsubscribe_when].call(self)
23
+ CatarseMailchimp::API.unsubscribe(options[:unsubscribe_email].call(self), options[:list_id])
24
+ end
25
+
26
+ end
27
+ RUBY
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ module CatarseMailchimp
2
+ module API
3
+ extend self
4
+
5
+ def subscribe(hash, list_id)
6
+ subscribe_params = {
7
+ id: list_id.to_s,
8
+ batch: [ hash ]
9
+ }
10
+
11
+ mailchimp_api.list_batch_subscribe(subscribe_params)
12
+ end
13
+
14
+ def unsubscribe(email, list_id)
15
+ unsubscribe_params = {
16
+ id: list_id.to_s,
17
+ emails: [email],
18
+ delete_member: true,
19
+ send_goodbye: true
20
+ }
21
+
22
+ mailchimp_api.list_batch_unsubscribe(unsubscribe_params)
23
+ end
24
+
25
+ protected
26
+
27
+ def mailchimp_api
28
+ Mailchimp::API.new(MAILCHIMP_API_KEY)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ module CatarseMailchimp
2
+ class Railtie < Rails::Railtie
3
+ initializer 'catarse_mailchimp.active_record' do
4
+ ActiveSupport.on_load :active_record do
5
+ extend ::CatarseMailchimp::ActiveRecord
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CatarseMailchimp
2
+ VERSION = "0.0.1-2ed4f3931dfa292e5c1c62619772f04e41c68629z"
3
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/catarse_mailchimp/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ class User < SuperModel::Base
4
+ extend CatarseMailchimp::ActiveRecord
5
+
6
+ sync_with_mailchimp subscribe_data: ->(user) { { EMAIL: user.email, NAME: user.name } },
7
+ list_id: 'listID',
8
+ subscribe_when: ->(user) { user.newsletter_changed? && user.newsletter },
9
+ unsubscribe_when: ->(user) { user.newsletter_changed? && !user.newsletter },
10
+ ubsubscribe_email: ->(user) { user.email }
11
+ end
12
+
13
+ describe CatarseMailchimp::ActiveRecord do
14
+ context 'when user not want to receive news' do
15
+ let(:user) { User.create(email: 'lorem@lorem.com', name: 'fuu', newsletter: false) }
16
+
17
+ before do
18
+ user.stubs(:newsletter_changed?).returns(true)
19
+ CatarseMailchimp::API.expects(:unsubscribe).with(user.email, 'listID')
20
+ end
21
+
22
+ it 'should satisfy expectations' do
23
+ user.save
24
+ end
25
+ end
26
+
27
+ context 'when user want to receive news' do
28
+ let(:user) { User.create(email: 'lorem@lorem.com', name: 'fuu', newsletter: true) }
29
+
30
+ before do
31
+ user.stubs(:newsletter_changed?).returns(true)
32
+ CatarseMailchimp::API.expects(:subscribe).with({ EMAIL: user.email, NAME: user.name }, 'listID')
33
+ end
34
+
35
+ it 'should satisfy expectations' do
36
+ user.save
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe CatarseMailchimp::API do
4
+ before do
5
+ fake_mailchimp = mock();
6
+ fake_mailchimp.stubs(:list_batch_subscribe).returns('list_batch_subscribe')
7
+ fake_mailchimp.stubs(:list_batch_unsubscribe).returns('list_batch_unsubscribe')
8
+
9
+ Mailchimp::API.stubs(:new).returns(fake_mailchimp)
10
+ end
11
+
12
+ let(:user) {
13
+ user = mock()
14
+ user.stubs(:email).returns('lorem@lorem.com')
15
+ user.stubs(:name).returns('Foo bar')
16
+ user
17
+ }
18
+
19
+ subject do
20
+ { EMAIL: user.email, NAME: user.name }
21
+ end
22
+
23
+ context '.subscribe' do
24
+ it 'when user want to receive a newsletter, should update on mailchimp list' do
25
+ instance = CatarseMailchimp::API.subscribe(subject, 'LISTID')
26
+ instance.should == 'list_batch_subscribe'
27
+ end
28
+ end
29
+
30
+ context '.unsubscribe' do
31
+ subject do
32
+ user = mock()
33
+ user.stubs(:email).returns('lorem@lorem.com')
34
+ user
35
+
36
+ [ user.email ]
37
+ end
38
+
39
+ it 'when user want to not receive a newsletter, should update on mailchimp list' do
40
+ instance = CatarseMailchimp::API.unsubscribe(subject, 'LISTID')
41
+ instance.should == 'list_batch_unsubscribe'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,8 @@
1
+ require 'catarse_mailchimp'
2
+ require 'supermodel'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :mocha
6
+ end
7
+
8
+ MAILCHIMP_API_KEY = '123'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marnen-catarse_mailchimp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.2ed4f3931dfa292e5c1c62619772f04e41c68629z
5
+ platform: ruby
6
+ authors:
7
+ - Antônio Roberto Silva
8
+ - Marnen Laibow-Koser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mailchimp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mocha
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: supermodel
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: MailChimp integration with Catarse crowdfunding platform
71
+ email:
72
+ - forevertonny@gmail.com
73
+ - marnen@marnen.org
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - MIT-LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - catarse_mailchimp.gemspec
85
+ - lib/catarse_mailchimp.rb
86
+ - lib/catarse_mailchimp/active_record.rb
87
+ - lib/catarse_mailchimp/api.rb
88
+ - lib/catarse_mailchimp/railtie.rb
89
+ - lib/catarse_mailchimp/version.rb
90
+ - script/rails
91
+ - spec/catarse_mailchimp_spec.rb
92
+ - spec/lib/catarse_mailchimp/api_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: http://github.com/marnen/catarse_mailchimp
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>'
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.1
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.1.11
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: MailChimp integration with Catarse
117
+ test_files: []