catarse_mailchimp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/**/*
@@ -0,0 +1,3 @@
1
+ [submodule "test/dummy"]
2
+ path = test/dummy
3
+ url = git://github.com/danielweinmann/catarse.git
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
+ catarse_mailchimp (0.0.1)
5
+ mailchimp
6
+ supermodel
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activemodel (3.0.3)
12
+ activesupport (= 3.0.3)
13
+ builder (~> 2.1.2)
14
+ i18n (~> 0.4)
15
+ activesupport (3.0.3)
16
+ builder (2.1.2)
17
+ diff-lcs (1.1.3)
18
+ httparty (0.8.1)
19
+ multi_json
20
+ multi_xml
21
+ i18n (0.6.0)
22
+ mailchimp (0.0.7.alpha)
23
+ httparty
24
+ metaclass (0.0.1)
25
+ mocha (0.11.4)
26
+ metaclass (~> 0.0.1)
27
+ multi_json (1.3.6)
28
+ multi_xml (0.4.1)
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
+ 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,52 @@
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'
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
23
+
24
+ ...
25
+ end
26
+
27
+ ### Configurations
28
+
29
+ Create this configurations into Catarse database:
30
+
31
+ mailchimp_api_key, mailchimp_list_id
32
+
33
+ In Rails console, run this:
34
+
35
+ Configuration.create!(name: "mailchimp_api_key", value: "API_KEY")
36
+ Configuration.create!(name: "mailchimp_list_id", value: "LIST_ID")
37
+
38
+ Create a mailchimp configuration file on config/initilazers/mailchimp.rb and add:
39
+
40
+ MAILCHIMP_API_KEY = Configuration[:mailchimp_api_key]
41
+ MAILCHIMP_LIST_ID = Configuration[:mailchimp_list_id]
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
50
+
51
+
52
+ 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 = "catarse_mailchimp"
10
+ s.version = CatarseMailchimp::VERSION
11
+ s.authors = ["Antônio Roberto Silva"]
12
+ s.email = ["forevertonny@gmail.com"]
13
+ s.homepage = "http://github.com/devton/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,2 @@
1
+ CatarseMailchimp::Engine.routes.draw do
2
+ 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,21 @@
1
+ module CatarseMailchimp
2
+ module ActiveRecord
3
+ # USAGE
4
+ #
5
+ # # Simple example
6
+ # class User < ActiveRecord::Base
7
+ # sync_with_mailchimp
8
+ # end
9
+ def sync_with_mailchimp
10
+ self.class_eval <<-RUBY
11
+ after_save do
12
+ if newsletter
13
+ CatarseMailchimp::API.subscribe(self)
14
+ else
15
+ CatarseMailchimp::API.unsubscribe(self)
16
+ end
17
+ end
18
+ RUBY
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module CatarseMailchimp
2
+ module API
3
+ extend self
4
+
5
+ def subscribe(user, list_id = MAILCHIMP_LIST_ID)
6
+ subscribe_params = {
7
+ id: list_id.to_s,
8
+ batch: [ { :EMAIL => user.email } ]
9
+ }
10
+
11
+ mailchimp_api.list_batch_subscribe(subscribe_params)
12
+ end
13
+
14
+ def unsubscribe(user, list_id = MAILCHIMP_LIST_ID)
15
+ unsubscribe_params = {
16
+ id: list_id.to_s,
17
+ emails: [ user.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"
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,27 @@
1
+ require 'spec_helper'
2
+
3
+ class User < SuperModel::Base
4
+ extend CatarseMailchimp::ActiveRecord
5
+
6
+ sync_with_mailchimp
7
+ end
8
+
9
+ describe CatarseMailchimp::ActiveRecord do
10
+ let(:user) { User.new(email: 'lorem@lorem.com', newsletter: false) }
11
+
12
+ context 'when user not want to receive news' do
13
+ it 'should call unsubscribe api' do
14
+ CatarseMailchimp::API.expects(:unsubscribe).with(user)
15
+ end
16
+ end
17
+ context 'when user want to receive news' do
18
+ it 'should call subcribe api' do
19
+ user.newsletter = true
20
+ CatarseMailchimp::API.expects(:subscribe).with(user)
21
+ end
22
+ end
23
+
24
+ after(:each) do
25
+ user.save
26
+ end
27
+ end
@@ -0,0 +1,31 @@
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
+ subject do
13
+ user = mock()
14
+ user.stubs(:email).returns('lorem@lorem.com')
15
+ user
16
+ end
17
+
18
+ context 'Subscribe' do
19
+ it 'when user want to receive a newsletter, should update on mailchimp list' do
20
+ instance = CatarseMailchimp::API.subscribe(subject, 'LISTID')
21
+ instance.should == 'list_batch_subscribe'
22
+ end
23
+ end
24
+
25
+ context 'Unsubscribe' do
26
+ it 'when user want to not receive a newsletter, should update on mailchimp list' do
27
+ instance = CatarseMailchimp::API.unsubscribe(subject, 'LISTID')
28
+ instance.should == 'list_batch_unsubscribe'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'catarse_mailchimp'
2
+ require 'supermodel'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :mocha
6
+ end
7
+
8
+ MAILCHIMP_LIST_ID = '123'
9
+ MAILCHIMP_API_KEY = '123'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catarse_mailchimp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Antônio Roberto Silva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mailchimp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: supermodel
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: MailChimp integration with Catarse crowdfunding platform
79
+ email:
80
+ - forevertonny@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .gitmodules
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - MIT-LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - catarse_mailchimp.gemspec
93
+ - config/routes.rb
94
+ - lib/catarse_mailchimp.rb
95
+ - lib/catarse_mailchimp/active_record.rb
96
+ - lib/catarse_mailchimp/api.rb
97
+ - lib/catarse_mailchimp/railtie.rb
98
+ - lib/catarse_mailchimp/version.rb
99
+ - script/rails
100
+ - spec/catarse_mailchimp_spec.rb
101
+ - spec/lib/catarse_mailchimp/api_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: http://github.com/devton/catarse_mailchimp
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.21
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: MailChimp integration with Catarse
127
+ test_files: []