├── Rakefile ├── lib ├── simple_faye │ ├── version.rb │ ├── engine.rb │ └── view_helpers.rb └── simple_faye.rb ├── Gemfile ├── .gitignore ├── README.md ├── simple_faye.gemspec └── LICENSE /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | -------------------------------------------------------------------------------- /lib/simple_faye/version.rb: -------------------------------------------------------------------------------- 1 | module SimpleFaye 2 | VERSION = "0.1.0" 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in simple_faye.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /lib/simple_faye/engine.rb: -------------------------------------------------------------------------------- 1 | require "simple_faye/view_helpers" 2 | 3 | module SimpleFaye 4 | class Engine < Rails::Engine 5 | # Adds the ViewHelpers into ActionView::Base 6 | initializer "simple_faye.view_helpers" do 7 | ActionView::Base.send :include, ViewHelpers 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/simple_faye.rb: -------------------------------------------------------------------------------- 1 | require "net/http" 2 | require "simple_faye/version" 3 | require "simple_faye/engine" if defined? Rails 4 | 5 | module SimpleFaye 6 | class << self 7 | def publish_message(subscription, message) 8 | url = URI.parse("http://localhost:9292/faye") 9 | form = Net::HTTP::Post.new(url.path.empty? ? '/' : url.path) 10 | form.set_form_data(:message => "{\"channel\":\"#{subscription}\", \"data\":{\"message\":\"#{message}\"}}") 11 | http = Net::HTTP.new(url.host, url.port) 12 | http.start {|h| h.request(form)} 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleFaye 2 | 3 | TODO: Write a gem description 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | gem 'simple_faye' 10 | 11 | And then execute: 12 | 13 | $ bundle 14 | 15 | Or install it yourself as: 16 | 17 | $ gem install simple_faye 18 | 19 | ## Usage 20 | 21 | TODO: Write usage instructions here 22 | 23 | ## Contributing 24 | 25 | 1. Fork it 26 | 2. Create your feature branch (`git checkout -b my-new-feature`) 27 | 3. Commit your changes (`git commit -am 'Added some feature'`) 28 | 4. Push to the branch (`git push origin my-new-feature`) 29 | 5. Create new Pull Request 30 | -------------------------------------------------------------------------------- /lib/simple_faye/view_helpers.rb: -------------------------------------------------------------------------------- 1 | module SimpleFaye 2 | module ViewHelpers 3 | #Initialize Faye JS and create Faye Client 4 | def faye_js 5 | html = javascript_include_tag "http://localhost:9292/faye.js" 6 | html += content_tag "script", :type => "text/javascript" do 7 | raw("var client = new Faye.Client('http://localhost:9292/faye');") 8 | end 9 | html 10 | end 11 | 12 | def subscribe_to(channel) 13 | content_tag "script", :type => "text/javascript" do 14 | raw("var subscription = client.subscribe(\'#{channel}\', function(data) { 15 | alert(data.message); 16 | subscription.cancel(); 17 | });") 18 | end 19 | 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /simple_faye.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/simple_faye/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Rob Race"] 6 | gem.email = ["rob.race@me.com"] 7 | gem.description = %q{Simple Faye pub/sub gem} 8 | gem.summary = %q{Simple extraction bare minimum methods and helpers to get a Faye pub/sub} 9 | gem.homepage = "" 10 | 11 | gem.files = `git ls-files`.split($\) 12 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 13 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 14 | gem.name = "simple_faye" 15 | gem.require_paths = ["lib"] 16 | gem.version = SimpleFaye::VERSION 17 | 18 | gem.add_dependency 'faye' 19 | gem.add_dependency 'thin' 20 | end 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Rob Race 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------