windbag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2011 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,50 @@
1
+ # Windbag
2
+ ### Notification Engine for Rails 3.1+
3
+
4
+ Windbag is an event notification system for Rails. Using Windbag with model observers, you can notify users about changes they're interested in over a variety of transports (WebSockets, email, SMS, Twitter, etc).
5
+
6
+ At present, the implementation of Transports is left up to you.
7
+
8
+ Windbag consists of Channels, Subscriptions and Notifications. A user subscribes to the Global Channel, his own Private Channel, and any number of other channels belonging to models in your application.
9
+
10
+ A Windbag notification is given a list of transport classes, which are triggered through an ActionMailer-like API upon creation.
11
+
12
+ ## Installation
13
+
14
+ Add windbag to your Gemfile:
15
+
16
+ gem 'windbag'
17
+
18
+ Then run `bundle install`, and migrate up:
19
+
20
+ rake windbag:install:migrations
21
+ rake db:migrate
22
+
23
+ In your **User** model, `include Windbag::UserClass`.
24
+
25
+ ## Users and Channels
26
+
27
+ When a User is created, he is automatically subscribed to two channels; Windbag.global_channel, and a private one created just for him. To sub/unsub other channels:
28
+
29
+ @user.subscribe(foo_channel).unsubscribe(bar_channel)
30
+
31
+ You can query `@user.notifications` for a list of notifications on all subscribed channels.
32
+
33
+ ## Creating Notifications
34
+
35
+ Windbag::Notification.create({
36
+ :event => :rsvp
37
+ :title => 'Someone has RSVP'd to the party!',
38
+ :description => 'I will be there!'
39
+ :url => party_url(party),
40
+ :icon => 'party_hat.png',
41
+ :sticky => false,
42
+ :transports => [ Windbag::Transports::Mailer, Windbag::Transports::SMS, Windbag::Transports::Pusher ],
43
+ :channel => party.windbag_channel
44
+ })
45
+
46
+ When the notification is created, the **deliver** method will be called on each transport class provided.
47
+
48
+ ### TODO
49
+
50
+ * User-selected transport preferences for specific events.
@@ -0,0 +1,31 @@
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 = 'Windbag'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec)
31
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,4 @@
1
+ module Windbag
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Windbag
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module Windbag
2
+ class Channel < ActiveRecord::Base
3
+ has_many :notifications, :class_name => 'Windbag::Notification'
4
+
5
+ belongs_to :owner, :polymorphic => true, :foreign_key => :owner_id
6
+
7
+ has_many :subscriptions, :class_name => 'Windbag::Subscription'
8
+ has_many :subscribers, :through => :subscriptions, :source => :user
9
+
10
+ validates_uniqueness_of :name
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module Windbag
2
+ class Notification < ActiveRecord::Base
3
+
4
+ belongs_to :channel, :class_name => 'Windbag::Channel'
5
+ serialize :transports, Array
6
+
7
+ validates_presence_of :event, :title
8
+
9
+ before_validation :convert_transports
10
+
11
+ after_create :deliver
12
+
13
+ def deliver
14
+ self.transports.each do |transport|
15
+ transport.constantize.with(self.id).deliver
16
+ end
17
+ end
18
+
19
+ def convert_transports
20
+ self.transports = self.transports.map {|t| t.to_s}
21
+ end
22
+
23
+ def channel_name
24
+ self.channel.name if self.channel
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ module Windbag
2
+ class Subscription < ActiveRecord::Base
3
+ belongs_to :user
4
+ belongs_to :channel, :class_name => 'Windbag::Channel'
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Windbag</title>
5
+ <%= stylesheet_link_tag "windbag/application" %>
6
+ <%= javascript_include_tag "windbag/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ Windbag::Engine.routes.draw do
2
+ end
@@ -0,0 +1,18 @@
1
+ class CreateWindbagNotifications < ActiveRecord::Migration
2
+ def change
3
+ create_table :windbag_notifications do |t|
4
+ t.string "event"
5
+ t.string "title"
6
+ t.text "description"
7
+ t.string "url"
8
+ t.string "icon"
9
+ t.boolean "sticky", :default => false
10
+ t.datetime "created_at"
11
+ t.datetime "updated_at"
12
+ t.string "transports"
13
+ t.integer "channel_id"
14
+ end
15
+
16
+ add_index "windbag_notifications", ["channel_id"], :name => "index_windbag_notifications_on_channel_id"
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ class CreateWindbagChannels < ActiveRecord::Migration
2
+ def change
3
+
4
+ create_table :windbag_channels do |t|
5
+ t.string "name"
6
+ t.integer "owner_id"
7
+ t.datetime "created_at"
8
+ t.datetime "updated_at"
9
+ t.string "owner_type"
10
+ end
11
+
12
+ add_index "windbag_channels", ["owner_id", "owner_type"], :name => "index_windbag_channels_on_owner_id_and_owner_type"
13
+
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateWindbagSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :windbag_subscriptions do |t|
4
+ t.integer "user_id"
5
+ t.integer "channel_id"
6
+ t.datetime "created_at"
7
+ t.datetime "updated_at"
8
+ t.timestamps
9
+ end
10
+
11
+ add_index "windbag_subscriptions", ["channel_id"], :name => "windbag_subs_on_chan_id"
12
+ add_index "windbag_subscriptions", ["user_id"], :name => "index_windbag_subscriptions_on_user_id"
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :windbag do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require "windbag/engine"
2
+ require "windbag/user_class"
3
+
4
+ module Windbag
5
+ def self.global_channel
6
+ Channel.find_or_create_by_name('global-notifications')
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Windbag
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Windbag
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :view_specs => false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ module Windbag
2
+ module UserClass
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_one :windbag_channel, :as => :owner, :dependent => :destroy, :class_name => 'Windbag::Channel'
6
+ has_many :windbag_subscriptions, :class_name => 'Windbag::Subscription'
7
+ has_many :windbag_channels, :through => :windbag_subscriptions, :class_name => 'Windbag::Channel', :source => :channel
8
+
9
+ after_create :subscribe_to_global_channel
10
+ after_create :create_private_channel
11
+ end
12
+ end
13
+
14
+ public
15
+ def subscribe(channel)
16
+ Subscription.find_or_create_by_user_id_and_channel_id(self.id, channel.id)
17
+ self
18
+ end
19
+
20
+ def unsubscribe(channel)
21
+ Subscription.destroy_all(:user_id => self.id, :channel_id => channel.id)
22
+ self
23
+ end
24
+
25
+ def notifications
26
+ notifications = []
27
+ windbag_channels.each do |channel|
28
+ notifications << channel.notifications
29
+ end
30
+ notifications.flatten
31
+ end
32
+
33
+ protected
34
+ def subscribe_to_global_channel
35
+ subscribe Windbag.global_channel
36
+ end
37
+
38
+ def create_private_channel
39
+ self.windbag_channel = Channel.find_or_create_by_name(
40
+ "private-user-#{self.id}-notifications"
41
+ )
42
+ subscribe self.windbag_channel
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Windbag
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: windbag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Logan Koester
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &14877840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14877840
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &14876240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *14876240
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &14875280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *14875280
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda-matchers
49
+ requirement: &14872340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *14872340
58
+ - !ruby/object:Gem::Dependency
59
+ name: factory_girl_rails
60
+ requirement: &14906820 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *14906820
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: &14905200 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *14905200
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard
82
+ requirement: &14904360 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *14904360
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-rspec
93
+ requirement: &14903740 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *14903740
102
+ description: Windbag is the event notification system extracted from MLG Starcraft
103
+ Arena
104
+ email:
105
+ - lkoester@majorleaguegaming.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - app/controllers/windbag/application_controller.rb
111
+ - app/helpers/windbag/application_helper.rb
112
+ - app/models/windbag/subscription.rb
113
+ - app/models/windbag/notification.rb
114
+ - app/models/windbag/channel.rb
115
+ - app/assets/stylesheets/windbag/application.css
116
+ - app/assets/javascripts/windbag/application.js
117
+ - app/views/layouts/windbag/application.html.erb
118
+ - config/routes.rb
119
+ - db/migrate/20111230191630_create_windbag_channels.rb
120
+ - db/migrate/20111230191249_create_windbag_notifications.rb
121
+ - db/migrate/20111230191822_create_windbag_subscriptions.rb
122
+ - lib/windbag/engine.rb
123
+ - lib/windbag/version.rb
124
+ - lib/windbag/user_class.rb
125
+ - lib/tasks/windbag_tasks.rake
126
+ - lib/windbag.rb
127
+ - MIT-LICENSE
128
+ - Rakefile
129
+ - README.markdown
130
+ homepage: http://github.com/agoragames/windbag
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 2181554666769158353
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: 2181554666769158353
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.10
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Notification System for Rails 3.1+
160
+ test_files: []