scout 5.7.1 → 5.7.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/lib/scout/command/run.rb +1 -1
  3. data/lib/scout/server.rb +2 -1
  4. data/lib/scout/streamer.rb +3 -2
  5. data/lib/scout/streamer_daemon.rb +4 -4
  6. data/lib/scout/version.rb +1 -1
  7. data/test/scout_test.rb +7 -8
  8. data/vendor/httpclient/README.txt +759 -0
  9. data/vendor/httpclient/bin/httpclient +65 -0
  10. data/vendor/httpclient/lib/hexdump.rb +50 -0
  11. data/vendor/httpclient/lib/http-access2.rb +55 -0
  12. data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
  13. data/vendor/httpclient/lib/http-access2/http.rb +1 -0
  14. data/vendor/httpclient/lib/httpclient.rb +1156 -0
  15. data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
  16. data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
  17. data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
  18. data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
  19. data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
  20. data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
  21. data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
  22. data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
  23. data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
  24. data/vendor/httpclient/lib/httpclient/util.rb +178 -0
  25. data/vendor/httpclient/lib/httpclient/version.rb +3 -0
  26. data/vendor/httpclient/lib/oauthclient.rb +110 -0
  27. data/vendor/httpclient/sample/async.rb +8 -0
  28. data/vendor/httpclient/sample/auth.rb +11 -0
  29. data/vendor/httpclient/sample/cookie.rb +18 -0
  30. data/vendor/httpclient/sample/dav.rb +103 -0
  31. data/vendor/httpclient/sample/howto.rb +49 -0
  32. data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
  33. data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
  34. data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
  35. data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
  36. data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
  37. data/vendor/httpclient/sample/ssl/0key.pem +30 -0
  38. data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
  39. data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
  40. data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
  41. data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
  42. data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/vendor/httpclient/sample/stream.rb +21 -0
  44. data/vendor/httpclient/sample/thread.rb +27 -0
  45. data/vendor/httpclient/sample/wcat.rb +21 -0
  46. data/vendor/httpclient/test/ca-chain.cert +44 -0
  47. data/vendor/httpclient/test/ca.cert +23 -0
  48. data/vendor/httpclient/test/client.cert +19 -0
  49. data/vendor/httpclient/test/client.key +15 -0
  50. data/vendor/httpclient/test/helper.rb +129 -0
  51. data/vendor/httpclient/test/htdigest +1 -0
  52. data/vendor/httpclient/test/htpasswd +2 -0
  53. data/vendor/httpclient/test/runner.rb +2 -0
  54. data/vendor/httpclient/test/server.cert +19 -0
  55. data/vendor/httpclient/test/server.key +15 -0
  56. data/vendor/httpclient/test/sslsvr.rb +65 -0
  57. data/vendor/httpclient/test/subca.cert +21 -0
  58. data/vendor/httpclient/test/test_auth.rb +321 -0
  59. data/vendor/httpclient/test/test_cookie.rb +391 -0
  60. data/vendor/httpclient/test/test_hexdump.rb +14 -0
  61. data/vendor/httpclient/test/test_http-access2.rb +507 -0
  62. data/vendor/httpclient/test/test_httpclient.rb +1783 -0
  63. data/vendor/httpclient/test/test_include_client.rb +52 -0
  64. data/vendor/httpclient/test/test_ssl.rb +235 -0
  65. data/vendor/multi_json/.document +5 -0
  66. data/vendor/multi_json/.rspec +3 -0
  67. data/vendor/multi_json/.travis.yml +11 -0
  68. data/vendor/multi_json/.yardopts +6 -0
  69. data/vendor/multi_json/CHANGELOG.md +169 -0
  70. data/vendor/multi_json/CONTRIBUTING.md +46 -0
  71. data/vendor/multi_json/Gemfile +31 -0
  72. data/vendor/multi_json/LICENSE.md +20 -0
  73. data/vendor/multi_json/README.md +109 -0
  74. data/vendor/multi_json/Rakefile +12 -0
  75. data/vendor/multi_json/lib/multi_json.rb +157 -0
  76. data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
  77. data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
  78. data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
  79. data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
  80. data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
  81. data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
  82. data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
  83. data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
  84. data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
  85. data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
  86. data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
  87. data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
  88. data/vendor/multi_json/lib/multi_json/options.rb +48 -0
  89. data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
  90. data/vendor/multi_json/lib/multi_json/version.rb +20 -0
  91. data/vendor/multi_json/multi_json.gemspec +22 -0
  92. data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
  93. data/vendor/multi_json/spec/has_options.rb +119 -0
  94. data/vendor/multi_json/spec/helper.rb +35 -0
  95. data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
  96. data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
  97. data/vendor/{signature → pusher}/.document +0 -0
  98. data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
  99. data/vendor/pusher/.gitignore +23 -0
  100. data/vendor/pusher/.travis.yml +15 -0
  101. data/vendor/pusher/Gemfile +2 -0
  102. data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
  103. data/vendor/pusher/README.md +186 -0
  104. data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
  105. data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
  106. data/vendor/pusher/lib/pusher.rb +60 -0
  107. data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
  108. data/vendor/pusher/lib/pusher/client.rb +306 -0
  109. data/vendor/pusher/lib/pusher/request.rb +107 -0
  110. data/vendor/pusher/lib/pusher/resource.rb +36 -0
  111. data/vendor/pusher/lib/pusher/webhook.rb +110 -0
  112. data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
  113. data/vendor/pusher/spec/channel_spec.rb +127 -0
  114. data/vendor/pusher/spec/client_spec.rb +464 -0
  115. data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
  116. data/vendor/pusher/spec/web_hook_spec.rb +117 -0
  117. data/vendor/signature/.travis.yml +15 -0
  118. data/vendor/signature/Gemfile +1 -1
  119. data/vendor/signature/README.md +38 -28
  120. data/vendor/signature/lib/signature.rb +97 -15
  121. data/vendor/signature/lib/signature/query_encoder.rb +47 -0
  122. data/vendor/signature/lib/signature/version.rb +1 -1
  123. data/vendor/signature/signature.gemspec +3 -2
  124. data/vendor/signature/spec/signature_spec.rb +164 -55
  125. data/vendor/signature/spec/spec_helper.rb +2 -3
  126. metadata +120 -145
  127. data/vendor/json_pure/.gitignore +0 -12
  128. data/vendor/json_pure/.travis.yml +0 -20
  129. data/vendor/json_pure/CHANGES +0 -282
  130. data/vendor/json_pure/COPYING +0 -58
  131. data/vendor/json_pure/COPYING-json-jruby +0 -57
  132. data/vendor/json_pure/GPL +0 -340
  133. data/vendor/json_pure/Gemfile +0 -11
  134. data/vendor/json_pure/README-json-jruby.markdown +0 -33
  135. data/vendor/json_pure/README.rdoc +0 -358
  136. data/vendor/json_pure/Rakefile +0 -412
  137. data/vendor/json_pure/TODO +0 -1
  138. data/vendor/json_pure/VERSION +0 -1
  139. data/vendor/json_pure/data/example.json +0 -1
  140. data/vendor/json_pure/data/index.html +0 -38
  141. data/vendor/json_pure/data/prototype.js +0 -4184
  142. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
  143. data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
  144. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
  145. data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
  146. data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
  147. data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
  148. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
  149. data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
  150. data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
  151. data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
  152. data/vendor/json_pure/install.rb +0 -23
  153. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
  154. data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
  155. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
  156. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
  157. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
  158. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
  159. data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
  160. data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
  161. data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
  162. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
  163. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
  164. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
  165. data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
  166. data/vendor/json_pure/json-java.gemspec +0 -23
  167. data/vendor/json_pure/json.gemspec +0 -37
  168. data/vendor/json_pure/json_pure.gemspec +0 -39
  169. data/vendor/json_pure/lib/json.rb +0 -62
  170. data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
  171. data/vendor/json_pure/lib/json/add/complex.rb +0 -22
  172. data/vendor/json_pure/lib/json/add/core.rb +0 -11
  173. data/vendor/json_pure/lib/json/add/date.rb +0 -34
  174. data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
  175. data/vendor/json_pure/lib/json/add/exception.rb +0 -31
  176. data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
  177. data/vendor/json_pure/lib/json/add/range.rb +0 -29
  178. data/vendor/json_pure/lib/json/add/rational.rb +0 -22
  179. data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
  180. data/vendor/json_pure/lib/json/add/struct.rb +0 -30
  181. data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
  182. data/vendor/json_pure/lib/json/add/time.rb +0 -38
  183. data/vendor/json_pure/lib/json/common.rb +0 -487
  184. data/vendor/json_pure/lib/json/ext.rb +0 -21
  185. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  186. data/vendor/json_pure/lib/json/generic_object.rb +0 -70
  187. data/vendor/json_pure/lib/json/pure.rb +0 -21
  188. data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
  189. data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
  190. data/vendor/json_pure/lib/json/version.rb +0 -8
  191. data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  192. data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  193. data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  194. data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  195. data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  196. data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  197. data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  198. data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  199. data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  200. data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  201. data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  202. data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  203. data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  204. data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  205. data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  206. data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  207. data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  208. data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  209. data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  210. data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  211. data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  212. data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  213. data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  214. data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  215. data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  216. data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  217. data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  218. data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  219. data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  220. data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  221. data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  222. data/vendor/json_pure/tests/setup_variant.rb +0 -11
  223. data/vendor/json_pure/tests/test_json.rb +0 -545
  224. data/vendor/json_pure/tests/test_json_addition.rb +0 -196
  225. data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
  226. data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
  227. data/vendor/json_pure/tests/test_json_generate.rb +0 -322
  228. data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
  229. data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
  230. data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
  231. data/vendor/json_pure/tools/fuzz.rb +0 -139
  232. data/vendor/json_pure/tools/server.rb +0 -62
  233. data/vendor/pusher-gem/Gemfile +0 -2
  234. data/vendor/pusher-gem/README.md +0 -80
  235. data/vendor/pusher-gem/lib/pusher.rb +0 -107
  236. data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
  237. data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
  238. data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
  239. data/vendor/ruby-hmac/History.txt +0 -15
  240. data/vendor/ruby-hmac/Manifest.txt +0 -11
  241. data/vendor/ruby-hmac/README.md +0 -41
  242. data/vendor/ruby-hmac/Rakefile +0 -23
  243. data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
  244. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
  245. data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
  246. data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
  247. data/vendor/ruby-hmac/lib/hmac.rb +0 -118
  248. data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
  249. data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
  250. data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
  251. data/vendor/signature/VERSION +0 -1
@@ -1,107 +0,0 @@
1
- autoload 'Logger', 'logger'
2
- require 'uri'
3
-
4
- # Used for configuring API credentials and creating Channel objects
5
- #
6
- module Pusher
7
- # All Pusher errors descend from this class so you can easily rescue Pusher
8
- # errors
9
- #
10
- # @example
11
- # begin
12
- # Pusher['a_channel'].trigger!('an_event', {:some => 'data'})
13
- # rescue Pusher::Error => e
14
- # # Do something on error
15
- # end
16
- class Error < RuntimeError; end
17
- class AuthenticationError < Error; end
18
- class ConfigurationError < Error; end
19
- class HTTPError < Error; attr_accessor :original_error; end
20
-
21
- class << self
22
- attr_accessor :scheme, :host, :port
23
- attr_writer :logger
24
- attr_accessor :app_id, :key, :secret
25
-
26
- # @private
27
- def logger
28
- @logger ||= begin
29
- log = Logger.new($stdout)
30
- log.level = Logger::INFO
31
- log
32
- end
33
- end
34
-
35
- # @private
36
- def authentication_token
37
- Signature::Token.new(@key, @secret)
38
- end
39
-
40
- # @private Builds a connection url for Pusherapp
41
- def url
42
- URI::Generic.build({
43
- :scheme => self.scheme,
44
- :host => self.host,
45
- :port => self.port,
46
- :path => "/apps/#{self.app_id}"
47
- })
48
- end
49
-
50
- # Configure Pusher connection by providing a url rather than specifying
51
- # scheme, key, secret, and app_id separately.
52
- #
53
- # @example
54
- # Pusher.url = http://KEY:SECRET@api.pusherapp.com/apps/APP_ID
55
- #
56
- def url=(url)
57
- uri = URI.parse(url)
58
- self.app_id = uri.path.split('/').last
59
- self.key = uri.user
60
- self.secret = uri.password
61
- self.host = uri.host
62
- self.port = uri.port
63
- end
64
-
65
- # Configure whether Pusher API calls should be made over SSL
66
- # (default false)
67
- #
68
- # @example
69
- # Pusher.encrypted = true
70
- #
71
- def encrypted=(boolean)
72
- Pusher.scheme = boolean ? 'https' : 'http'
73
- # Configure port if it hasn't already been configured
74
- Pusher.port ||= boolean ? 443 : 80
75
- end
76
-
77
- private
78
-
79
- def configured?
80
- host && scheme && key && secret && app_id
81
- end
82
- end
83
-
84
- # Defaults
85
- self.scheme = 'http'
86
- self.host = 'api.pusherapp.com'
87
-
88
- if ENV['PUSHER_URL']
89
- self.url = ENV['PUSHER_URL']
90
- end
91
-
92
- # Return a channel by name
93
- #
94
- # @example
95
- # Pusher['my-channel']
96
- # @return [Channel]
97
- # @raise [ConfigurationError] unless key, secret and app_id have been
98
- # configured
99
- def self.[](channel_name)
100
- raise ConfigurationError, 'Missing configuration: please check that Pusher.key, Pusher.secret and Pusher.app_id are configured.' unless configured?
101
- @channels ||= {}
102
- @channels[channel_name.to_s] ||= Channel.new(url, channel_name)
103
- end
104
- end
105
-
106
- require 'pusher/channel'
107
- require 'pusher/request'
@@ -1,107 +0,0 @@
1
- require 'signature'
2
- require 'digest/md5'
3
- require 'json'
4
-
5
- module Pusher
6
- class Request
7
- def initialize(verb, uri, params, body = nil, token = nil)
8
- @verb = verb
9
- @uri = uri
10
-
11
- if body
12
- @body = body
13
- params[:body_md5] = Digest::MD5.hexdigest(body)
14
- end
15
-
16
- request = Signature::Request.new(verb.to_s.upcase, uri.path, params)
17
- auth_hash = request.sign(token || Pusher.authentication_token)
18
- @params = params.merge(auth_hash)
19
- end
20
-
21
- def send_sync
22
- require 'net/http' unless defined?(Net::HTTP)
23
- require 'net/https' if (ssl? && !defined?(Net::HTTPS))
24
-
25
- @http_sync ||= begin
26
- http = Net::HTTP.new(@uri.host, @uri.port)
27
- http.use_ssl = true if ssl?
28
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ssl?
29
- http
30
- end
31
-
32
- begin
33
- case @verb
34
- when :post
35
- response = @http_sync.post("#{@uri.path}?#{@params.to_params}",
36
- @body, { 'Content-Type'=> 'application/json' })
37
- when :get
38
- response = @http_sync.get("#{@uri.path}?#{@params.to_params}",
39
- { 'Content-Type'=> 'application/json' })
40
- else
41
- raise "Unknown verb"
42
- end
43
- rescue Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED,
44
- Errno::ETIMEDOUT, Errno::EHOSTUNREACH, Errno::ECONNRESET,
45
- Timeout::Error, EOFError,
46
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
47
- Net::ProtocolError => e
48
- error = Pusher::HTTPError.new("#{e.message} (#{e.class})")
49
- error.original_error = e
50
- raise error
51
- end
52
-
53
- return handle_response(response.code.to_i, response.body.chomp)
54
- end
55
-
56
- def send_async
57
- unless defined?(EventMachine) && EventMachine.reactor_running?
58
- raise Error, "In order to use trigger_async you must be running inside an eventmachine loop"
59
- end
60
- require 'em-http' unless defined?(EventMachine::HttpRequest)
61
-
62
- deferrable = EM::DefaultDeferrable.new
63
-
64
- http = EventMachine::HttpRequest.new(@uri).post({
65
- :query => @params, :timeout => 5, :body => @body,
66
- :head => {'Content-Type'=> 'application/json'}
67
- })
68
- http.callback {
69
- begin
70
- handle_response(http.response_header.status, http.response.chomp)
71
- deferrable.succeed
72
- rescue => e
73
- deferrable.fail(e)
74
- end
75
- }
76
- http.errback {
77
- Pusher.logger.debug("Network error connecting to pusher: #{http.inspect}")
78
- deferrable.fail(Error.new("Network error connecting to pusher"))
79
- }
80
-
81
- deferrable
82
- end
83
-
84
- private
85
-
86
- def handle_response(status_code, body)
87
- case status_code
88
- when 200
89
- return JSON.decode(body, :symbolize_keys => true)
90
- when 202
91
- return true
92
- when 400
93
- raise Error, "Bad request: #{body}"
94
- when 401
95
- raise AuthenticationError, body
96
- when 404
97
- raise Error, "Resource not found: app_id is probably invalid"
98
- else
99
- raise Error, "Unknown error (status code #{status_code}): #{body}"
100
- end
101
- end
102
-
103
- def ssl?
104
- @uri.scheme == 'https'
105
- end
106
- end
107
- end
@@ -1,274 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Pusher::Channel do
4
- before do
5
- Pusher.app_id = '20'
6
- Pusher.key = '12345678900000001'
7
- Pusher.secret = '12345678900000001'
8
- Pusher.host = 'api.pusherapp.com'
9
- Pusher.port = 80
10
- Pusher.encrypted = false
11
-
12
- WebMock.reset!
13
- WebMock.disable_net_connect!
14
-
15
- @pusher_url_regexp = %r{/apps/20/channels/test_channel/events}
16
- end
17
-
18
- after do
19
- Pusher.app_id = nil
20
- Pusher.key = nil
21
- Pusher.secret = nil
22
- end
23
-
24
- describe 'trigger!' do
25
- before :each do
26
- WebMock.stub_request(:post, @pusher_url_regexp).
27
- to_return(:status => 202)
28
- @channel = Pusher['test_channel']
29
- end
30
-
31
- it 'should configure HTTP library to talk to pusher API' do
32
- @channel.trigger!('new_event', 'Some data')
33
- WebMock.should have_requested(:post, %r{http://api.pusherapp.com})
34
- end
35
-
36
- it "should POST to https api if ssl enabled" do
37
- Pusher.encrypted = true
38
- Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
39
- WebMock.should have_requested(:post, %r{https://api.pusherapp.com})
40
- end
41
-
42
- it 'should POST hashes by encoding as JSON in the request body' do
43
- @channel.trigger!('new_event', {
44
- :name => 'Pusher',
45
- :last_name => 'App'
46
- })
47
- WebMock.should have_requested(:post, %r{/apps/20/channels/test_channel/events}).with do |req|
48
- query_hash = req.uri.query_values
49
- query_hash["name"].should == 'new_event'
50
- query_hash["auth_key"].should == Pusher.key
51
- query_hash["auth_timestamp"].should_not be_nil
52
-
53
- parsed = MultiJson.decode(req.body)
54
- parsed.should == {
55
- "name" => 'Pusher',
56
- "last_name" => 'App'
57
- }
58
-
59
- req.headers['Content-Type'].should == 'application/json'
60
- end
61
- end
62
-
63
- it "should POST string data unmodified in request body" do
64
- string = "foo\nbar\""
65
- @channel.trigger!('new_event', string)
66
- WebMock.should have_requested(:post, %r{/apps/20/channels/test_channel/events}).with do |req|
67
- req.body.should == "foo\nbar\""
68
- end
69
- end
70
-
71
- it "should catch all Net::HTTP exceptions and raise a Pusher::HTTPError, exposing the original error if required" do
72
- WebMock.stub_request(
73
- :post, %r{/apps/20/channels/test_channel/events}
74
- ).to_raise(Timeout::Error)
75
-
76
- error_raised = nil
77
- begin
78
- Pusher['test_channel'].trigger!('new_event', 'Some data')
79
- rescue => e
80
- error_raised = e
81
- end
82
- error_raised.class.should == Pusher::HTTPError
83
- error_raised.message.should == 'Exception from WebMock (Timeout::Error)'
84
- error_raised.original_error.class.should == Timeout::Error
85
- end
86
-
87
- it "should raise AuthenticationError if pusher returns 401" do
88
- WebMock.stub_request(
89
- :post,
90
- %r{/apps/20/channels/test_channel/events}
91
- ).to_return(:status => 401)
92
- lambda {
93
- Pusher['test_channel'].trigger!('new_event', 'Some data')
94
- }.should raise_error(Pusher::AuthenticationError)
95
- end
96
-
97
- it "should raise Pusher::Error if pusher returns 404" do
98
- WebMock.stub_request(
99
- :post, %r{/apps/20/channels/test_channel/events}
100
- ).to_return(:status => 404)
101
- lambda {
102
- Pusher['test_channel'].trigger!('new_event', 'Some data')
103
- }.should raise_error(Pusher::Error, 'Resource not found: app_id is probably invalid')
104
- end
105
-
106
- it "should raise Pusher::Error if pusher returns 500" do
107
- WebMock.stub_request(
108
- :post, %r{/apps/20/channels/test_channel/events}
109
- ).to_return(:status => 500, :body => "some error")
110
- lambda {
111
- Pusher['test_channel'].trigger!('new_event', 'Some data')
112
- }.should raise_error(Pusher::Error, 'Unknown error (status code 500): some error')
113
- end
114
- end
115
-
116
- describe 'trigger' do
117
- it "should log failure if error raised in Net::HTTP call" do
118
- stub_request(:post, @pusher_url_regexp).to_raise(Net::HTTPBadResponse)
119
- Pusher.logger.should_receive(:error).with("Exception from WebMock (Net::HTTPBadResponse) (Pusher::HTTPError)")
120
- Pusher.logger.should_receive(:debug) #backtrace
121
- Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
122
- end
123
-
124
- it "should log failure if Pusher returns an error response" do
125
- stub_request(:post, @pusher_url_regexp).to_return(:status => 401)
126
- # @http.should_receive(:post).and_raise(Net::HTTPBadResponse)
127
- Pusher.logger.should_receive(:error).with(" (Pusher::AuthenticationError)")
128
- Pusher.logger.should_receive(:debug) #backtrace
129
- Pusher::Channel.new(Pusher.url, 'test_channel').trigger('new_event', 'Some data')
130
- end
131
- end
132
-
133
- describe "trigger_async" do
134
- it "should by default POST to http api" do
135
- EM.run {
136
- stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
137
- channel = Pusher::Channel.new(Pusher.url, 'test_channel')
138
- channel.trigger_async('new_event', 'Some data').callback {
139
- WebMock.should have_requested(:post, %r{http://api.pusherapp.com})
140
- EM.stop
141
- }
142
- }
143
- end
144
-
145
- it "should POST to https api if ssl enabled" do
146
- Pusher.encrypted = true
147
- EM.run {
148
- stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
149
- channel = Pusher::Channel.new(Pusher.url, 'test_channel')
150
- channel.trigger_async('new_event', 'Some data').callback {
151
- WebMock.should have_requested(:post, %r{https://api.pusherapp.com})
152
- EM.stop
153
- }
154
- }
155
- end
156
-
157
- it "should return a deferrable which succeeds in success case" do
158
- stub_request(:post, @pusher_url_regexp).to_return(:status => 202)
159
-
160
- EM.run {
161
- d = Pusher['test_channel'].trigger_async('new_event', 'Some data')
162
- d.callback {
163
- WebMock.should have_requested(:post, @pusher_url_regexp)
164
- EM.stop
165
- }
166
- d.errback {
167
- fail
168
- EM.stop
169
- }
170
- }
171
- end
172
-
173
- it "should return a deferrable which fails (with exception) in fail case" do
174
- stub_request(:post, @pusher_url_regexp).to_return(:status => 401)
175
-
176
- EM.run {
177
- d = Pusher['test_channel'].trigger_async('new_event', 'Some data')
178
- d.callback {
179
- fail
180
- }
181
- d.errback { |error|
182
- WebMock.should have_requested(:post, @pusher_url_regexp)
183
- error.should be_kind_of(Pusher::AuthenticationError)
184
- EM.stop
185
- }
186
- }
187
- end
188
- end
189
-
190
- describe "stats" do
191
- before :each do
192
- @api_path = %r{/apps/20/channels/presence-test_channel/stats}
193
- end
194
-
195
- it "should call the user_count api" do
196
- WebMock.stub_request(:get, @api_path).to_return({
197
- :status => 200,
198
- :body => JSON.generate(:user_count => 1)
199
- })
200
- @channel = Pusher['presence-test_channel']
201
-
202
- @channel.stats.should == {
203
- :user_count => 1
204
- }
205
- end
206
- end
207
-
208
- describe "socket_auth" do
209
- before :each do
210
- @channel = Pusher['test_channel']
211
- end
212
-
213
- it "should return an authentication string given a socket id" do
214
- auth = @channel.socket_auth('socketid')
215
-
216
- auth.should == '12345678900000001:827076f551e22451357939e4c7bb1200de29f921d5bf80b40d71668f9cd61c40'
217
- end
218
-
219
- it "should raise error if authentication is invalid" do
220
- [nil, ''].each do |invalid|
221
- lambda {
222
- @channel.socket_auth(invalid)
223
- }.should raise_error
224
- end
225
- end
226
-
227
- describe 'with extra string argument' do
228
-
229
- it 'should be a string or nil' do
230
- lambda {
231
- @channel.socket_auth('socketid', 'boom')
232
- }.should_not raise_error
233
-
234
- lambda {
235
- @channel.socket_auth('socketid', 123)
236
- }.should raise_error
237
-
238
- lambda {
239
- @channel.socket_auth('socketid', nil)
240
- }.should_not raise_error
241
-
242
- lambda {
243
- @channel.socket_auth('socketid', {})
244
- }.should raise_error
245
- end
246
-
247
- it "should return an authentication string given a socket id and custom args" do
248
- auth = @channel.socket_auth('socketid', 'foobar')
249
-
250
- auth.should == "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:foobar")}"
251
- end
252
-
253
- end
254
- end
255
-
256
- describe '#authenticate' do
257
-
258
- before :each do
259
- @channel = Pusher['test_channel']
260
- @custom_data = {:uid => 123, :info => {:name => 'Foo'}}
261
- end
262
-
263
- it 'should return a hash with signature including custom data and data as json string' do
264
- MultiJson.stub!(:encode).with(@custom_data).and_return 'a json string'
265
-
266
- response = @channel.authenticate('socketid', @custom_data)
267
-
268
- response.should == {
269
- :auth => "12345678900000001:#{HMAC::SHA256.hexdigest(Pusher.secret, "socketid:test_channel:a json string")}",
270
- :channel_data => 'a json string'
271
- }
272
- end
273
- end
274
- end