courier 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format d
data/.watchr ADDED
@@ -0,0 +1,99 @@
1
+
2
+ # https://github.com/rspec/rspec-rails/blob/master/specs.watchr
3
+
4
+ # Other examples:
5
+ # https://gist.github.com/298168
6
+
7
+ # --------------------------------------------------
8
+ # Convenience Methods
9
+ # --------------------------------------------------
10
+
11
+ def all_spec_files
12
+ 'spec/**/*_spec.rb'
13
+ end
14
+
15
+ def run_spec_matching(thing_to_match)
16
+ puts "Matching #{thing_to_match}"
17
+ matches = Dir[all_spec_files].grep(/#{thing_to_match}_spec/i)
18
+ if matches.empty?
19
+ puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
20
+ else
21
+ run matches.join(' ')
22
+ end
23
+ end
24
+
25
+ def run(files_to_run)
26
+ puts "Running #{files_to_run}"
27
+ system "bundle exec rspec -d #{files_to_run}"
28
+ no_int_for_you
29
+ notify
30
+ puts
31
+ end
32
+
33
+ def notify message=''
34
+ # message = message.split('---------------------------------------------------------------')[3].split('Time taken by tests')[0]
35
+ # image = message.include?('fails') ? "~/.watchr_images/failed.png" : "~/.watchr_images/passed.png"
36
+
37
+ # Grub images from autotest-growl
38
+ image = $?.success? ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
39
+ message = $?.success? ? "success" : "failed"
40
+
41
+ options = "-i #{File.expand_path(image)} "
42
+ options += '-u critical -t 10000 ' unless $?.success?
43
+
44
+ notify_send = `which notify-send`.chomp
45
+ cmd = "#{notify_send} #{options} 'Watchr Test Results: #{message}'"
46
+ system cmd
47
+ end
48
+
49
+ def run_all_specs
50
+ run('spec/') #all_spec_files
51
+ end
52
+
53
+
54
+ # def run_suite
55
+ # system "clear"
56
+ # run_spec('spec/*/*_spec.rb spec/*/*/*_spec.rb')
57
+ # end
58
+
59
+
60
+
61
+ # --------------------------------------------------
62
+ # Watchr Rules
63
+ # --------------------------------------------------
64
+ watch('^app/(.*)\.(.*)') { |m| run_spec_matching(m[1]) }
65
+ watch('^lib\/(.*)\.rb') { |m| run_spec_matching(m[1]) }
66
+ watch('^spec\/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
67
+ watch('^spec\/factories/(.*)_factory\.rb') { |m| run_spec_matching(m[1]) }
68
+ watch('^spec/spec_helper\.rb') { run_all_specs }
69
+ watch('^spec/support/.*\.rb') { run_all_specs }
70
+
71
+ # --------------------------------------------------
72
+ # Signal Handling
73
+ # --------------------------------------------------
74
+
75
+ def no_int_for_you
76
+ @sent_an_int = nil
77
+ end
78
+
79
+ # Ctrl-C
80
+ Signal.trap 'INT' do
81
+ if @sent_an_int then
82
+ puts " A second INT? Ok, I get the message. Shutting down now."
83
+ exit
84
+ else
85
+ puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
86
+ @sent_an_int = true
87
+ Kernel.sleep 1.5
88
+ run_all_specs
89
+ end
90
+ end
91
+
92
+
93
+ # Ctrl-\
94
+ Signal.trap 'QUIT' do
95
+ puts " --- Running all tests ---\n\n"
96
+ run_suite
97
+ end
98
+
99
+ puts "Watching.."
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'activerecord', "~> 3.0"
4
+ gem 'actionpack', "~> 3.0"
5
+ gem 'state_machine', "~> 0.10.2"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development, :test do
10
+ gem 'pg'
11
+ gem "ruby-debug"
12
+ gem "watchr"
13
+ gem "sqlite3"
14
+ gem "factory_girl"
15
+ gem "shoulda", ">= 0"
16
+ gem "rspec", "~> 2.5"
17
+ gem "rspec-rails"
18
+ gem "bundler", "~> 1.0.0"
19
+ gem "jeweler", "~> 1.5.2"
20
+ gem "rcov", ">= 0"
21
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Danil Pismenny
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,98 @@
1
+ = Courier
2
+
3
+ Давным давно, в одной далекой-предалекой галактике, был такой модем USR Courier,
4
+ он хорошо держал карриер и был мечтой каждого фидошника. А сейчас чтобы получать
5
+ много не нужных писем достаточно зарегистрироваться на еще одной социальной
6
+ сети.
7
+
8
+ Чтобы помочь социальной сети справиться с большим количеством видов подписок и
9
+ оповещений, а пользователю настроить способы их доставки мы разработали плагин
10
+ Courier. Courier On Rails.
11
+
12
+ Courier - Система управления пользовательскими оповещениями и подписоками.
13
+
14
+ == Установка
15
+
16
+ Gemfile:
17
+
18
+ gem 'courier'
19
+
20
+ Создание миграции и конфигцарции <tt>./config/initializers/courier.rb</tt>
21
+
22
+ rails g courier
23
+
24
+ rake db:migrate
25
+
26
+ В <tt>config/initializers/courier.rb</tt> регистрируем используемые сервисы, шаблоны и их значения по умолчанию:
27
+
28
+ Courier.init do |d|
29
+ d.services :active_mailer, :gritter_notice, :facebook
30
+ d.template :import_complete, :off, :on, :off
31
+ d.template :avatar_loaded, :on, :off, :on
32
+ d.template :weekly_subscription, :on, :on, :on
33
+ end
34
+
35
+ В модели пользователя:
36
+
37
+ class User << ActiveRecord::Base
38
+ has_courier
39
+ ...
40
+
41
+ == Использование
42
+
43
+ Посылаем пользователю сообщение по шаблону <tt>:import_complete<tt> во все разрешенные сервисы
44
+
45
+ user.message :import_complete, {:some=>'arguments in hash'}
46
+
47
+ Если сервис отправляет сообщение в реальном времени, то он его уже
48
+ отправил, а если сообщения собираются для дальнейшей отправки, то
49
+ осуществляется эта доставка так:
50
+
51
+ Courier.deliver_all!
52
+
53
+ == Сервисы
54
+
55
+ На данный момент реализованы сервисы:
56
+
57
+ * Courier::Service::GritterNotice - отправка сообщений через gritter_notices[http://github.com/dapi/gritter_notices]
58
+ * Courier::Service::ActionMailer - TODO
59
+ * Courier::Service::MailChimp - TODO
60
+ * Courier::Service::Facebook - Использует Koala[https://github.com/arsduo/koala]
61
+
62
+ == Свой сервис
63
+
64
+ Все сервисы наследуютсяо от <tt>Courier::Service::Base</tt>. Последнее
65
+ имя класс автоматически становится именем этого сервиса через
66
+ <tt>demodulize.underscore</tt>. Всего нужно имплементировать 2 метода:
67
+
68
+ * message(owner, template, args)
69
+ * deliver!
70
+
71
+ === Сервис отложенной отправки
72
+
73
+ Достаточно реализовать метод <tt>deliver!</tt>, так как +message+ удачно складывает все сообщения в базу. Например:
74
+
75
+ def deliver!
76
+ courier_messages.fresh.each do |message|
77
+ send_message_my_way message.owner, message.text
78
+ end
79
+ end
80
+
81
+ === Сервис отправки в реальном времени
82
+
83
+ Достаточно реализоват метод +message+. Например:
84
+
85
+ def message(owner, template, args)
86
+ send_message_my_way owner, template.get_text(args)
87
+ end
88
+
89
+
90
+
91
+ == Contributing to courier
92
+
93
+ * Yes, please.
94
+
95
+ == Copyright
96
+
97
+ Copyright (c) 2011 Danil Pismenny.
98
+
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "courier"
17
+ gem.homepage = "http://github.com/dapi/courier"
18
+ gem.license = "MIT"
19
+ gem.summary = "Система управления пользовательскими оповещениями и подписками"
20
+ gem.description = 'Система управления пользовательскими оповещениями и подписками'
21
+ gem.email = "danil@orionet.ru"
22
+ gem.authors = ["Danil Pismenny"]
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "courier #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,135 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{courier}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Danil Pismenny"]
12
+ s.date = %q{2011-04-02}
13
+ s.description = %q{Система управления пользовательскими оповещениями и подписками}
14
+ s.email = %q{danil@orionet.ru}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".watchr",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "courier.gemspec",
29
+ "lib/courier.rb",
30
+ "lib/courier/config.rb",
31
+ "lib/courier/engine.rb",
32
+ "lib/courier/message.rb",
33
+ "lib/courier/owner.rb",
34
+ "lib/courier/owner_setting.rb",
35
+ "lib/courier/service/active_mailer.rb",
36
+ "lib/courier/service/base.rb",
37
+ "lib/courier/service/facebook.rb",
38
+ "lib/courier/service/gritter_notice.rb",
39
+ "lib/courier/template/base.rb",
40
+ "lib/generators/courier_generator.rb",
41
+ "lib/generators/templates/courier.rb",
42
+ "lib/generators/templates/migration.rb",
43
+ "spec/courier/config_spec.rb",
44
+ "spec/courier/message_spec.rb",
45
+ "spec/courier/owner_setting_spec.rb",
46
+ "spec/courier/owner_spec.rb",
47
+ "spec/courier/service/base_spec.rb",
48
+ "spec/courier/service/facebook_spec.rb",
49
+ "spec/courier/service/gritter_notice_spec.rb",
50
+ "spec/courier/template/base_spec.rb",
51
+ "spec/courier_spec.rb",
52
+ "spec/examples/example1_spec.rb",
53
+ "spec/spec_helper.rb",
54
+ "spec/support/factories.rb",
55
+ "spec/support/gems_simulation.rb",
56
+ "spec/support/migration.rb",
57
+ "spec/support/mocks.rb",
58
+ "spec/support/user.rb"
59
+ ]
60
+ s.homepage = %q{http://github.com/dapi/courier}
61
+ s.licenses = ["MIT"]
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = %q{1.5.0}
64
+ s.summary = %q{Система управления пользовательскими оповещениями и подписками}
65
+ s.test_files = [
66
+ "spec/courier/config_spec.rb",
67
+ "spec/courier/message_spec.rb",
68
+ "spec/courier/owner_setting_spec.rb",
69
+ "spec/courier/owner_spec.rb",
70
+ "spec/courier/service/base_spec.rb",
71
+ "spec/courier/service/facebook_spec.rb",
72
+ "spec/courier/service/gritter_notice_spec.rb",
73
+ "spec/courier/template/base_spec.rb",
74
+ "spec/courier_spec.rb",
75
+ "spec/examples/example1_spec.rb",
76
+ "spec/spec_helper.rb",
77
+ "spec/support/factories.rb",
78
+ "spec/support/gems_simulation.rb",
79
+ "spec/support/migration.rb",
80
+ "spec/support/mocks.rb",
81
+ "spec/support/user.rb"
82
+ ]
83
+
84
+ if s.respond_to? :specification_version then
85
+ s.specification_version = 3
86
+
87
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
88
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.0"])
89
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0"])
90
+ s.add_runtime_dependency(%q<state_machine>, ["~> 0.10.2"])
91
+ s.add_development_dependency(%q<pg>, [">= 0"])
92
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
93
+ s.add_development_dependency(%q<watchr>, [">= 0"])
94
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
95
+ s.add_development_dependency(%q<factory_girl>, [">= 0"])
96
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
97
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
98
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
99
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
100
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
101
+ s.add_development_dependency(%q<rcov>, [">= 0"])
102
+ else
103
+ s.add_dependency(%q<activerecord>, ["~> 3.0"])
104
+ s.add_dependency(%q<actionpack>, ["~> 3.0"])
105
+ s.add_dependency(%q<state_machine>, ["~> 0.10.2"])
106
+ s.add_dependency(%q<pg>, [">= 0"])
107
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
108
+ s.add_dependency(%q<watchr>, [">= 0"])
109
+ s.add_dependency(%q<sqlite3>, [">= 0"])
110
+ s.add_dependency(%q<factory_girl>, [">= 0"])
111
+ s.add_dependency(%q<shoulda>, [">= 0"])
112
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
113
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
114
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
115
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
116
+ s.add_dependency(%q<rcov>, [">= 0"])
117
+ end
118
+ else
119
+ s.add_dependency(%q<activerecord>, ["~> 3.0"])
120
+ s.add_dependency(%q<actionpack>, ["~> 3.0"])
121
+ s.add_dependency(%q<state_machine>, ["~> 0.10.2"])
122
+ s.add_dependency(%q<pg>, [">= 0"])
123
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
124
+ s.add_dependency(%q<watchr>, [">= 0"])
125
+ s.add_dependency(%q<sqlite3>, [">= 0"])
126
+ s.add_dependency(%q<factory_girl>, [">= 0"])
127
+ s.add_dependency(%q<shoulda>, [">= 0"])
128
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
129
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
130
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
131
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
132
+ s.add_dependency(%q<rcov>, [">= 0"])
133
+ end
134
+ end
135
+
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Courier
3
+ require 'courier/owner_setting'
4
+ require 'courier/config'
5
+ module Service
6
+ require 'courier/service/base'
7
+ Dir["#{File.dirname(__FILE__)}/courier/service/**/*.rb"].each {|f| require f}
8
+ end
9
+ module Template
10
+ require 'courier/template/base'
11
+ end
12
+
13
+ class << self
14
+ cattr_accessor :config
15
+
16
+ def init
17
+ yield self.config = Courier::Config.new
18
+ end
19
+
20
+ def deliver_all!
21
+ config.services.each do |service|
22
+ service.deliver!
23
+ end
24
+ end
25
+
26
+ def template(name)
27
+ config.get_template(name)
28
+ end
29
+
30
+ def service(name)
31
+ config.get_service(name)
32
+ end
33
+ end
34
+ end
35
+
36
+ require 'courier/message'
37
+
38
+ require 'courier/owner'
39
+ ActiveRecord::Base.send(:extend, Courier::Owner )
40
+
41
+ #require 'gritter_notices/view_helpers' ActionView::Base.send(:include, GritterNotices::ViewHelpers )
42
+ # require 'gritter_notices/rspec_matcher'
43
+
44
+ require 'courier/engine' if defined?(Rails)
45
+
46
+