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
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'adapter_shared_example'
|
3
|
+
require 'json_common_shared_example'
|
4
|
+
require 'has_options'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
describe 'MultiJson' do
|
8
|
+
context 'adapters' do
|
9
|
+
before{ MultiJson.use nil }
|
10
|
+
|
11
|
+
context 'when no other json implementations are available' do
|
12
|
+
before do
|
13
|
+
@old_map = MultiJson::REQUIREMENT_MAP
|
14
|
+
@old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
|
15
|
+
@old_oj = Object.const_get :Oj if Object.const_defined?(:Oj)
|
16
|
+
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
|
17
|
+
@old_gson = Object.const_get :Gson if Object.const_defined?(:Gson)
|
18
|
+
@old_jrjackson = Object.const_get :JrJackson if Object.const_defined?(:JrJackson)
|
19
|
+
|
20
|
+
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
|
21
|
+
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
|
22
|
+
end
|
23
|
+
Object.send :remove_const, :JSON if instance_variable_defined?(:@old_json)
|
24
|
+
Object.send :remove_const, :Oj if instance_variable_defined?(:@old_oj)
|
25
|
+
Object.send :remove_const, :Yajl if instance_variable_defined?(:@old_yajl)
|
26
|
+
Object.send :remove_const, :Gson if instance_variable_defined?(:@old_gson)
|
27
|
+
Object.send :remove_const, :JrJackson if instance_variable_defined?(:@old_jrjackson)
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
@old_map.each_with_index do |(library, adapter), index|
|
32
|
+
MultiJson::REQUIREMENT_MAP[index] = [library, adapter]
|
33
|
+
end
|
34
|
+
Object.const_set :JSON, @old_json if instance_variable_defined?(:@old_json)
|
35
|
+
Object.const_set :Oj, @old_oj if instance_variable_defined?(:@old_oj)
|
36
|
+
Object.const_set :Yajl, @old_yajl if instance_variable_defined?(:@old_yajl)
|
37
|
+
Object.const_set :Gson, @old_gson if instance_variable_defined?(:@old_gson)
|
38
|
+
Object.const_set :JrJackson, @old_jrjackson if instance_variable_defined?(:@old_jrjackson)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'defaults to ok_json if no other json implementions are available' do
|
42
|
+
silence_warnings do
|
43
|
+
expect(MultiJson.default_adapter).to eq :ok_json
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'prints a warning' do
|
48
|
+
expect(Kernel).to receive(:warn).with(/warning/i)
|
49
|
+
MultiJson.default_adapter
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'caching' do
|
54
|
+
before{ MultiJson.use adapter }
|
55
|
+
let(:adapter){ MultiJson::Adapters::JsonGem }
|
56
|
+
let(:json_string){ '{"abc":"def"}' }
|
57
|
+
|
58
|
+
it 'busts caches on global options change' do
|
59
|
+
MultiJson.load_options = { :symbolize_keys => true }
|
60
|
+
expect(MultiJson.load(json_string)).to eq(:abc => 'def')
|
61
|
+
MultiJson.load_options = nil
|
62
|
+
expect(MultiJson.load(json_string)).to eq('abc' => 'def')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'busts caches on per-adapter options change' do
|
66
|
+
adapter.load_options = { :symbolize_keys => true }
|
67
|
+
expect(MultiJson.load(json_string)).to eq(:abc => 'def')
|
68
|
+
adapter.load_options = nil
|
69
|
+
expect(MultiJson.load(json_string)).to eq('abc' => 'def')
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'defaults to the best available gem' do
|
75
|
+
# Clear cache variable already set by previous tests
|
76
|
+
MultiJson.send(:remove_instance_variable, :@adapter) if MultiJson.instance_variable_defined?(:@adapter)
|
77
|
+
if jruby?
|
78
|
+
expect(MultiJson.adapter.to_s).to eq 'MultiJson::Adapters::JrJackson'
|
79
|
+
else
|
80
|
+
expect(MultiJson.adapter.to_s).to eq 'MultiJson::Adapters::Oj'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'looks for adapter even if @adapter variable is nil' do
|
85
|
+
MultiJson.send(:instance_variable_set, :@adapter, nil)
|
86
|
+
expect(MultiJson).to receive(:default_adapter).and_return(:ok_json)
|
87
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::OkJson
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'is settable via a symbol' do
|
91
|
+
MultiJson.use :json_gem
|
92
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::JsonGem
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'is settable via a class' do
|
96
|
+
adapter = Class.new
|
97
|
+
MultiJson.use adapter
|
98
|
+
expect(MultiJson.adapter).to eq adapter
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'is settable via a module' do
|
102
|
+
adapter = Module.new
|
103
|
+
MultiJson.use adapter
|
104
|
+
expect(MultiJson.adapter).to eq adapter
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'throws ArgumentError on bad input' do
|
108
|
+
expect{ MultiJson.use 'bad adapter' }.to raise_error(ArgumentError)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'using one-shot parser' do
|
112
|
+
before do
|
113
|
+
expect(MultiJson::Adapters::JsonPure).to receive(:dump).once.and_return('dump_something')
|
114
|
+
expect(MultiJson::Adapters::JsonPure).to receive(:load).once.and_return('load_something')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should use the defined parser just for the call' do
|
118
|
+
MultiJson.use :json_gem
|
119
|
+
expect(MultiJson.dump('', :adapter => :json_pure)).to eq 'dump_something'
|
120
|
+
expect(MultiJson.load('', :adapter => :json_pure)).to eq 'load_something'
|
121
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::JsonGem
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'can set adapter for a block' do
|
127
|
+
MultiJson.use :ok_json
|
128
|
+
MultiJson.with_adapter(:json_pure) do
|
129
|
+
MultiJson.with_engine(:json_gem) do
|
130
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::JsonGem
|
131
|
+
end
|
132
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::JsonPure
|
133
|
+
end
|
134
|
+
expect(MultiJson.adapter).to eq MultiJson::Adapters::OkJson
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'JSON gem does not create symbols on parse' do
|
138
|
+
MultiJson.with_engine(:json_gem) do
|
139
|
+
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
140
|
+
|
141
|
+
expect{
|
142
|
+
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
143
|
+
}.to_not change{Symbol.all_symbols.count}
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
unless jruby?
|
148
|
+
it 'Oj does not create symbols on parse' do
|
149
|
+
MultiJson.with_engine(:oj) do
|
150
|
+
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
151
|
+
|
152
|
+
expect{
|
153
|
+
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
154
|
+
}.to_not change{Symbol.all_symbols.count}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'with Oj.default_settings' do
|
159
|
+
|
160
|
+
around do |example|
|
161
|
+
options = Oj.default_options
|
162
|
+
Oj.default_options = { :symbol_keys => true }
|
163
|
+
MultiJson.with_engine(:oj){ example.call }
|
164
|
+
Oj.default_options = options
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'ignores global settings' do
|
168
|
+
MultiJson.with_engine(:oj) do
|
169
|
+
example = '{"a": 1, "b": 2}'
|
170
|
+
expected = { 'a' => 1, 'b' => 2 }
|
171
|
+
expect(MultiJson.load(example)).to eq expected
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe 'default options' do
|
178
|
+
after(:all){ MultiJson.load_options = MultiJson.dump_options = nil }
|
179
|
+
|
180
|
+
it 'is deprecated' do
|
181
|
+
expect(Kernel).to receive(:warn).with(/deprecated/i)
|
182
|
+
silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'sets both load and dump options' do
|
186
|
+
expect(MultiJson).to receive(:dump_options=).with(:foo => 'bar')
|
187
|
+
expect(MultiJson).to receive(:load_options=).with(:foo => 'bar')
|
188
|
+
silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it_behaves_like 'has options', MultiJson
|
193
|
+
|
194
|
+
%w(gson jr_jackson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
|
195
|
+
next if !jruby? && %w(gson jr_jackson).include?(adapter)
|
196
|
+
next if !macruby? && adapter == 'nsjsonserialization'
|
197
|
+
next if jruby? && %w(oj yajl).include?(adapter)
|
198
|
+
|
199
|
+
context adapter do
|
200
|
+
it_behaves_like 'an adapter', adapter
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
%w(json_gem json_pure).each do |adapter|
|
205
|
+
context adapter do
|
206
|
+
it_behaves_like 'JSON-like adapter', adapter
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe 'aliases' do
|
211
|
+
if jruby?
|
212
|
+
describe 'jrjackson' do
|
213
|
+
after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
|
214
|
+
|
215
|
+
it 'allows jrjackson alias as symbol' do
|
216
|
+
expect{ MultiJson.use :jrjackson }.not_to raise_error
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'allows jrjackson alias as string' do
|
220
|
+
expect{ MultiJson.use 'jrjackson' }.not_to raise_error
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,186 @@
|
|
1
|
+
Pusher gem
|
2
|
+
==========
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/pusher/pusher-gem.png?branch=master)](http://travis-ci.org/pusher/pusher-gem)
|
5
|
+
|
6
|
+
## Installation & Configuration
|
7
|
+
|
8
|
+
Add pusher to your Gemfile, and then run `bundle install`
|
9
|
+
|
10
|
+
gem 'pusher'
|
11
|
+
|
12
|
+
or install via gem
|
13
|
+
|
14
|
+
gem install pusher
|
15
|
+
|
16
|
+
After registering at <http://pusher.com> configure your app with the security credentials.
|
17
|
+
|
18
|
+
### Global
|
19
|
+
|
20
|
+
The most standard way of configuring Pusher is to do it globally on the Pusher class.
|
21
|
+
|
22
|
+
Pusher.app_id = 'your-pusher-app-id'
|
23
|
+
Pusher.key = 'your-pusher-key'
|
24
|
+
Pusher.secret = 'your-pusher-secret'
|
25
|
+
|
26
|
+
Global configuration will automatically be set from the `PUSHER_URL` environment variable if it exists. This should be in the form `http://KEY:SECRET@api.pusherapp.com/apps/APP_ID`. On Heroku this environment variable will already be set.
|
27
|
+
|
28
|
+
If you need to make requests via a HTTP proxy then it can be configured
|
29
|
+
|
30
|
+
Pusher.http_proxy = 'http://(user):(password)@(host):(port)'
|
31
|
+
|
32
|
+
By default API requests are made over HTTP. HTTPS can be used by setting
|
33
|
+
|
34
|
+
Pusher.encrypted = true
|
35
|
+
|
36
|
+
As of version 0.12, SSL certificates are verified when using the synchronous http client. If you need to disable this behaviour for any reason use:
|
37
|
+
|
38
|
+
Pusher.default_client.sync_http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
39
|
+
|
40
|
+
### Instantiating a Pusher client
|
41
|
+
|
42
|
+
Sometimes you may have multiple sets of API keys, or want different configuration in different parts of your application. In these scenarios, a pusher `client` may be configured:
|
43
|
+
|
44
|
+
pusher_client = Pusher::Client.new({
|
45
|
+
app_id: 'your-pusher-app-id',
|
46
|
+
key: 'your-pusher-key',
|
47
|
+
secret: 'your-pusher-secret'
|
48
|
+
})
|
49
|
+
|
50
|
+
This `client` will have all the functionality listed on the main Pusher class (which proxies to a client internally).
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
## Interacting with the Pusher service
|
55
|
+
|
56
|
+
The Pusher gem contains a number of helpers for interacting with the service. As a general rule, the library adheres to a set of conventions that we have aimed to make universal.
|
57
|
+
|
58
|
+
### Handling errors
|
59
|
+
|
60
|
+
Handle errors by rescuing `Pusher::Error` (all errors are descendants of this error)
|
61
|
+
|
62
|
+
begin
|
63
|
+
Pusher.trigger('a_channel', 'an_event', {:some => 'data'})
|
64
|
+
rescue Pusher::Error => e
|
65
|
+
# (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
|
66
|
+
end
|
67
|
+
|
68
|
+
### Logging
|
69
|
+
|
70
|
+
Errors are logged to `Pusher.logger`. It will by default log at info level to STDOUT using `Logger` from the standard library, however you can assign any logger:
|
71
|
+
|
72
|
+
Pusher.logger = Rails.logger
|
73
|
+
|
74
|
+
### Publishing events
|
75
|
+
|
76
|
+
An event can be sent to Pusher in in the following ways:
|
77
|
+
|
78
|
+
# on the Pusher class
|
79
|
+
Pusher.trigger('channel_name', 'event_name', {some: 'data'})
|
80
|
+
Pusher.trigger(['channel_1', 'channel_2'], 'event_name', {some: 'data'})
|
81
|
+
|
82
|
+
# or on a pusher_client
|
83
|
+
pusher_client.trigger(['your_channels'], 'your_event_name', {some: 'data'})
|
84
|
+
|
85
|
+
Note: the first `channels` argument can contain multiple channels you'd like your event and data payload to go to. There is a limit of 100 on the number of channels this can contain.
|
86
|
+
|
87
|
+
An optional fourth argument of this method can specify a `socket_id` that will be excluded from receiving the event (generally the user where the event originated -- see <http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients> for more info).
|
88
|
+
|
89
|
+
#### Original publisher API
|
90
|
+
|
91
|
+
Most examples and documentation will refer to the following syntax for triggering an event:
|
92
|
+
|
93
|
+
Pusher['a_channel'].trigger('an_event', {:some => 'data'})
|
94
|
+
|
95
|
+
This will continue to work, but will be replaced as the canonical version by `Pusher.trigger` which supports multiple channels.
|
96
|
+
|
97
|
+
### Generic requests to the Pusher REST API
|
98
|
+
|
99
|
+
Aside from triggering events, the REST API also supports a number of operations for querying the state of the system. A reference of the available methods is available at <http://pusher.com/docs/rest_api>.
|
100
|
+
|
101
|
+
All requests must be signed by using your secret key, which is handled automatically using these methods:
|
102
|
+
|
103
|
+
# using the Pusher class
|
104
|
+
Pusher.get('url_without_app_id', params)
|
105
|
+
|
106
|
+
# using a client
|
107
|
+
pusher_client.post('url_without_app_id', params)
|
108
|
+
|
109
|
+
Note that you don't need to specify your app_id in the URL, as this is inferred from your credentials.
|
110
|
+
|
111
|
+
### Asynchronous requests
|
112
|
+
|
113
|
+
There are two main reasons for using the `_async` methods:
|
114
|
+
|
115
|
+
* In a web application where the response from Pusher is not used, but you'd like to avoid a blocking call in the request-response cycle
|
116
|
+
* Your application is running in an event loop and you need to avoid blocking the reactor
|
117
|
+
|
118
|
+
Asynchronous calls are supported either by using an event loop (eventmachine, preferred), or via a thread.
|
119
|
+
|
120
|
+
The following methods are available (in each case the calling iterface matches the non-async version):
|
121
|
+
|
122
|
+
* `Pusher.get_async`
|
123
|
+
* `Pusher.post_async`
|
124
|
+
* `Pusher.trigger_async`
|
125
|
+
|
126
|
+
It is of course also possible to make calls to pusher via a job queue. This approach is recommended if you're sending a large number of events to pusher.
|
127
|
+
|
128
|
+
#### With eventmachine
|
129
|
+
|
130
|
+
* Add the `em-http-request` gem to your Gemfile (it's not a gem dependency).
|
131
|
+
* Run the eventmachine reactor (either using `EM.run` or by running inside an evented server such as Thin).
|
132
|
+
|
133
|
+
The `_async` methods return an `EM::Deferrable` which you can bind callbacks to:
|
134
|
+
|
135
|
+
Pusher.get_async("/channels").callback { |response|
|
136
|
+
# use reponse[:channels]
|
137
|
+
}.errback { |error|
|
138
|
+
# error is an instance of Pusher::Error
|
139
|
+
}
|
140
|
+
|
141
|
+
A HTTP error or an error response from pusher will cause the errback to be called with an appropriate error object.
|
142
|
+
|
143
|
+
#### Without eventmachine
|
144
|
+
|
145
|
+
If the eventmachine reactor is not running, async requests will be make using threads (managed by the httpclient gem).
|
146
|
+
|
147
|
+
An `HTTPClient::Connection` object is returned immediately which can be [interrogated](http://rubydoc.info/gems/httpclient/HTTPClient/Connection) to discover the status of the request. The usual response checking and processing is not done when the request completes, and frankly this method is most useful when you're not interested in waiting for the response.
|
148
|
+
|
149
|
+
|
150
|
+
## Authenticating subscription requests
|
151
|
+
|
152
|
+
It's possible to use the gem to authenticate subscription requests to private or presence channels. The `authenticate` method is available on a channel object for this purpose and returns a JSON object that can be returned to the client that made the request. More information on this authentication scheme can be found in the docs on <http://pusher.com>
|
153
|
+
|
154
|
+
### Private channels
|
155
|
+
|
156
|
+
Pusher['private-my_channel'].authenticate(params[:socket_id])
|
157
|
+
|
158
|
+
### Presence channels
|
159
|
+
|
160
|
+
These work in a very similar way, but require a unique identifier for the user being authenticated, and optionally some attributes that are provided to clients via presence events:
|
161
|
+
|
162
|
+
Pusher['presence-my_channel'].authenticate(params[:socket_id], {
|
163
|
+
user_id: 'user_id',
|
164
|
+
user_info: {} # optional
|
165
|
+
})
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
## Receiving WebHooks
|
170
|
+
|
171
|
+
A WebHook object may be created to validate received WebHooks against your app credentials, and to extract events. It should be created with the `Rack::Request` object (available as `request` in Rails controllers or Sinatra handlers for example).
|
172
|
+
|
173
|
+
webhook = Pusher.webhook(request)
|
174
|
+
if webhook.valid?
|
175
|
+
webhook.events.each do |event|
|
176
|
+
case event["name"]
|
177
|
+
when 'channel_occupied'
|
178
|
+
puts "Channel occupied: #{event["channel"]}"
|
179
|
+
when 'channel_vacated'
|
180
|
+
puts "Channel vacated: #{event["channel"]}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
render text: 'ok'
|
184
|
+
else
|
185
|
+
render text: 'invalid', status: 401
|
186
|
+
end
|