hootenanny 0.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 (63) hide show
  1. data/.gitignore +35 -0
  2. data/.rspec +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +26 -0
  5. data/Gemfile.lock +145 -0
  6. data/README.md +3 -0
  7. data/Rakefile +23 -0
  8. data/app/controllers/hootenanny/subscriptions_controller.rb +14 -0
  9. data/app/models/hootenanny/subscription.rb +71 -0
  10. data/config/routes.rb +3 -0
  11. data/db/migrate/20130522014217_create_subscription_table.rb +7 -0
  12. data/db/migrate/20130522020623_rename_subscriptions_table.rb +9 -0
  13. data/db/migrate/20130522235837_add_topic_to_subscriptions.rb +8 -0
  14. data/db/migrate/20130523032940_add_subscriber_to_subscriptions.rb +9 -0
  15. data/hootenanny.gemspec +41 -0
  16. data/lib/hootenanny.rb +5 -0
  17. data/lib/hootenanny/engine.rb +9 -0
  18. data/lib/hootenanny/errors.rb +7 -0
  19. data/lib/hootenanny/hub.rb +41 -0
  20. data/lib/hootenanny/version.rb +3 -0
  21. data/lib/tasks/hootenanny_tasks.rake +4 -0
  22. data/script/rails +8 -0
  23. data/spec/controllers/hootenanny/hub_spec.rb +15 -0
  24. data/spec/dummy/README.rdoc +261 -0
  25. data/spec/dummy/Rakefile +7 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/mailers/.gitkeep +0 -0
  31. data/spec/dummy/app/models/.gitkeep +0 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/spec/dummy/config.ru +4 -0
  34. data/spec/dummy/config/application.rb +65 -0
  35. data/spec/dummy/config/boot.rb +10 -0
  36. data/spec/dummy/config/database.yml +11 -0
  37. data/spec/dummy/config/environment.rb +5 -0
  38. data/spec/dummy/config/environments/development.rb +37 -0
  39. data/spec/dummy/config/environments/production.rb +67 -0
  40. data/spec/dummy/config/environments/test.rb +37 -0
  41. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/spec/dummy/config/initializers/inflections.rb +15 -0
  43. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  44. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  45. data/spec/dummy/config/initializers/session_store.rb +8 -0
  46. data/spec/dummy/config/initializers/strong_parameters.rb +1 -0
  47. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/spec/dummy/config/locales/en.yml +5 -0
  49. data/spec/dummy/config/routes.rb +3 -0
  50. data/spec/dummy/db/migrate/20130522014446_create_subscription_table.hootenanny.rb +8 -0
  51. data/spec/dummy/db/migrate/20130522020714_rename_subscriptions_table.hootenanny.rb +10 -0
  52. data/spec/dummy/db/migrate/20130523000104_add_topic_to_subscriptions.hootenanny.rb +9 -0
  53. data/spec/dummy/db/migrate/20130523053741_add_subscriber_to_subscriptions.hootenanny.rb +10 -0
  54. data/spec/dummy/lib/assets/.gitkeep +0 -0
  55. data/spec/dummy/public/404.html +26 -0
  56. data/spec/dummy/public/422.html +26 -0
  57. data/spec/dummy/public/500.html +25 -0
  58. data/spec/dummy/public/favicon.ico +0 -0
  59. data/spec/dummy/script/rails +6 -0
  60. data/spec/factories/subscription.rb +6 -0
  61. data/spec/features/subscribers/can_subscribe_to_a_topic_spec.rb +45 -0
  62. data/spec/models/hootenanny/subscription_spec.rb +50 -0
  63. metadata +282 -0
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ ### Local development files
2
+ public/uploads
3
+ *.sqlite3
4
+ /config/environment.rb
5
+
6
+ ### System Files
7
+ .DS_Store
8
+ tags
9
+
10
+ ## Environment-specific Files
11
+ config/initializers/local_developer.rb
12
+
13
+ REVISION
14
+
15
+ ## Temporary and Swap Files
16
+ .gitshots
17
+ .bundle
18
+ .yardoc
19
+ coverage/
20
+ public/tmp
21
+ public/assets
22
+ public/system
23
+ log
24
+ log/*
25
+ log/**/*
26
+ *.log
27
+ tmp/*
28
+ *.swp
29
+ capybara-*
30
+ *.sassc
31
+ *.scssc
32
+ spec/dummy/tmp
33
+ spec/dummy/db/schema.rb
34
+
35
+ *_spec.js
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -I app
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in hootenanny.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+ gem 'strong_parameters'
19
+
20
+ gem 'rspectacular', :require => false
21
+ gem 'database_cleaner'
22
+ gem 'sqlite3'
23
+ gem 'rspec-rails'
24
+ gem 'shoulda-matchers'
25
+ gem 'factory_girl_rails'
26
+ gem 'awesome_print'
data/Gemfile.lock ADDED
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hootenanny (0.0.1)
5
+ rails (~> 3.2)
6
+ strong_parameters (~> 0.2.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.13)
12
+ actionpack (= 3.2.13)
13
+ mail (~> 2.5.3)
14
+ actionpack (3.2.13)
15
+ activemodel (= 3.2.13)
16
+ activesupport (= 3.2.13)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.4)
20
+ rack (~> 1.4.5)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.2.1)
24
+ activemodel (3.2.13)
25
+ activesupport (= 3.2.13)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.13)
28
+ activemodel (= 3.2.13)
29
+ activesupport (= 3.2.13)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.13)
33
+ activemodel (= 3.2.13)
34
+ activesupport (= 3.2.13)
35
+ activesupport (3.2.13)
36
+ i18n (= 0.6.1)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ awesome_print (1.1.0)
40
+ builder (3.0.4)
41
+ database_cleaner (1.0.1)
42
+ diff-lcs (1.2.4)
43
+ erubis (2.7.0)
44
+ factory_girl (4.2.0)
45
+ activesupport (>= 3.0.0)
46
+ factory_girl_rails (4.2.1)
47
+ factory_girl (~> 4.2.0)
48
+ railties (>= 3.0.0)
49
+ fuubar (1.1.0)
50
+ rspec (~> 2.0)
51
+ rspec-instafail (~> 0.2.0)
52
+ ruby-progressbar (~> 1.0.0)
53
+ hike (1.2.2)
54
+ i18n (0.6.1)
55
+ journey (1.0.4)
56
+ jquery-rails (2.2.1)
57
+ railties (>= 3.0, < 5.0)
58
+ thor (>= 0.14, < 2.0)
59
+ json (1.8.0)
60
+ mail (2.5.4)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ mime-types (1.23)
64
+ multi_json (1.7.3)
65
+ pg (0.15.1)
66
+ polyglot (0.3.3)
67
+ rack (1.4.5)
68
+ rack-cache (1.2)
69
+ rack (>= 0.4)
70
+ rack-ssl (1.3.3)
71
+ rack
72
+ rack-test (0.6.2)
73
+ rack (>= 1.0)
74
+ rails (3.2.13)
75
+ actionmailer (= 3.2.13)
76
+ actionpack (= 3.2.13)
77
+ activerecord (= 3.2.13)
78
+ activeresource (= 3.2.13)
79
+ activesupport (= 3.2.13)
80
+ bundler (~> 1.0)
81
+ railties (= 3.2.13)
82
+ railties (3.2.13)
83
+ actionpack (= 3.2.13)
84
+ activesupport (= 3.2.13)
85
+ rack-ssl (~> 1.3.2)
86
+ rake (>= 0.8.7)
87
+ rdoc (~> 3.4)
88
+ thor (>= 0.14.6, < 2.0)
89
+ rake (10.0.4)
90
+ rdoc (3.12.2)
91
+ json (~> 1.4)
92
+ rspec (2.13.0)
93
+ rspec-core (~> 2.13.0)
94
+ rspec-expectations (~> 2.13.0)
95
+ rspec-mocks (~> 2.13.0)
96
+ rspec-core (2.13.1)
97
+ rspec-expectations (2.13.0)
98
+ diff-lcs (>= 1.1.3, < 2.0)
99
+ rspec-instafail (0.2.4)
100
+ rspec-mocks (2.13.1)
101
+ rspec-rails (2.13.2)
102
+ actionpack (>= 3.0)
103
+ activesupport (>= 3.0)
104
+ railties (>= 3.0)
105
+ rspec-core (~> 2.13.0)
106
+ rspec-expectations (~> 2.13.0)
107
+ rspec-mocks (~> 2.13.0)
108
+ rspectacular (0.13.0)
109
+ fuubar (~> 1.0)
110
+ rspec (~> 2.12)
111
+ ruby-progressbar (1.0.2)
112
+ shoulda-matchers (2.1.0)
113
+ activesupport (>= 3.0.0)
114
+ sprockets (2.2.2)
115
+ hike (~> 1.2)
116
+ multi_json (~> 1.0)
117
+ rack (~> 1.0)
118
+ tilt (~> 1.1, != 1.3.0)
119
+ sqlite3 (1.3.7)
120
+ strong_parameters (0.2.1)
121
+ actionpack (~> 3.0)
122
+ activemodel (~> 3.0)
123
+ railties (~> 3.0)
124
+ thor (0.18.1)
125
+ tilt (1.4.1)
126
+ treetop (1.4.12)
127
+ polyglot
128
+ polyglot (>= 0.3.1)
129
+ tzinfo (0.3.37)
130
+
131
+ PLATFORMS
132
+ ruby
133
+
134
+ DEPENDENCIES
135
+ awesome_print
136
+ database_cleaner
137
+ factory_girl_rails
138
+ hootenanny!
139
+ jquery-rails
140
+ pg
141
+ rspec-rails
142
+ rspectacular
143
+ shoulda-matchers
144
+ sqlite3
145
+ strong_parameters
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ = Hootenanny
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
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 = 'Hootenanny'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.md')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,14 @@
1
+ require 'hootenanny/hub'
2
+
3
+ module Hootenanny
4
+ class SubscriptionsController < ActionController::Base
5
+ def create
6
+ if Hootenanny::Hub.subscribe(params[:callback], to: params[:topic])
7
+ render :nothing => true, :status => :no_content
8
+ end
9
+ rescue Hootenanny::SubscriptionAssignmentError => e
10
+ render json: { error: e.to_h },
11
+ status: :bad_request
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ require 'uri'
2
+ require 'hootenanny/errors'
3
+
4
+ module Hootenanny
5
+ class Subscription < ActiveRecord::Base
6
+ self.table_name = 'hootenanny_subscriptions'
7
+
8
+ ###
9
+ # Private: Finds all subscriptions which are subscribed to a given topic
10
+ #
11
+ # topic - A String represeenting a topic which has been subscribed to
12
+ #
13
+ # Example:
14
+ #
15
+ # Subscription.to('http://example.com/foo')
16
+ # # => <ActiveRelation>
17
+ #
18
+ # Returns an ActiveRelation which (if it has not been chained) represents the
19
+ # subscriptions which are subscribed to the topic.
20
+ #
21
+ def self.to(topic)
22
+ where(:topic => topic)
23
+ end
24
+
25
+ ###
26
+ # Private: Assigns a given subscriber to a given topic URL by creating
27
+ # a Subscription.
28
+ #
29
+ # options - A Hash of options
30
+ #
31
+ # :subscriber - A String representing the URI which should be
32
+ # notified when changes occur on the topic
33
+ # :to - A String representing the topic URI which is
34
+ # publishing the items that the subscriber is
35
+ # interested in.
36
+ #
37
+ # Example:
38
+ #
39
+ # # If a subscription does not yet exist for the subscriber/topic, it
40
+ # # creates # a new Subscription
41
+ #
42
+ # Subscription.assign(subscriber: 'http://example.com/my_callback',
43
+ # to: 'http://example.org/my_topic')
44
+ #
45
+ # # => <Subscription subscriber: 'http://example.com/my_callback',
46
+ # topic: 'http://example.org/my_topic'>
47
+ #
48
+ #
49
+ #
50
+ # # If a subscription already exists for the subscriber/topic, it retrieves
51
+ # # and returns the current Subscription
52
+ #
53
+ # Subscription.assign(subscriber: 'http://example.com/my_callback',
54
+ # to: 'http://example.org/my_topic')
55
+ #
56
+ # # => <Subscription subscriber: 'http://example.com/my_callback',
57
+ # topic: 'http://example.org/my_topic'>
58
+ #
59
+ # Returns a Subscription
60
+ #
61
+ def self.assign(options = {})
62
+ subscriber = URI.parse(options.fetch(:subscriber)).to_s
63
+ topic = URI.parse(options.fetch(:to)).to_s
64
+
65
+ where( subscriber: subscriber, topic: topic).first ||
66
+ create(subscriber: subscriber, topic: topic)
67
+ rescue URI::InvalidURIError
68
+ raise Hootenanny::SubscriptionAssignmentError.new('All options passed need to be valid URIs')
69
+ end
70
+ end
71
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Hootenanny::Engine.routes.draw do
2
+ resource :subscription, :only => :create
3
+ end
@@ -0,0 +1,7 @@
1
+ class CreateSubscriptionTable < ActiveRecord::Migration
2
+ def change
3
+ create_table :subscriptions do |t|
4
+ t.timestamps
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class RenameSubscriptionsTable < ActiveRecord::Migration
2
+ def up
3
+ rename_table :subscriptions, :hootenanny_subscriptions
4
+ end
5
+
6
+ def down
7
+ rename_table :hootenanny_subscriptions, :subscriptions
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class AddTopicToSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :hootenanny_subscriptions, :topic, :string, :limit => 250
4
+ change_column :hootenanny_subscriptions, :topic, :string, :limit => 250, :null => false
5
+
6
+ add_index :hootenanny_subscriptions, :topic, :unique => false
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class AddSubscriberToSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :hootenanny_subscriptions, :subscriber, :string, :limit => 250
4
+ change_column :hootenanny_subscriptions, :subscriber, :string, :limit => 250, :null => false
5
+
6
+ add_index :hootenanny_subscriptions, :subscriber, :unique => false
7
+ add_index :hootenanny_subscriptions, [:subscriber, :topic], :unique => true
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ $:.push File.expand_path("../app/models", __FILE__)
4
+ require 'hootenanny/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.rubygems_version = '1.3.5'
8
+
9
+ s.name = 'hootenanny'
10
+ s.rubyforge_project = 'hootenanny'
11
+
12
+ s.version = Hootenanny::VERSION
13
+ s.platform = Gem::Platform::RUBY
14
+
15
+ s.authors = %w{jfelchner}
16
+ s.email = 'support@thekompanee.com'
17
+ s.date = Time.now
18
+ s.homepage = 'https://github.com/thekompanee/hootenanny'
19
+
20
+ s.summary = "PubSubHubBub Engine for Rails"
21
+ s.description = %Q{A drop-in PubSubHubBub-compliant Rails Engine for easy hubbubing.}
22
+
23
+ s.rdoc_options = ["--charset = UTF-8"]
24
+ s.extra_rdoc_files = %w[README.md]
25
+
26
+ #= Manifest =#
27
+ s.files = `git ls-files`.split($/)
28
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
30
+ s.require_paths = ["lib"]
31
+
32
+ s.add_dependency 'rails', '~> 3.2'
33
+ s.add_dependency 'strong_parameters', '~> 0.2.1'
34
+
35
+ s.add_development_dependency 'pg'
36
+ s.add_development_dependency 'sqlite3'
37
+ s.add_development_dependency 'rspec-rails', '~> 2.13'
38
+ s.add_development_dependency 'database_cleaner', '~> 0.9.1'
39
+ s.add_development_dependency 'rspectacular', '~> 0.13'
40
+ s.add_development_dependency 'factory_girl_rails', '~> 4.2'
41
+ end
data/lib/hootenanny.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rails'
2
+ require 'hootenanny/engine'
3
+
4
+ module Hootenanny
5
+ end
@@ -0,0 +1,9 @@
1
+ module Hootenanny
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Hootenanny
4
+
5
+ initializer "model_core.factories", :after => "factory_girl.set_factory_paths" do
6
+ FactoryGirl.definition_file_paths << File.expand_path('../../../../spec/factories', __FILE__) if defined?(FactoryGirl)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class Hootenanny::SubscriptionAssignmentError < ArgumentError
2
+ def to_h
3
+ {
4
+ message: self.message
5
+ }
6
+ end
7
+ end