pubnub 3.3.0.7 → 3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.yardoc/checksums +13 -0
  4. data/.yardoc/object_types +0 -0
  5. data/.yardoc/objects/root.dat +0 -0
  6. data/.yardoc/proxy_types +0 -0
  7. data/LICENSE +27 -0
  8. data/README.md +259 -0
  9. data/Rakefile +7 -0
  10. data/VERSION +1 -0
  11. data/examples/demo_console.rb +198 -0
  12. data/examples/error_server.rb +28 -0
  13. data/examples/pubnub_livestream/.gitignore +16 -0
  14. data/examples/pubnub_livestream/Gemfile +51 -0
  15. data/examples/pubnub_livestream/Gemfile.lock +191 -0
  16. data/examples/pubnub_livestream/README.rdoc +28 -0
  17. data/examples/pubnub_livestream/Rakefile +6 -0
  18. data/examples/pubnub_livestream/app/assets/images/.keep +0 -0
  19. data/examples/pubnub_livestream/app/assets/javascripts/application.js +16 -0
  20. data/examples/pubnub_livestream/app/assets/javascripts/streamer.js.coffee +42 -0
  21. data/examples/pubnub_livestream/app/assets/stylesheets/application.css.sass +22 -0
  22. data/examples/pubnub_livestream/app/assets/stylesheets/streamer.css.scss +3 -0
  23. data/examples/pubnub_livestream/app/controllers/application_controller.rb +5 -0
  24. data/examples/pubnub_livestream/app/controllers/concerns/.keep +0 -0
  25. data/examples/pubnub_livestream/app/controllers/streamer_controller.rb +38 -0
  26. data/examples/pubnub_livestream/app/helpers/application_helper.rb +2 -0
  27. data/examples/pubnub_livestream/app/helpers/streamer_helper.rb +2 -0
  28. data/examples/pubnub_livestream/app/mailers/.keep +0 -0
  29. data/examples/pubnub_livestream/app/models/.keep +0 -0
  30. data/examples/pubnub_livestream/app/models/concerns/.keep +0 -0
  31. data/examples/pubnub_livestream/app/models/message.rb +11 -0
  32. data/examples/pubnub_livestream/app/views/layouts/application.html.erb +14 -0
  33. data/examples/pubnub_livestream/app/views/streamer/index.haml +22 -0
  34. data/examples/pubnub_livestream/bin/bundle +3 -0
  35. data/examples/pubnub_livestream/bin/rails +4 -0
  36. data/examples/pubnub_livestream/bin/rake +4 -0
  37. data/examples/pubnub_livestream/config.ru +4 -0
  38. data/examples/pubnub_livestream/config/application.rb +23 -0
  39. data/examples/pubnub_livestream/config/boot.rb +4 -0
  40. data/examples/pubnub_livestream/config/database.yml +25 -0
  41. data/examples/pubnub_livestream/config/environment.rb +5 -0
  42. data/examples/pubnub_livestream/config/environments/development.rb +29 -0
  43. data/examples/pubnub_livestream/config/environments/production.rb +80 -0
  44. data/examples/pubnub_livestream/config/environments/test.rb +36 -0
  45. data/examples/pubnub_livestream/config/initializers/backtrace_silencers.rb +7 -0
  46. data/examples/pubnub_livestream/config/initializers/filter_parameter_logging.rb +4 -0
  47. data/examples/pubnub_livestream/config/initializers/inflections.rb +16 -0
  48. data/examples/pubnub_livestream/config/initializers/mime_types.rb +5 -0
  49. data/examples/pubnub_livestream/config/initializers/pubnub.rb +12 -0
  50. data/examples/pubnub_livestream/config/initializers/secret_token.rb +12 -0
  51. data/examples/pubnub_livestream/config/initializers/session_store.rb +3 -0
  52. data/examples/pubnub_livestream/config/initializers/wrap_parameters.rb +14 -0
  53. data/examples/pubnub_livestream/config/locales/en.yml +23 -0
  54. data/examples/pubnub_livestream/config/routes.rb +62 -0
  55. data/examples/pubnub_livestream/db/migrate/20130826110322_create_messages.rb +11 -0
  56. data/examples/pubnub_livestream/db/schema.rb +24 -0
  57. data/examples/pubnub_livestream/db/seeds.rb +7 -0
  58. data/examples/pubnub_livestream/lib/assets/.keep +0 -0
  59. data/examples/pubnub_livestream/lib/tasks/.keep +0 -0
  60. data/examples/pubnub_livestream/log/.keep +0 -0
  61. data/examples/pubnub_livestream/public/404.html +58 -0
  62. data/examples/pubnub_livestream/public/422.html +58 -0
  63. data/examples/pubnub_livestream/public/500.html +57 -0
  64. data/examples/pubnub_livestream/public/assets/application-22a604196dfb65fd0d602eb1eb65f9b7.js +4 -0
  65. data/examples/pubnub_livestream/public/assets/application-22a604196dfb65fd0d602eb1eb65f9b7.js.gz +0 -0
  66. data/examples/pubnub_livestream/public/assets/application-3fac0c014bbdf9ee7b3986ff615d5da0.css +5019 -0
  67. data/examples/pubnub_livestream/public/assets/application-3fac0c014bbdf9ee7b3986ff615d5da0.css.gz +0 -0
  68. data/examples/pubnub_livestream/public/assets/application-f06834e402639ad43230e3859b9bdd78.css +1 -0
  69. data/examples/pubnub_livestream/public/assets/application-f06834e402639ad43230e3859b9bdd78.css.gz +0 -0
  70. data/examples/pubnub_livestream/public/assets/application-f91b87f490140d86003c46b4d06b6c70.js +10682 -0
  71. data/examples/pubnub_livestream/public/assets/application-f91b87f490140d86003c46b4d06b6c70.js.gz +0 -0
  72. data/examples/pubnub_livestream/public/assets/manifest-c129e1f5ec52d8b661ebfa902554a2e2.json +1 -0
  73. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-0bc0341283e3bb8ec518375794cc7c28.eot +0 -0
  74. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-24dfb40c91db789b8b8faba6886ac1ef.svg +228 -0
  75. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-4b2130768da98222338d1519f9179528.ttf +0 -0
  76. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-7a07f26f72466361ac9671de2d33fd1c.woff +0 -0
  77. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-9f75212cf9fca594cee7e0e3587db9d1.svg +228 -0
  78. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-ab2f6984951c07fd89e6afdefabd93c7.eot +0 -0
  79. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-c21928f7d46b397b0af6b9ee4a7bd0dd.ttf +0 -0
  80. data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-fa1d7f79d80d03f8a598822bd9df79bf.woff +0 -0
  81. data/examples/pubnub_livestream/public/favicon.ico +0 -0
  82. data/examples/pubnub_livestream/public/robots.txt +5 -0
  83. data/examples/pubnub_livestream/test/controllers/.keep +0 -0
  84. data/examples/pubnub_livestream/test/controllers/streamer_controller_test.rb +7 -0
  85. data/examples/pubnub_livestream/test/fixtures/.keep +0 -0
  86. data/examples/pubnub_livestream/test/fixtures/messages.yml +9 -0
  87. data/examples/pubnub_livestream/test/helpers/.keep +0 -0
  88. data/examples/pubnub_livestream/test/helpers/streamer_helper_test.rb +4 -0
  89. data/examples/pubnub_livestream/test/integration/.keep +0 -0
  90. data/examples/pubnub_livestream/test/mailers/.keep +0 -0
  91. data/examples/pubnub_livestream/test/models/.keep +0 -0
  92. data/examples/pubnub_livestream/test/models/message_test.rb +7 -0
  93. data/examples/pubnub_livestream/test/test_helper.rb +15 -0
  94. data/examples/pubnub_livestream/vendor/assets/javascripts/.keep +0 -0
  95. data/examples/pubnub_livestream/vendor/assets/stylesheets/.keep +0 -0
  96. data/examples/serial_publish.rb +46 -0
  97. data/examples/sinatra/.sass-cache/65d837cc121fc62381bb76d93e5bd081356aa3f9/application.sassc +0 -0
  98. data/examples/sinatra/.sass-cache/d1525a8542f6e7fb2ecd3275251283768779b344/main.rbc +0 -0
  99. data/examples/sinatra/.sass-cache/d35765d68c1df11fa3368aa802b3d38109cba214/application.sassc +0 -0
  100. data/examples/sinatra/main.rb +54 -0
  101. data/examples/sinatra/public/bootstrap-responsive.min.css +9 -0
  102. data/examples/sinatra/public/bootstrap.css +5909 -0
  103. data/examples/sinatra/public/bootstrap.min.css +845 -0
  104. data/examples/sinatra/public/jquery-1.10.2.min.js +5 -0
  105. data/examples/sinatra/views/application.sass +6 -0
  106. data/examples/sinatra/views/index.slim +16 -0
  107. data/examples/sinatra/views/layout.slim +12 -0
  108. data/examples/sinatra/views/streamer.coffee +41 -0
  109. data/examples/sub_and_unsub_1.rb +56 -0
  110. data/examples/translator.rb +129 -0
  111. data/lib/pubnub.rb +31 -375
  112. data/lib/pubnub/client.rb +527 -0
  113. data/lib/pubnub/configuration.rb +25 -0
  114. data/lib/pubnub/crypto.rb +53 -0
  115. data/lib/pubnub/error.rb +23 -0
  116. data/lib/pubnub/request.rb +288 -0
  117. data/lib/pubnub/response.rb +126 -0
  118. data/lib/pubnub/subscription.rb +24 -0
  119. data/lib/tasks/examples.rake +39 -0
  120. data/lib/version.rb +1 -0
  121. data/pubnub.gemspec +26 -0
  122. data/spec/lib/client_spec.rb +346 -0
  123. data/spec/lib/crypto_spec.rb +89 -0
  124. data/spec/lib/history_integration_spec.rb +0 -0
  125. data/spec/lib/presence_integration_spec.rb +16 -0
  126. data/spec/lib/publish_integration_spec.rb +994 -0
  127. data/spec/lib/pubnub_spec.rb +12 -0
  128. data/spec/lib/request_spec.rb +151 -0
  129. data/spec/lib/subscribe_integration_spec.rb +944 -0
  130. data/spec/lib/time_integration_spec.rb +0 -0
  131. data/spec/spec_helper.rb +15 -0
  132. metadata +158 -45
  133. data/lib/pubnub_crypto.rb +0 -53
  134. data/lib/pubnub_request.rb +0 -310
@@ -0,0 +1,28 @@
1
+ require 'eventmachine'
2
+ require 'evma_httpserver'
3
+
4
+ class MyHttpServer < EM::Connection
5
+ include EM::HttpServer
6
+
7
+ def post_init
8
+ super
9
+ no_environment_strings
10
+ end
11
+
12
+ def process_http_request
13
+ server_codes = [400,500,404]
14
+ content_types = ['text/html', 'text/javascript']
15
+ content_bodies = ['YG^SD@UIEKA', '']
16
+
17
+ response = EM::DelegatedHttpResponse.new(self)
18
+ response.status = server_codes.sample
19
+ response.content_type content_types.sample
20
+ response.content = content_bodies.sample
21
+ response.send_response
22
+ puts '>> response send'
23
+ end
24
+ end
25
+
26
+ EM.run{
27
+ EM.start_server '0.0.0.0', 80, MyHttpServer
28
+ }
@@ -0,0 +1,16 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1,51 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
+ gem 'rails', '4.0.0'
5
+ gem 'thin'
6
+ gem 'pubnub', :github => 'pubnub/ruby', :branch => 'pTest'
7
+ gem 'haml'
8
+
9
+ # Use sqlite3 as the database for Active Record
10
+ gem 'sqlite3'
11
+
12
+ # Use SCSS for stylesheets
13
+ gem 'sass-rails', '~> 4.0.0'
14
+
15
+ # Use Uglifier as compressor for JavaScript assets
16
+ gem 'uglifier', '>= 1.3.0'
17
+
18
+ # Use CoffeeScript for .js.coffee assets and views
19
+ gem 'coffee-rails', '~> 4.0.0'
20
+
21
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
22
+ gem 'therubyracer', platforms: :ruby
23
+
24
+ # Use jquery as the JavaScript library
25
+ gem 'jquery-rails'
26
+
27
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
28
+ gem 'turbolinks'
29
+
30
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
31
+ gem 'jbuilder', '~> 1.2'
32
+
33
+ gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails',
34
+ :github => 'anjlab/bootstrap-rails'
35
+
36
+ group :doc do
37
+ # bundle exec rake doc:rails generates the API under doc/api.
38
+ gem 'sdoc', require: false
39
+ end
40
+
41
+ # Use ActiveModel has_secure_password
42
+ # gem 'bcrypt-ruby', '~> 3.0.0'
43
+
44
+ # Use unicorn as the app server
45
+ # gem 'unicorn'
46
+
47
+ # Use Capistrano for deployment
48
+ # gem 'capistrano', group: :development
49
+
50
+ # Use debugger
51
+ # gem 'debugger', group: [:development, :test]
@@ -0,0 +1,191 @@
1
+ GIT
2
+ remote: git://github.com/anjlab/bootstrap-rails.git
3
+ revision: 0ad67ceeab189aa7be69dc2d2f5903d213bbc956
4
+ specs:
5
+ anjlab-bootstrap-rails (3.0.0.2)
6
+ railties (>= 3.0)
7
+ sass (>= 3.2)
8
+
9
+ GIT
10
+ remote: git://github.com/pubnub/ruby.git
11
+ revision: 2eecbe09d37c565d824885ce317d30a6019714c7
12
+ branch: pTest
13
+ specs:
14
+ pubnub (3.4beta)
15
+ em-http-request
16
+ eventmachine
17
+ httparty
18
+ json
19
+ persistent_httparty
20
+ uuid (~> 2.3.5)
21
+
22
+ GEM
23
+ remote: https://rubygems.org/
24
+ specs:
25
+ actionmailer (4.0.0)
26
+ actionpack (= 4.0.0)
27
+ mail (~> 2.5.3)
28
+ actionpack (4.0.0)
29
+ activesupport (= 4.0.0)
30
+ builder (~> 3.1.0)
31
+ erubis (~> 2.7.0)
32
+ rack (~> 1.5.2)
33
+ rack-test (~> 0.6.2)
34
+ activemodel (4.0.0)
35
+ activesupport (= 4.0.0)
36
+ builder (~> 3.1.0)
37
+ activerecord (4.0.0)
38
+ activemodel (= 4.0.0)
39
+ activerecord-deprecated_finders (~> 1.0.2)
40
+ activesupport (= 4.0.0)
41
+ arel (~> 4.0.0)
42
+ activerecord-deprecated_finders (1.0.3)
43
+ activesupport (4.0.0)
44
+ i18n (~> 0.6, >= 0.6.4)
45
+ minitest (~> 4.2)
46
+ multi_json (~> 1.3)
47
+ thread_safe (~> 0.1)
48
+ tzinfo (~> 0.3.37)
49
+ addressable (2.3.5)
50
+ arel (4.0.0)
51
+ atomic (1.1.13)
52
+ atomic (1.1.13-java)
53
+ builder (3.1.4)
54
+ coffee-rails (4.0.0)
55
+ coffee-script (>= 2.2.0)
56
+ railties (>= 4.0.0.beta, < 5.0)
57
+ coffee-script (2.2.0)
58
+ coffee-script-source
59
+ execjs
60
+ coffee-script-source (1.6.3)
61
+ cookiejar (0.3.0)
62
+ daemons (1.1.9)
63
+ em-http-request (1.1.1)
64
+ addressable (>= 2.3.4)
65
+ cookiejar
66
+ em-socksify (>= 0.3)
67
+ eventmachine (>= 1.0.3)
68
+ http_parser.rb (>= 0.6.0.beta.2)
69
+ em-socksify (0.3.0)
70
+ eventmachine (>= 1.0.0.beta.4)
71
+ erubis (2.7.0)
72
+ eventmachine (1.0.3)
73
+ eventmachine (1.0.3-java)
74
+ execjs (2.0.0)
75
+ gene_pool (1.3.0)
76
+ haml (4.0.3)
77
+ tilt
78
+ hike (1.2.3)
79
+ http_parser.rb (0.6.0.beta.2)
80
+ http_parser.rb (0.6.0.beta.2-java)
81
+ httparty (0.11.0)
82
+ multi_json (~> 1.0)
83
+ multi_xml (>= 0.5.2)
84
+ i18n (0.6.5)
85
+ jbuilder (1.5.1)
86
+ activesupport (>= 3.0.0)
87
+ multi_json (>= 1.2.0)
88
+ jquery-rails (3.0.4)
89
+ railties (>= 3.0, < 5.0)
90
+ thor (>= 0.14, < 2.0)
91
+ json (1.8.0)
92
+ json (1.8.0-java)
93
+ libv8 (3.16.14.3)
94
+ macaddr (1.6.1)
95
+ systemu (~> 2.5.0)
96
+ mail (2.5.4)
97
+ mime-types (~> 1.16)
98
+ treetop (~> 1.4.8)
99
+ mime-types (1.24)
100
+ minitest (4.7.5)
101
+ multi_json (1.7.9)
102
+ multi_xml (0.5.5)
103
+ persistent_http (1.0.6)
104
+ gene_pool (>= 1.3)
105
+ persistent_httparty (0.1.1)
106
+ httparty (~> 0.9)
107
+ persistent_http
108
+ polyglot (0.3.3)
109
+ rack (1.5.2)
110
+ rack-test (0.6.2)
111
+ rack (>= 1.0)
112
+ rails (4.0.0)
113
+ actionmailer (= 4.0.0)
114
+ actionpack (= 4.0.0)
115
+ activerecord (= 4.0.0)
116
+ activesupport (= 4.0.0)
117
+ bundler (>= 1.3.0, < 2.0)
118
+ railties (= 4.0.0)
119
+ sprockets-rails (~> 2.0.0)
120
+ railties (4.0.0)
121
+ actionpack (= 4.0.0)
122
+ activesupport (= 4.0.0)
123
+ rake (>= 0.8.7)
124
+ thor (>= 0.18.1, < 2.0)
125
+ rake (10.1.0)
126
+ rdoc (3.12.2)
127
+ json (~> 1.4)
128
+ ref (1.0.5)
129
+ sass (3.2.10)
130
+ sass-rails (4.0.0)
131
+ railties (>= 4.0.0.beta, < 5.0)
132
+ sass (>= 3.1.10)
133
+ sprockets-rails (~> 2.0.0)
134
+ sdoc (0.3.20)
135
+ json (>= 1.1.3)
136
+ rdoc (~> 3.10)
137
+ sprockets (2.10.0)
138
+ hike (~> 1.2)
139
+ multi_json (~> 1.0)
140
+ rack (~> 1.0)
141
+ tilt (~> 1.1, != 1.3.0)
142
+ sprockets-rails (2.0.0)
143
+ actionpack (>= 3.0)
144
+ activesupport (>= 3.0)
145
+ sprockets (~> 2.8)
146
+ sqlite3 (1.3.8)
147
+ systemu (2.5.2)
148
+ therubyracer (0.12.0)
149
+ libv8 (~> 3.16.14.0)
150
+ ref
151
+ thin (1.5.1)
152
+ daemons (>= 1.0.9)
153
+ eventmachine (>= 0.12.6)
154
+ rack (>= 1.0.0)
155
+ thor (0.18.1)
156
+ thread_safe (0.1.2)
157
+ atomic
158
+ thread_safe (0.1.2-java)
159
+ atomic
160
+ tilt (1.4.1)
161
+ treetop (1.4.15)
162
+ polyglot
163
+ polyglot (>= 0.3.1)
164
+ turbolinks (1.3.0)
165
+ coffee-rails
166
+ tzinfo (0.3.37)
167
+ uglifier (2.2.0)
168
+ execjs (>= 0.3.0)
169
+ multi_json (~> 1.0, >= 1.0.2)
170
+ uuid (2.3.7)
171
+ macaddr (~> 1.0)
172
+
173
+ PLATFORMS
174
+ java
175
+ ruby
176
+
177
+ DEPENDENCIES
178
+ anjlab-bootstrap-rails!
179
+ coffee-rails (~> 4.0.0)
180
+ haml
181
+ jbuilder (~> 1.2)
182
+ jquery-rails
183
+ pubnub!
184
+ rails (= 4.0.0)
185
+ sass-rails (~> 4.0.0)
186
+ sdoc
187
+ sqlite3
188
+ therubyracer
189
+ thin
190
+ turbolinks
191
+ uglifier (>= 1.3.0)
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
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
+
6
+ PubnubLivestream::Application.load_tasks
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require streamer
@@ -0,0 +1,42 @@
1
+ worker = ->
2
+ $.ajax
3
+ url: "get_messages"
4
+ success: (data) ->
5
+ append message for message in data
6
+
7
+ complete: ->
8
+ setTimeout worker, 500
9
+
10
+ append = (message) ->
11
+ timetoken = parseInt($("#timetoken").html())
12
+ if timetoken < message["timetoken"]
13
+ msg = jQuery("<div/>",
14
+ text: message["message"]
15
+ class: 'list-group-item'
16
+ )
17
+
18
+ author = jQuery("<span/>",
19
+ text: message["author"] + "@" + message["created_at"]
20
+ class: 'badge'
21
+ )
22
+
23
+ author.appendTo msg
24
+ msg.appendTo "#messages"
25
+
26
+ $("#messages").stop().animate
27
+ scrollTop: $("#messages")[0].scrollHeight
28
+ , 800
29
+
30
+ $("#timetoken").html(message["timetoken"])
31
+ $("#message-field").val('')
32
+
33
+ $ ->
34
+ $('#send-button').click ->
35
+ $.ajax
36
+ url: "publish"
37
+ data: {
38
+ author: $("#author-field").val()
39
+ message: $("#message-field").val()
40
+ }
41
+
42
+ $ -> worker()
@@ -0,0 +1,22 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
14
+
15
+ @import "twitter/bootstrap"
16
+
17
+ body
18
+ padding: 10px
19
+
20
+ #messages
21
+ max-height: 400px
22
+ overflow-y: auto
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the streamer controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,38 @@
1
+ class StreamerController < ApplicationController
2
+ before_filter :subscribe, :only => :index
3
+
4
+ def index
5
+ end
6
+
7
+ def publish
8
+ render :json => $pubnub.publish(
9
+ :channel => 'pubnub_chat',
10
+ :callback => lambda {|x|},
11
+ :message => {
12
+ :author => params[:author],
13
+ :message => params[:message]
14
+
15
+ }
16
+ )
17
+ end
18
+
19
+ def get_messages
20
+ render :json => Message.all
21
+ end
22
+
23
+ def status
24
+ render :text => $pubnub.inspect
25
+ end
26
+
27
+ private
28
+
29
+ def subscribe
30
+ puts 'subscribing...'
31
+
32
+ $pubnub.subscribe(
33
+ :channel => 'pubnub_chat',
34
+ :callback => $callback
35
+ ) unless $pubnub.subscription_running?
36
+ end
37
+
38
+ end