silvermoon 0.1

Sign up to get free protection for your applications and to get access to all the features.
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,18 @@
1
+ require 'yaml'
2
+ require 'rails'
3
+
4
+ module Silvermoon
5
+ module Notifier
6
+
7
+ def self.config
8
+ @@config ||= begin
9
+ YAML.load_file("#{Rails.root}/config/silvermoon.yml").symbolize_keys[Rails.env.to_sym]
10
+ end
11
+ end
12
+
13
+ def self.reload_config!
14
+ @@config = nil
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Silvermoon
2
+ module Notifier
3
+
4
+ class Base
5
+
6
+ attr_accessor :identifier
7
+
8
+ def config
9
+ Silvermoon::Notifier.config[identifier.to_sym] || Silvermoon::Notifier.config[identifier.to_s]
10
+ end
11
+
12
+ def notify(title, content, url, extras = {})
13
+ raise NotImplementedError
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'koala'
2
+
3
+ module Silvermoon
4
+ module Notifier
5
+ class Facebook < Base
6
+
7
+ def identifier
8
+ :facebook
9
+ end
10
+
11
+ def notify(title, content, url, extras = {})
12
+ Rails.logger.info("Notifying Facebook: #{title}, #{content}, #{url}")
13
+ comment = extras.delete(:comment)
14
+ graph.put_wall_post(comment, {:link => url, :description => content, :picture => ''}.reverse_merge(extras), nil, :use_ssl => false)
15
+ end
16
+
17
+ def oauth
18
+ @oauth ||= ::Koala::Facebook::OAuth.new(config['app_id'], config['app_secret'])
19
+ end
20
+
21
+ def graph
22
+ @graph ||= ::Koala::Facebook::GraphAPI.new(access_token)
23
+ end
24
+
25
+ def access_token
26
+ @access_token ||= begin
27
+ token = oauth.get_app_access_token
28
+ raise "Cannot obtain access token" unless token
29
+ token
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module Silvermoon
2
+ module Notifier
3
+ class Twitter < Base
4
+
5
+ def configure
6
+ ::Twitter.configure do |c|
7
+ c.consumer_key = config['consumer_key']
8
+ c.consumer_secret = config['consumer_secret']
9
+ c.oauth_token = config['oauth_token']
10
+ c.oauth_token_secret = config['oauth_token_secret']
11
+ end
12
+ end
13
+
14
+ def notify(title, content, url, extras = {})
15
+ Rails.logger.info("Notifying Twitter: #{title}, #{content}, #{url}")
16
+ twitter.update(title[0..140])
17
+ end
18
+
19
+ def twitter
20
+ @twitter ||= begin
21
+ configure
22
+ ::Twitter::Client.new
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Silvermoon
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ initializer :silvermoon do
5
+ ActiveSupport.on_load(:action_controller) do
6
+ ActionController::Base.send :include, ::Silvermoon::ActionControllerExtension
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Silvermoon
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "silvermoon/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "silvermoon"
7
+ s.version = Silvermoon::VERSION
8
+ s.authors = ["Luiz Felipe G. Pereira"]
9
+ s.email = ["luiz.felipe.gp@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A notification wrapper gem for rails}
12
+ s.description = %q{Silvermoon aims to provide a solid interface to exchange notifications of events on your rails application to several services}
13
+
14
+ #s.rubyforge_project = "silvermoon"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,86 @@
1
+ class NotificationsController < ApplicationController
2
+ notifies :twitter, :facebook
3
+
4
+ # GET /notifications
5
+ # GET /notifications.xml
6
+ def index
7
+ @notifications = Notification.all
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.erb
11
+ format.xml { render :xml => @notifications }
12
+ end
13
+ end
14
+
15
+ # GET /notifications/1
16
+ # GET /notifications/1.xml
17
+ def show
18
+ @notification = Notification.find(params[:id])
19
+
20
+ respond_to do |format|
21
+ format.html # show.html.erb
22
+ format.xml { render :xml => @notification }
23
+ end
24
+ end
25
+
26
+ # GET /notifications/new
27
+ # GET /notifications/new.xml
28
+ def new
29
+ @notification = Notification.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.xml { render :xml => @notification }
34
+ end
35
+ end
36
+
37
+ # GET /notifications/1/edit
38
+ def edit
39
+ @notification = Notification.find(params[:id])
40
+ end
41
+
42
+ # POST /notifications
43
+ # POST /notifications.xml
44
+ def create
45
+ @notification = Notification.new(params[:notification])
46
+
47
+ respond_to do |format|
48
+ if @notification.save
49
+ notify(@notification.title, @notification.content, @notification.url)
50
+ format.html { redirect_to(@notification, :notice => 'Notification was successfully created.') }
51
+ format.xml { render :xml => @notification, :status => :created, :location => @notification }
52
+ else
53
+ format.html { render :action => "new" }
54
+ format.xml { render :xml => @notification.errors, :status => :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PUT /notifications/1
60
+ # PUT /notifications/1.xml
61
+ def update
62
+ @notification = Notification.find(params[:id])
63
+
64
+ respond_to do |format|
65
+ if @notification.update_attributes(params[:notification])
66
+ format.html { redirect_to(@notification, :notice => 'Notification was successfully updated.') }
67
+ format.xml { head :ok }
68
+ else
69
+ format.html { render :action => "edit" }
70
+ format.xml { render :xml => @notification.errors, :status => :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /notifications/1
76
+ # DELETE /notifications/1.xml
77
+ def destroy
78
+ @notification = Notification.find(params[:id])
79
+ @notification.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to(notifications_url) }
83
+ format.xml { head :ok }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module NotificationsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Notification < ActiveRecord::Base
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,29 @@
1
+ <%= form_for(@notification) do |f| %>
2
+ <% if @notification.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@notification.errors.count, "error") %> prohibited this notification from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @notification.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br />
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :content %><br />
20
+ <%= f.text_field :content %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :url %><br />
24
+ <%= f.text_field :url %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing notification</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @notification %> |
6
+ <%= link_to 'Back', notifications_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing notifications</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Title</th>
6
+ <th>Content</th>
7
+ <th>Url</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% @notifications.each do |notification| %>
14
+ <tr>
15
+ <td><%= notification.title %></td>
16
+ <td><%= notification.content %></td>
17
+ <td><%= notification.url %></td>
18
+ <td><%= link_to 'Show', notification %></td>
19
+ <td><%= link_to 'Edit', edit_notification_path(notification) %></td>
20
+ <td><%= link_to 'Destroy', notification, :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%= link_to 'New Notification', new_notification_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New notification</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', notifications_path %>
@@ -0,0 +1,20 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Title:</b>
5
+ <%= @notification.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Content:</b>
10
+ <%= @notification.content %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Url:</b>
15
+ <%= @notification.url %>
16
+ </p>
17
+
18
+
19
+ <%= link_to 'Edit', edit_notification_path(@notification) %> |
20
+ <%= link_to 'Back', notifications_path %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "silvermoon"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000