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.
- data/CHANGELOG.markdown +5 -0
- data/lib/scout/command/run.rb +1 -1
- data/lib/scout/server.rb +2 -1
- data/lib/scout/streamer.rb +3 -2
- data/lib/scout/streamer_daemon.rb +4 -4
- data/lib/scout/version.rb +1 -1
- data/test/scout_test.rb +7 -8
- data/vendor/httpclient/README.txt +759 -0
- data/vendor/httpclient/bin/httpclient +65 -0
- data/vendor/httpclient/lib/hexdump.rb +50 -0
- data/vendor/httpclient/lib/http-access2.rb +55 -0
- data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
- data/vendor/httpclient/lib/http-access2/http.rb +1 -0
- data/vendor/httpclient/lib/httpclient.rb +1156 -0
- data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
- data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
- data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
- data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
- data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
- data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
- data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
- data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
- data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
- data/vendor/httpclient/lib/httpclient/util.rb +178 -0
- data/vendor/httpclient/lib/httpclient/version.rb +3 -0
- data/vendor/httpclient/lib/oauthclient.rb +110 -0
- data/vendor/httpclient/sample/async.rb +8 -0
- data/vendor/httpclient/sample/auth.rb +11 -0
- data/vendor/httpclient/sample/cookie.rb +18 -0
- data/vendor/httpclient/sample/dav.rb +103 -0
- data/vendor/httpclient/sample/howto.rb +49 -0
- data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
- data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
- data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
- data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
- data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
- data/vendor/httpclient/sample/ssl/0key.pem +30 -0
- data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
- data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
- data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
- data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
- data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
- data/vendor/httpclient/sample/stream.rb +21 -0
- data/vendor/httpclient/sample/thread.rb +27 -0
- data/vendor/httpclient/sample/wcat.rb +21 -0
- data/vendor/httpclient/test/ca-chain.cert +44 -0
- data/vendor/httpclient/test/ca.cert +23 -0
- data/vendor/httpclient/test/client.cert +19 -0
- data/vendor/httpclient/test/client.key +15 -0
- data/vendor/httpclient/test/helper.rb +129 -0
- data/vendor/httpclient/test/htdigest +1 -0
- data/vendor/httpclient/test/htpasswd +2 -0
- data/vendor/httpclient/test/runner.rb +2 -0
- data/vendor/httpclient/test/server.cert +19 -0
- data/vendor/httpclient/test/server.key +15 -0
- data/vendor/httpclient/test/sslsvr.rb +65 -0
- data/vendor/httpclient/test/subca.cert +21 -0
- data/vendor/httpclient/test/test_auth.rb +321 -0
- data/vendor/httpclient/test/test_cookie.rb +391 -0
- data/vendor/httpclient/test/test_hexdump.rb +14 -0
- data/vendor/httpclient/test/test_http-access2.rb +507 -0
- data/vendor/httpclient/test/test_httpclient.rb +1783 -0
- data/vendor/httpclient/test/test_include_client.rb +52 -0
- data/vendor/httpclient/test/test_ssl.rb +235 -0
- data/vendor/multi_json/.document +5 -0
- data/vendor/multi_json/.rspec +3 -0
- data/vendor/multi_json/.travis.yml +11 -0
- data/vendor/multi_json/.yardopts +6 -0
- data/vendor/multi_json/CHANGELOG.md +169 -0
- data/vendor/multi_json/CONTRIBUTING.md +46 -0
- data/vendor/multi_json/Gemfile +31 -0
- data/vendor/multi_json/LICENSE.md +20 -0
- data/vendor/multi_json/README.md +109 -0
- data/vendor/multi_json/Rakefile +12 -0
- data/vendor/multi_json/lib/multi_json.rb +157 -0
- data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
- data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
- data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
- data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
- data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
- data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
- data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
- data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
- data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
- data/vendor/multi_json/lib/multi_json/options.rb +48 -0
- data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
- data/vendor/multi_json/lib/multi_json/version.rb +20 -0
- data/vendor/multi_json/multi_json.gemspec +22 -0
- data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
- data/vendor/multi_json/spec/has_options.rb +119 -0
- data/vendor/multi_json/spec/helper.rb +35 -0
- data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
- data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
- data/vendor/{signature → pusher}/.document +0 -0
- data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
- data/vendor/pusher/.gitignore +23 -0
- data/vendor/pusher/.travis.yml +15 -0
- data/vendor/pusher/Gemfile +2 -0
- data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
- data/vendor/pusher/README.md +186 -0
- data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
- data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
- data/vendor/pusher/lib/pusher.rb +60 -0
- data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
- data/vendor/pusher/lib/pusher/client.rb +306 -0
- data/vendor/pusher/lib/pusher/request.rb +107 -0
- data/vendor/pusher/lib/pusher/resource.rb +36 -0
- data/vendor/pusher/lib/pusher/webhook.rb +110 -0
- data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
- data/vendor/pusher/spec/channel_spec.rb +127 -0
- data/vendor/pusher/spec/client_spec.rb +464 -0
- data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
- data/vendor/pusher/spec/web_hook_spec.rb +117 -0
- data/vendor/signature/.travis.yml +15 -0
- data/vendor/signature/Gemfile +1 -1
- data/vendor/signature/README.md +38 -28
- data/vendor/signature/lib/signature.rb +97 -15
- data/vendor/signature/lib/signature/query_encoder.rb +47 -0
- data/vendor/signature/lib/signature/version.rb +1 -1
- data/vendor/signature/signature.gemspec +3 -2
- data/vendor/signature/spec/signature_spec.rb +164 -55
- data/vendor/signature/spec/spec_helper.rb +2 -3
- metadata +120 -145
- data/vendor/json_pure/.gitignore +0 -12
- data/vendor/json_pure/.travis.yml +0 -20
- data/vendor/json_pure/CHANGES +0 -282
- data/vendor/json_pure/COPYING +0 -58
- data/vendor/json_pure/COPYING-json-jruby +0 -57
- data/vendor/json_pure/GPL +0 -340
- data/vendor/json_pure/Gemfile +0 -11
- data/vendor/json_pure/README-json-jruby.markdown +0 -33
- data/vendor/json_pure/README.rdoc +0 -358
- data/vendor/json_pure/Rakefile +0 -412
- data/vendor/json_pure/TODO +0 -1
- data/vendor/json_pure/VERSION +0 -1
- data/vendor/json_pure/data/example.json +0 -1
- data/vendor/json_pure/data/index.html +0 -38
- data/vendor/json_pure/data/prototype.js +0 -4184
- data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
- data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
- data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
- data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
- data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
- data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
- data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
- data/vendor/json_pure/install.rb +0 -23
- data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
- data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
- data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
- data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
- data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
- data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
- data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
- data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
- data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
- data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
- data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
- data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
- data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
- data/vendor/json_pure/json-java.gemspec +0 -23
- data/vendor/json_pure/json.gemspec +0 -37
- data/vendor/json_pure/json_pure.gemspec +0 -39
- data/vendor/json_pure/lib/json.rb +0 -62
- data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
- data/vendor/json_pure/lib/json/add/complex.rb +0 -22
- data/vendor/json_pure/lib/json/add/core.rb +0 -11
- data/vendor/json_pure/lib/json/add/date.rb +0 -34
- data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
- data/vendor/json_pure/lib/json/add/exception.rb +0 -31
- data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
- data/vendor/json_pure/lib/json/add/range.rb +0 -29
- data/vendor/json_pure/lib/json/add/rational.rb +0 -22
- data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
- data/vendor/json_pure/lib/json/add/struct.rb +0 -30
- data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
- data/vendor/json_pure/lib/json/add/time.rb +0 -38
- data/vendor/json_pure/lib/json/common.rb +0 -487
- data/vendor/json_pure/lib/json/ext.rb +0 -21
- data/vendor/json_pure/lib/json/ext/.keep +0 -0
- data/vendor/json_pure/lib/json/generic_object.rb +0 -70
- data/vendor/json_pure/lib/json/pure.rb +0 -21
- data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
- data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
- data/vendor/json_pure/lib/json/version.rb +0 -8
- data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
- data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
- data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
- data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
- data/vendor/json_pure/tests/setup_variant.rb +0 -11
- data/vendor/json_pure/tests/test_json.rb +0 -545
- data/vendor/json_pure/tests/test_json_addition.rb +0 -196
- data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
- data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
- data/vendor/json_pure/tests/test_json_generate.rb +0 -322
- data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
- data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
- data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
- data/vendor/json_pure/tools/fuzz.rb +0 -139
- data/vendor/json_pure/tools/server.rb +0 -62
- data/vendor/pusher-gem/Gemfile +0 -2
- data/vendor/pusher-gem/README.md +0 -80
- data/vendor/pusher-gem/lib/pusher.rb +0 -107
- data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
- data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
- data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
- data/vendor/ruby-hmac/History.txt +0 -15
- data/vendor/ruby-hmac/Manifest.txt +0 -11
- data/vendor/ruby-hmac/README.md +0 -41
- data/vendor/ruby-hmac/Rakefile +0 -23
- data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
- data/vendor/ruby-hmac/lib/hmac.rb +0 -118
- data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
- data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
- data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
- data/vendor/signature/VERSION +0 -1
File without changes
|
File without changes
|
@@ -0,0 +1,60 @@
|
|
1
|
+
autoload 'Logger', 'logger'
|
2
|
+
require 'uri'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
require 'pusher/client'
|
6
|
+
|
7
|
+
# Used for configuring API credentials and creating Channel objects
|
8
|
+
#
|
9
|
+
module Pusher
|
10
|
+
# All errors descend from this class so they can be easily rescued
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# begin
|
14
|
+
# Pusher.trigger('channel_name', 'event_name, {:some => 'data'})
|
15
|
+
# rescue Pusher::Error => e
|
16
|
+
# # Do something on error
|
17
|
+
# end
|
18
|
+
class Error < RuntimeError; end
|
19
|
+
class AuthenticationError < Error; end
|
20
|
+
class ConfigurationError < Error; end
|
21
|
+
class HTTPError < Error; attr_accessor :original_error; end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
extend Forwardable
|
25
|
+
|
26
|
+
def_delegators :default_client, :scheme, :host, :port, :app_id, :key, :secret, :http_proxy
|
27
|
+
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
|
28
|
+
|
29
|
+
def_delegators :default_client, :authentication_token, :url
|
30
|
+
def_delegators :default_client, :encrypted=, :url=
|
31
|
+
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
|
32
|
+
|
33
|
+
def_delegators :default_client, :get, :get_async, :post, :post_async
|
34
|
+
def_delegators :default_client, :channels, :channel_info, :trigger, :trigger_async
|
35
|
+
def_delegators :default_client, :webhook, :channel, :[]
|
36
|
+
|
37
|
+
attr_writer :logger
|
38
|
+
|
39
|
+
def logger
|
40
|
+
@logger ||= begin
|
41
|
+
log = Logger.new($stdout)
|
42
|
+
log.level = Logger::INFO
|
43
|
+
log
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def default_client
|
48
|
+
@default_client ||= Pusher::Client.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if ENV['PUSHER_URL']
|
53
|
+
self.url = ENV['PUSHER_URL']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'pusher/channel'
|
58
|
+
require 'pusher/request'
|
59
|
+
require 'pusher/resource'
|
60
|
+
require 'pusher/webhook'
|
@@ -1,20 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'json'
|
1
|
+
require 'openssl'
|
2
|
+
require 'multi_json'
|
4
3
|
|
5
4
|
module Pusher
|
6
5
|
# Trigger events on Channels
|
7
6
|
class Channel
|
8
7
|
attr_reader :name
|
9
8
|
|
10
|
-
def initialize(base_url, name)
|
9
|
+
def initialize(base_url, name, client = Pusher)
|
11
10
|
@uri = base_url.dup
|
12
11
|
@uri.path = @uri.path + "/channels/#{name}/"
|
13
12
|
@name = name
|
13
|
+
@client = client
|
14
14
|
end
|
15
15
|
|
16
16
|
# Trigger event asynchronously using EventMachine::HttpRequest
|
17
17
|
#
|
18
|
+
# [Deprecated] This method will be removed in a future gem version. Please
|
19
|
+
# switch to Pusher.trigger_async or Pusher::Client#trigger_async instead
|
20
|
+
#
|
18
21
|
# @param (see #trigger!)
|
19
22
|
# @return [EM::DefaultDeferrable]
|
20
23
|
# Attach a callback to be notified of success (with no parameters).
|
@@ -24,13 +27,17 @@ module Pusher
|
|
24
27
|
# @raise [Pusher::Error] unless the eventmachine reactor is running. You
|
25
28
|
# probably want to run your application inside a server such as thin
|
26
29
|
#
|
27
|
-
def trigger_async(event_name, data, socket_id = nil
|
28
|
-
|
29
|
-
|
30
|
+
def trigger_async(event_name, data, socket_id = nil)
|
31
|
+
params = {}
|
32
|
+
params[:socket_id] = socket_id if socket_id
|
33
|
+
@client.trigger_async(name, event_name, data, params)
|
30
34
|
end
|
31
35
|
|
32
36
|
# Trigger event
|
33
37
|
#
|
38
|
+
# [Deprecated] This method will be removed in a future gem version. Please
|
39
|
+
# switch to Pusher.trigger or Pusher::Client#trigger instead
|
40
|
+
#
|
34
41
|
# @example
|
35
42
|
# begin
|
36
43
|
# Pusher['my-channel'].trigger!('an_event', {:some => 'data'})
|
@@ -44,15 +51,19 @@ module Pusher
|
|
44
51
|
# event - see http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients for more info
|
45
52
|
#
|
46
53
|
# @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
|
47
|
-
# @raise [Pusher::HTTPError] on any error raised inside
|
54
|
+
# @raise [Pusher::HTTPError] on any error raised inside http client - the original error is available in the original_error attribute
|
48
55
|
#
|
49
56
|
def trigger!(event_name, data, socket_id = nil)
|
50
|
-
|
51
|
-
|
57
|
+
params = {}
|
58
|
+
params[:socket_id] = socket_id if socket_id
|
59
|
+
@client.trigger(name, event_name, data, params)
|
52
60
|
end
|
53
61
|
|
54
62
|
# Trigger event, catching and logging any errors.
|
55
63
|
#
|
64
|
+
# [Deprecated] This method will be removed in a future gem version. Please
|
65
|
+
# switch to Pusher.trigger or Pusher::Client#trigger instead
|
66
|
+
#
|
56
67
|
# @note CAUTION! No exceptions will be raised on failure
|
57
68
|
# @param (see #trigger!)
|
58
69
|
#
|
@@ -62,21 +73,21 @@ module Pusher
|
|
62
73
|
Pusher.logger.error("#{e.message} (#{e.class})")
|
63
74
|
Pusher.logger.debug(e.backtrace.join("\n"))
|
64
75
|
end
|
65
|
-
|
66
|
-
# Request channel
|
76
|
+
|
77
|
+
# Request info for a channel
|
67
78
|
#
|
68
|
-
# @
|
79
|
+
# @param info [Array] Array of attributes required (as lowercase strings)
|
80
|
+
# @return [Hash] Hash of requested attributes for this channel
|
69
81
|
# @raise [Pusher::Error] on invalid Pusher response - see the error message for more details
|
70
|
-
# @raise [Pusher::HTTPError] on any error raised inside
|
82
|
+
# @raise [Pusher::HTTPError] on any error raised inside http client - the original error is available in the original_error attribute
|
71
83
|
#
|
72
|
-
def
|
73
|
-
|
74
|
-
return request.send_sync
|
84
|
+
def info(attributes = [])
|
85
|
+
@client.get("/channels/#{name}", :info => attributes.join(','))
|
75
86
|
end
|
76
87
|
|
77
|
-
# Compute authentication string required
|
78
|
-
#
|
79
|
-
#
|
88
|
+
# Compute authentication string required as part of the authentication
|
89
|
+
# endpoint response. Generally the authenticate method should be used in
|
90
|
+
# preference to this one
|
80
91
|
#
|
81
92
|
# @param socket_id [String] Each Pusher socket connection receives a
|
82
93
|
# unique socket_id. This is sent from pusher.js to your server when
|
@@ -85,21 +96,26 @@ module Pusher
|
|
85
96
|
# @return [String]
|
86
97
|
#
|
87
98
|
def authentication_string(socket_id, custom_string = nil)
|
88
|
-
|
89
|
-
|
99
|
+
if socket_id.nil? || socket_id.empty?
|
100
|
+
raise Error, "Invalid socket_id #{socket_id}"
|
101
|
+
end
|
90
102
|
|
91
|
-
|
103
|
+
unless custom_string.nil? || custom_string.kind_of?(String)
|
104
|
+
raise Error, 'Custom argument must be a string'
|
105
|
+
end
|
106
|
+
|
107
|
+
string_to_sign = [socket_id, name, custom_string].
|
108
|
+
compact.map(&:to_s).join(':')
|
92
109
|
Pusher.logger.debug "Signing #{string_to_sign}"
|
93
|
-
token =
|
94
|
-
|
110
|
+
token = @client.authentication_token
|
111
|
+
digest = OpenSSL::Digest::SHA256.new
|
112
|
+
signature = OpenSSL::HMAC.hexdigest(digest, token.secret, string_to_sign)
|
95
113
|
|
96
114
|
return "#{token.key}:#{signature}"
|
97
115
|
end
|
98
|
-
|
99
|
-
# Deprecated - for backward compatibility
|
100
|
-
alias :socket_auth :authentication_string
|
101
116
|
|
102
|
-
# Generate an authentication endpoint
|
117
|
+
# Generate the expected response for an authentication endpoint.
|
118
|
+
# See http://pusher.com/docs/authenticating_users for details.
|
103
119
|
#
|
104
120
|
# @example Private channels
|
105
121
|
# render :json => Pusher['private-my_channel'].authenticate(params[:socket_id])
|
@@ -121,34 +137,11 @@ module Pusher
|
|
121
137
|
# @private Custom data is sent to server as JSON-encoded string
|
122
138
|
#
|
123
139
|
def authenticate(socket_id, custom_data = nil)
|
124
|
-
custom_data = custom_data
|
125
|
-
auth =
|
140
|
+
custom_data = MultiJson.encode(custom_data) if custom_data
|
141
|
+
auth = authentication_string(socket_id, custom_data)
|
126
142
|
r = {:auth => auth}
|
127
143
|
r[:channel_data] = custom_data if custom_data
|
128
144
|
r
|
129
145
|
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def construct_event_request(event_name, data, socket_id)
|
134
|
-
params = {
|
135
|
-
:name => event_name,
|
136
|
-
}
|
137
|
-
params[:socket_id] = socket_id if socket_id
|
138
|
-
|
139
|
-
body = case data
|
140
|
-
when String
|
141
|
-
data
|
142
|
-
else
|
143
|
-
begin
|
144
|
-
data.to_json
|
145
|
-
rescue Exception => e
|
146
|
-
Pusher.logger.error("Could not convert #{data.inspect} into JSON")
|
147
|
-
raise e
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
Pusher::Request.new(:post, @uri + 'events', params, body)
|
152
|
-
end
|
153
146
|
end
|
154
147
|
end
|
@@ -0,0 +1,306 @@
|
|
1
|
+
require 'signature'
|
2
|
+
|
3
|
+
module Pusher
|
4
|
+
class Client
|
5
|
+
attr_accessor :scheme, :host, :port, :app_id, :key, :secret
|
6
|
+
attr_reader :http_proxy, :proxy
|
7
|
+
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
|
8
|
+
:keep_alive_timeout
|
9
|
+
|
10
|
+
## CONFIGURATION ##
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
options = {
|
14
|
+
:scheme => 'http',
|
15
|
+
:host => 'api.pusherapp.com',
|
16
|
+
:port => 80,
|
17
|
+
}.merge(options)
|
18
|
+
@scheme, @host, @port, @app_id, @key, @secret = options.values_at(
|
19
|
+
:scheme, :host, :port, :app_id, :key, :secret
|
20
|
+
)
|
21
|
+
@http_proxy = nil
|
22
|
+
self.http_proxy = options[:http_proxy] if options[:http_proxy]
|
23
|
+
|
24
|
+
# Default timeouts
|
25
|
+
@connect_timeout = 5
|
26
|
+
@send_timeout = 5
|
27
|
+
@receive_timeout = 5
|
28
|
+
@keep_alive_timeout = 30
|
29
|
+
end
|
30
|
+
|
31
|
+
# @private Returns the authentication token for the client
|
32
|
+
def authentication_token
|
33
|
+
Signature::Token.new(@key, @secret)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @private Builds a url for this app, optionally appending a path
|
37
|
+
def url(path = nil)
|
38
|
+
URI::Generic.build({
|
39
|
+
:scheme => @scheme,
|
40
|
+
:host => @host,
|
41
|
+
:port => @port,
|
42
|
+
:path => "/apps/#{@app_id}#{path}"
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
# Configure Pusher connection by providing a url rather than specifying
|
47
|
+
# scheme, key, secret, and app_id separately.
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# Pusher.url = http://KEY:SECRET@api.pusherapp.com/apps/APP_ID
|
51
|
+
#
|
52
|
+
def url=(url)
|
53
|
+
uri = URI.parse(url)
|
54
|
+
@scheme = uri.scheme
|
55
|
+
@app_id = uri.path.split('/').last
|
56
|
+
@key = uri.user
|
57
|
+
@secret = uri.password
|
58
|
+
@host = uri.host
|
59
|
+
@port = uri.port
|
60
|
+
end
|
61
|
+
|
62
|
+
def http_proxy=(http_proxy)
|
63
|
+
@http_proxy = http_proxy
|
64
|
+
uri = URI.parse(http_proxy)
|
65
|
+
@proxy = {
|
66
|
+
:scheme => uri.scheme,
|
67
|
+
:host => uri.host,
|
68
|
+
:port => uri.port,
|
69
|
+
:user => uri.user,
|
70
|
+
:password => uri.password
|
71
|
+
}
|
72
|
+
@http_proxy
|
73
|
+
end
|
74
|
+
|
75
|
+
# Configure whether Pusher API calls should be made over SSL
|
76
|
+
# (default false)
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# Pusher.encrypted = true
|
80
|
+
#
|
81
|
+
def encrypted=(boolean)
|
82
|
+
@scheme = boolean ? 'https' : 'http'
|
83
|
+
# Configure port if it hasn't already been configured
|
84
|
+
@port = boolean ? 443 : 80
|
85
|
+
end
|
86
|
+
|
87
|
+
def encrypted?
|
88
|
+
@scheme == 'https'
|
89
|
+
end
|
90
|
+
|
91
|
+
# Convenience method to set all timeouts to the same value (in seconds).
|
92
|
+
# For more control, use the individual writers.
|
93
|
+
def timeout=(value)
|
94
|
+
@connect_timeout, @send_timeout, @receive_timeout = value, value, value
|
95
|
+
end
|
96
|
+
|
97
|
+
## INTERACE WITH THE API ##
|
98
|
+
|
99
|
+
def resource(path)
|
100
|
+
Resource.new(self, path)
|
101
|
+
end
|
102
|
+
|
103
|
+
# GET arbitrary REST API resource using a synchronous http client.
|
104
|
+
# All request signing is handled automatically.
|
105
|
+
#
|
106
|
+
# @example
|
107
|
+
# begin
|
108
|
+
# Pusher.get('/channels', filter_by_prefix: 'private-')
|
109
|
+
# rescue Pusher::Error => e
|
110
|
+
# # Handle error
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# @param path [String] Path excluding /apps/APP_ID
|
114
|
+
# @param params [Hash] API params (see http://pusher.com/docs/rest_api)
|
115
|
+
#
|
116
|
+
# @return [Hash] See Pusher API docs
|
117
|
+
#
|
118
|
+
# @raise [Pusher::Error] Unsuccessful response - see the error message
|
119
|
+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
120
|
+
#
|
121
|
+
def get(path, params = {})
|
122
|
+
Resource.new(self, path).get(params)
|
123
|
+
end
|
124
|
+
|
125
|
+
# GET arbitrary REST API resource using an asynchronous http client.
|
126
|
+
# All request signing is handled automatically.
|
127
|
+
#
|
128
|
+
# When the eventmachine reactor is running, the em-http-request gem is used;
|
129
|
+
# otherwise an async request is made using httpclient. See README for
|
130
|
+
# details and examples.
|
131
|
+
#
|
132
|
+
# @param path [String] Path excluding /apps/APP_ID
|
133
|
+
# @param params [Hash] API params (see http://pusher.com/docs/rest_api)
|
134
|
+
#
|
135
|
+
# @return Either an EM::DefaultDeferrable or a HTTPClient::Connection
|
136
|
+
#
|
137
|
+
def get_async(path, params = {})
|
138
|
+
Resource.new(self, path).get_async(params)
|
139
|
+
end
|
140
|
+
|
141
|
+
# POST arbitrary REST API resource using a synchronous http client.
|
142
|
+
# Works identially to get method, but posts params as JSON in post body.
|
143
|
+
def post(path, params = {})
|
144
|
+
Resource.new(self, path).post(params)
|
145
|
+
end
|
146
|
+
|
147
|
+
# POST arbitrary REST API resource using an asynchronous http client.
|
148
|
+
# Works identially to get_async method, but posts params as JSON in post
|
149
|
+
# body.
|
150
|
+
def post_async(path, params = {})
|
151
|
+
Resource.new(self, path).post_async(params)
|
152
|
+
end
|
153
|
+
|
154
|
+
## HELPER METHODS ##
|
155
|
+
|
156
|
+
# Convenience method for creating a new WebHook instance for validating
|
157
|
+
# and extracting info from a received WebHook
|
158
|
+
#
|
159
|
+
# @param request [Rack::Request] Either a Rack::Request or a Hash containing :key, :signature, :body, and optionally :content_type.
|
160
|
+
#
|
161
|
+
def webhook(request)
|
162
|
+
WebHook.new(request, self)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Return a convenience channel object by name. No API request is made.
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# Pusher['my-channel']
|
169
|
+
# @return [Channel]
|
170
|
+
# @raise [ConfigurationError] unless key, secret and app_id have been
|
171
|
+
# configured
|
172
|
+
def channel(channel_name)
|
173
|
+
raise ConfigurationError, 'Missing client configuration: please check that key, secret and app_id are configured.' unless configured?
|
174
|
+
Channel.new(url, channel_name, self)
|
175
|
+
end
|
176
|
+
|
177
|
+
alias :[] :channel
|
178
|
+
|
179
|
+
# Request a list of occupied channels from the API
|
180
|
+
#
|
181
|
+
# GET /apps/[id]/channels
|
182
|
+
#
|
183
|
+
# @param params [Hash] Hash of parameters for the API - see REST API docs
|
184
|
+
#
|
185
|
+
# @return [Hash] See Pusher API docs
|
186
|
+
#
|
187
|
+
# @raise [Pusher::Error] Unsuccessful response - see the error message
|
188
|
+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
189
|
+
#
|
190
|
+
def channels(params = {})
|
191
|
+
get('/channels', params)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Request info for a specific channel
|
195
|
+
#
|
196
|
+
# GET /apps/[id]/channels/[channel_name]
|
197
|
+
#
|
198
|
+
# @param channel_name [String] Channel name
|
199
|
+
# @param params [Hash] Hash of parameters for the API - see REST API docs
|
200
|
+
#
|
201
|
+
# @return [Hash] See Pusher API docs
|
202
|
+
#
|
203
|
+
# @raise [Pusher::Error] Unsuccessful response - see the error message
|
204
|
+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
205
|
+
#
|
206
|
+
def channel_info(channel_name, params = {})
|
207
|
+
get("/channels/#{channel_name}", params)
|
208
|
+
end
|
209
|
+
|
210
|
+
# Trigger an event on one or more channels
|
211
|
+
#
|
212
|
+
# POST /apps/[app_id]/events
|
213
|
+
#
|
214
|
+
# @param channels [String or Array] One of more channel names
|
215
|
+
# @param event_name [String]
|
216
|
+
# @param data [Object] Event data to be triggered in javascript.
|
217
|
+
# Objects other than strings will be converted to JSON
|
218
|
+
# @param params [Hash] Additional parameters to send to api, e.g socket_id
|
219
|
+
#
|
220
|
+
# @return [Hash] See Pusher API docs
|
221
|
+
#
|
222
|
+
# @raise [Pusher::Error] Unsuccessful response - see the error message
|
223
|
+
# @raise [Pusher::HTTPError] Error raised inside http client. The original error is wrapped in error.original_error
|
224
|
+
#
|
225
|
+
def trigger(channels, event_name, data, params = {})
|
226
|
+
post('/events', trigger_params(channels, event_name, data, params))
|
227
|
+
end
|
228
|
+
|
229
|
+
# Trigger an event on one or more channels asynchronously.
|
230
|
+
# For parameters see #trigger
|
231
|
+
#
|
232
|
+
def trigger_async(channels, event_name, data, params = {})
|
233
|
+
post_async('/events', trigger_params(channels, event_name, data, params))
|
234
|
+
end
|
235
|
+
|
236
|
+
# @private Construct a net/http http client
|
237
|
+
def sync_http_client
|
238
|
+
@client ||= begin
|
239
|
+
require 'httpclient'
|
240
|
+
|
241
|
+
HTTPClient.new(@http_proxy).tap do |c|
|
242
|
+
c.connect_timeout = @connect_timeout
|
243
|
+
c.send_timeout = @send_timeout
|
244
|
+
c.receive_timeout = @receive_timeout
|
245
|
+
c.keep_alive_timeout = @keep_alive_timeout
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# @private Construct an em-http-request http client
|
251
|
+
def em_http_client(uri)
|
252
|
+
begin
|
253
|
+
unless defined?(EventMachine) && EventMachine.reactor_running?
|
254
|
+
raise Error, "In order to use async calling you must be running inside an eventmachine loop"
|
255
|
+
end
|
256
|
+
require 'em-http' unless defined?(EventMachine::HttpRequest)
|
257
|
+
|
258
|
+
connection_opts = {
|
259
|
+
:connect_timeout => @connect_timeout,
|
260
|
+
:inactivity_timeout => @receive_timeout,
|
261
|
+
}
|
262
|
+
|
263
|
+
if defined?(@proxy)
|
264
|
+
proxy_opts = {
|
265
|
+
:host => @proxy[:host],
|
266
|
+
:port => @proxy[:port]
|
267
|
+
}
|
268
|
+
if @proxy[:user]
|
269
|
+
proxy_opts[:authorization] = [@proxy[:user], @proxy[:password]]
|
270
|
+
end
|
271
|
+
connection_opts[:proxy] = proxy_opts
|
272
|
+
end
|
273
|
+
|
274
|
+
EventMachine::HttpRequest.new(uri, connection_opts)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
private
|
279
|
+
|
280
|
+
def trigger_params(channels, event_name, data, params)
|
281
|
+
channels = Array(channels).map(&:to_s)
|
282
|
+
|
283
|
+
encoded_data = case data
|
284
|
+
when String
|
285
|
+
data
|
286
|
+
else
|
287
|
+
begin
|
288
|
+
MultiJson.encode(data)
|
289
|
+
rescue MultiJson::DecodeError => e
|
290
|
+
Pusher.logger.error("Could not convert #{data.inspect} into JSON")
|
291
|
+
raise e
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
return params.merge({
|
296
|
+
:name => event_name,
|
297
|
+
:channels => channels,
|
298
|
+
:data => encoded_data,
|
299
|
+
})
|
300
|
+
end
|
301
|
+
|
302
|
+
def configured?
|
303
|
+
host && scheme && key && secret && app_id
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|