silvermoon 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/.gitignore +8 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +159 -0
  5. data/Guardfile +21 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +83 -0
  8. data/Rakefile +27 -0
  9. data/lib/generators/silvermoon/install/install_generator.rb +16 -0
  10. data/lib/generators/silvermoon/install/templates/silvermoon.yml +17 -0
  11. data/lib/silvermoon.rb +54 -0
  12. data/lib/silvermoon/action_controller_extension.rb +22 -0
  13. data/lib/silvermoon/notifier.rb +18 -0
  14. data/lib/silvermoon/notifier/base.rb +19 -0
  15. data/lib/silvermoon/notifier/facebook.rb +35 -0
  16. data/lib/silvermoon/notifier/twitter.rb +27 -0
  17. data/lib/silvermoon/railtie.rb +11 -0
  18. data/lib/silvermoon/version.rb +3 -0
  19. data/silvermoon.gemspec +21 -0
  20. data/spec/dummy/Rakefile +7 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  22. data/spec/dummy/app/controllers/notifications_controller.rb +86 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/helpers/notifications_helper.rb +2 -0
  25. data/spec/dummy/app/models/notification.rb +2 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/app/views/notifications/_form.html.erb +29 -0
  28. data/spec/dummy/app/views/notifications/edit.html.erb +6 -0
  29. data/spec/dummy/app/views/notifications/index.html.erb +27 -0
  30. data/spec/dummy/app/views/notifications/new.html.erb +5 -0
  31. data/spec/dummy/app/views/notifications/show.html.erb +20 -0
  32. data/spec/dummy/config.ru +4 -0
  33. data/spec/dummy/config/application.rb +45 -0
  34. data/spec/dummy/config/boot.rb +10 -0
  35. data/spec/dummy/config/database.yml +22 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +26 -0
  38. data/spec/dummy/config/environments/production.rb +49 -0
  39. data/spec/dummy/config/environments/test.rb +35 -0
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/dummy/config/initializers/inflections.rb +10 -0
  42. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  43. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  44. data/spec/dummy/config/initializers/session_store.rb +8 -0
  45. data/spec/dummy/config/locales/en.yml +5 -0
  46. data/spec/dummy/config/routes.rb +60 -0
  47. data/spec/dummy/config/silvermoon.yml +12 -0
  48. data/spec/dummy/db/migrate/20110906125229_create_notifications.rb +15 -0
  49. data/spec/dummy/db/schema.rb +23 -0
  50. data/spec/dummy/public/404.html +26 -0
  51. data/spec/dummy/public/422.html +26 -0
  52. data/spec/dummy/public/500.html +26 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/public/javascripts/application.js +2 -0
  55. data/spec/dummy/public/javascripts/controls.js +965 -0
  56. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  57. data/spec/dummy/public/javascripts/effects.js +1123 -0
  58. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  59. data/spec/dummy/public/javascripts/rails.js +191 -0
  60. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  61. data/spec/dummy/public/stylesheets/scaffold.css +56 -0
  62. data/spec/dummy/script/rails +6 -0
  63. data/spec/integration/navigation_spec.rb +9 -0
  64. data/spec/silvermoon/action_controller_extension_spec.rb +45 -0
  65. data/spec/silvermoon/notifier/base_spec.rb +18 -0
  66. data/spec/silvermoon/notifier_spec.rb +20 -0
  67. data/spec/silvermoon_spec.rb +45 -0
  68. data/spec/spec_helper.rb +34 -0
  69. data/spec/support/config_helpers.rb +13 -0
  70. data/spec/support/stubs.rb +15 -0
  71. metadata +186 -0
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ *.swp
8
+ *.swo
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.8.7@silvermoon --create
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "3.0.10"
6
+ gem "capybara", ">= 0.4.0"
7
+ gem "sqlite3"
8
+
9
+ gem "rspec-rails", ">= 2.0.0.beta"
10
+ gem 'guard-rails'
11
+ gem 'ruby-debug'
12
+
13
+ gem 'twitter'
14
+ gem 'koala'
@@ -0,0 +1,159 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ silvermoon (0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ abstract (1.0.0)
10
+ actionmailer (3.0.10)
11
+ actionpack (= 3.0.10)
12
+ mail (~> 2.2.19)
13
+ actionpack (3.0.10)
14
+ activemodel (= 3.0.10)
15
+ activesupport (= 3.0.10)
16
+ builder (~> 2.1.2)
17
+ erubis (~> 2.6.6)
18
+ i18n (~> 0.5.0)
19
+ rack (~> 1.2.1)
20
+ rack-mount (~> 0.6.14)
21
+ rack-test (~> 0.5.7)
22
+ tzinfo (~> 0.3.23)
23
+ activemodel (3.0.10)
24
+ activesupport (= 3.0.10)
25
+ builder (~> 2.1.2)
26
+ i18n (~> 0.5.0)
27
+ activerecord (3.0.10)
28
+ activemodel (= 3.0.10)
29
+ activesupport (= 3.0.10)
30
+ arel (~> 2.0.10)
31
+ tzinfo (~> 0.3.23)
32
+ activeresource (3.0.10)
33
+ activemodel (= 3.0.10)
34
+ activesupport (= 3.0.10)
35
+ activesupport (3.0.10)
36
+ addressable (2.2.6)
37
+ arel (2.0.10)
38
+ builder (2.1.2)
39
+ capybara (1.0.1)
40
+ mime-types (>= 1.16)
41
+ nokogiri (>= 1.3.3)
42
+ rack (>= 1.0.0)
43
+ rack-test (>= 0.5.4)
44
+ selenium-webdriver (~> 2.0)
45
+ xpath (~> 0.1.4)
46
+ childprocess (0.2.2)
47
+ ffi (~> 1.0.6)
48
+ columnize (0.3.4)
49
+ diff-lcs (1.1.3)
50
+ erubis (2.6.6)
51
+ abstract (>= 1.0.0)
52
+ faraday (0.7.4)
53
+ addressable (~> 2.2.6)
54
+ multipart-post (~> 1.1.0)
55
+ rack (>= 1.1.0, < 2)
56
+ faraday_middleware (0.7.0)
57
+ faraday (~> 0.7.3)
58
+ ffi (1.0.9)
59
+ guard (0.6.2)
60
+ thor (~> 0.14.6)
61
+ guard-rails (0.0.3)
62
+ guard (>= 0.2.2)
63
+ hashie (1.1.0)
64
+ i18n (0.5.0)
65
+ json_pure (1.5.4)
66
+ spruz (~> 0.2.8)
67
+ koala (1.1.0)
68
+ multi_json (~> 1.0)
69
+ multipart-post (~> 1.0)
70
+ linecache (0.46)
71
+ rbx-require-relative (> 0.0.4)
72
+ mail (2.2.19)
73
+ activesupport (>= 2.3.6)
74
+ i18n (>= 0.4.0)
75
+ mime-types (~> 1.16)
76
+ treetop (~> 1.4.8)
77
+ mime-types (1.16)
78
+ multi_json (1.0.3)
79
+ multi_xml (0.2.2)
80
+ multipart-post (1.1.3)
81
+ nokogiri (1.5.0)
82
+ polyglot (0.3.2)
83
+ rack (1.2.3)
84
+ rack-mount (0.6.14)
85
+ rack (>= 1.0.0)
86
+ rack-test (0.5.7)
87
+ rack (>= 1.0)
88
+ rails (3.0.10)
89
+ actionmailer (= 3.0.10)
90
+ actionpack (= 3.0.10)
91
+ activerecord (= 3.0.10)
92
+ activeresource (= 3.0.10)
93
+ activesupport (= 3.0.10)
94
+ bundler (~> 1.0)
95
+ railties (= 3.0.10)
96
+ railties (3.0.10)
97
+ actionpack (= 3.0.10)
98
+ activesupport (= 3.0.10)
99
+ rake (>= 0.8.7)
100
+ rdoc (~> 3.4)
101
+ thor (~> 0.14.4)
102
+ rake (0.9.2)
103
+ rbx-require-relative (0.0.5)
104
+ rdoc (3.9.4)
105
+ rspec (2.6.0)
106
+ rspec-core (~> 2.6.0)
107
+ rspec-expectations (~> 2.6.0)
108
+ rspec-mocks (~> 2.6.0)
109
+ rspec-core (2.6.4)
110
+ rspec-expectations (2.6.0)
111
+ diff-lcs (~> 1.1.2)
112
+ rspec-mocks (2.6.0)
113
+ rspec-rails (2.6.1)
114
+ actionpack (~> 3.0)
115
+ activesupport (~> 3.0)
116
+ railties (~> 3.0)
117
+ rspec (~> 2.6.0)
118
+ ruby-debug (0.10.4)
119
+ columnize (>= 0.1)
120
+ ruby-debug-base (~> 0.10.4.0)
121
+ ruby-debug-base (0.10.4)
122
+ linecache (>= 0.3)
123
+ rubyzip (0.9.4)
124
+ selenium-webdriver (2.5.0)
125
+ childprocess (>= 0.2.1)
126
+ ffi (>= 1.0.7)
127
+ json_pure
128
+ rubyzip
129
+ simple_oauth (0.1.5)
130
+ spruz (0.2.13)
131
+ sqlite3 (1.3.4)
132
+ thor (0.14.6)
133
+ treetop (1.4.10)
134
+ polyglot
135
+ polyglot (>= 0.3.1)
136
+ twitter (1.6.2)
137
+ faraday (~> 0.7.4)
138
+ faraday_middleware (~> 0.7.0)
139
+ hashie (~> 1.1.0)
140
+ multi_json (~> 1.0.0)
141
+ multi_xml (~> 0.2.0)
142
+ simple_oauth (~> 0.1.5)
143
+ tzinfo (0.3.29)
144
+ xpath (0.1.4)
145
+ nokogiri (~> 1.3)
146
+
147
+ PLATFORMS
148
+ ruby
149
+
150
+ DEPENDENCIES
151
+ capybara (>= 0.4.0)
152
+ guard-rails
153
+ koala
154
+ rails (= 3.0.10)
155
+ rspec-rails (>= 2.0.0.beta)
156
+ ruby-debug
157
+ silvermoon!
158
+ sqlite3
159
+ twitter
@@ -0,0 +1,21 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec/" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec/" }
15
+ watch('spec/spec_helper.rb') { "spec/" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+ # Capybara request specs
19
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+ end
21
+
@@ -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,83 @@
1
+ = Silvermoon
2
+
3
+ A simple notifier wrapper for rails.
4
+
5
+ == Usage
6
+
7
+ On the Gemfile:
8
+
9
+ gem 'silvermoon'
10
+ Then:
11
+
12
+ bundle install
13
+
14
+ After you have the gem installed, run the installer
15
+
16
+ rails g silvermoon:install
17
+
18
+ This will generate one file:
19
+
20
+ config/silvermoon.yml
21
+
22
+ And add two gems to your gemfile:
23
+
24
+ koala
25
+ twitter
26
+
27
+ The file will configure how *Silvermoon* will work on your system and
28
+ the two gems are a dependency for the default notifiers, if you create your
29
+ own implementations you can just remove them.
30
+
31
+ === silvermoon.yml
32
+
33
+ Here you will add specifics for each notifier that you use, and any extra
34
+ information necessary so that they notify their respective services.
35
+
36
+ It uses dependency injection so you can specificy what class will be
37
+ instantiated to receive the notify method.
38
+
39
+ It comes with two defaults, the Facebook and the Twitter notifiers and they
40
+ use respectively Koala and Twitter gems to communicate with the services.
41
+
42
+ If you don't like them, you can simply remove them and make your own class to
43
+ receive the notification.
44
+
45
+ Check out `Silvermoon::Notifier::Base` to know how to implement your own
46
+ notifier.
47
+
48
+ === Notifying
49
+
50
+ Now that your environment is ready, you have to specify what and who to notify.
51
+ This is done in two ways at your controllers.
52
+
53
+ To say *who* will be notified, you simply add in the top of your controller:
54
+
55
+ notifies :twitter, :facebook
56
+
57
+ By default it will use all the notifiers declared on the `silvermoon.rb` but you can
58
+ specify different notifications for different controllers.
59
+
60
+ This sets up a controller scope notification setting, but you can still override it at the notification time.
61
+
62
+ Finally, to say *what* will be notified by the services you've enabled, you add this line:
63
+
64
+ notify('This is my title', 'This is my content', 'http://myurl.com')
65
+
66
+ ==== Important note
67
+
68
+ This is an interface for notifications, the notify method also accepts an additional hash of parameters
69
+ and every notifier reads this data and uses it in different ways.
70
+ For instance, the twitter notifier does not use the content, it uses just the title and the url. On the other hand
71
+ the facebook notifier can take an `:image` parameter and will render that image url together with the wall post.
72
+
73
+ This is the complete method signature for `notify`:
74
+
75
+ notify(title, content, url, extra = {}, notifiers = controller_notifiers)
76
+
77
+ As you can see, you can specify exclusive notifiers for different actions in your controllers, just pass them to the
78
+ `notifiers` parameter.
79
+
80
+ == Contribution
81
+
82
+ Every contribution is welcome !
83
+ I am eager to receive constructive criticism, feature requests, bug reports, pull requests, anything!
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ require 'bundler/gem_tasks'
16
+
17
+ RSpec::Core::RakeTask.new(:spec)
18
+
19
+ task :default => :spec
20
+
21
+ Rake::RDocTask.new(:rdoc) do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'Silvermoon'
24
+ rdoc.options << '--line-numbers' << '--inline-source'
25
+ rdoc.rdoc_files.include('README.rdoc')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
27
+ end
@@ -0,0 +1,16 @@
1
+ module Silvermoon
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_silvermoon_yaml
7
+ copy_file 'silvermoon.yml', 'config/silvermoon.yml'
8
+ end
9
+
10
+ def add_default_dependent_gems
11
+ gem 'koala'
12
+ gem 'twitter'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+
2
+ development: &development
3
+ facebook:
4
+ klass: 'Silvermoon::Notifier::Facebook'
5
+ app_id: 'MY_APP_ID'
6
+ app_secret: 'MY_APP_SECRET'
7
+ twitter:
8
+ klass: 'Silvermoon::Notifier::Twitter'
9
+ consumer_key: 'MY_APP_CONSUMER_KEY'
10
+ consumer_secret: 'MY_APP_CONSUMER_SECRET'
11
+ oauth_token: 'MY_APP_OAUTH_TOKEN'
12
+ oauth_token_secret: 'MY_APP_OAUTH_TOKEN_SECRET'
13
+
14
+ production:
15
+ <<: *development
16
+ test:
17
+ <<: *development
@@ -0,0 +1,54 @@
1
+ module Silvermoon
2
+
3
+ autoload :Notifier, 'silvermoon/notifier'
4
+
5
+ autoload :ActionControllerExtension, 'silvermoon/action_controller_extension'
6
+
7
+ module Notifier
8
+ autoload :Base, 'silvermoon/notifier/base'
9
+ autoload :Facebook, 'silvermoon/notifier/facebook'
10
+ autoload :Twitter, 'silvermoon/notifier/twitter'
11
+ end
12
+
13
+ require 'silvermoon/railtie'
14
+
15
+ mattr_accessor :loaded_notifiers
16
+ @@loaded_notifiers = Hash.new
17
+
18
+ def self.notify(title, content, url, extras = {}, notifiers = [])
19
+ returns = {}
20
+ notifiers = Notifier.config.keys if notifiers.empty?
21
+ notifiers.each do |notifier|
22
+ loaded_notifier = loaded_notifiers[notifier] || load_notifier(notifier)
23
+ begin
24
+ returns[notifier] = loaded_notifier.notify(title, content, url, extras)
25
+ rescue ::Exception => e
26
+ returns[notifier] = e
27
+ end
28
+ end
29
+ returns
30
+ end
31
+
32
+ def self.add_notifier(notifier)
33
+ load_notifier(notifier)
34
+ end
35
+
36
+ def self.clear_notifiers!
37
+ @@loaded_notifiers = Hash.new
38
+ end
39
+
40
+ # def self.setup(&block)
41
+ # self.instance_exec(&block)
42
+ # end
43
+
44
+ private
45
+
46
+ def self.load_notifier(notifier)
47
+ return loaded_notifiers[notifier] if loaded_notifiers.has_key?(notifier)
48
+ loaded_notifier = Silvermoon::Notifier.config[notifier]['klass'].constantize.new
49
+ loaded_notifier.identifier = notifier
50
+ loaded_notifiers[notifier] = loaded_notifier
51
+ loaded_notifier
52
+ end
53
+
54
+ end
@@ -0,0 +1,22 @@
1
+ module Silvermoon
2
+ module ActionControllerExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ cattr_accessor :controller_notifiers
7
+ end
8
+
9
+ module ClassMethods
10
+ def notifies(*what)
11
+ self.controller_notifiers = what.to_a.compact
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def notify(title, content, url, extras = {}, notifiers = nil)
17
+ Silvermoon.notify(title, content, url, extras, (notifiers || self.controller_notifiers) )
18
+ end
19
+ end
20
+
21
+ end
22
+ end