centrifuge 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/centrifuge/client.rb +7 -7
- data/lib/centrifuge/request.rb +1 -1
- data/lib/centrifuge/version.rb +1 -1
- data/lib/centrifuge.rb +2 -2
- data/spec/client_spec.rb +11 -22
- data/spec/spec_helper.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c72f7e53d98f1c39fa274dad8db771151df6275
|
4
|
+
data.tar.gz: c26967230df365720bcab949250650cd1f368df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 753fe93461f18f82a268cb0e648e30bb0cce09f88aace6d5b15a044eef1e291d1b1105f57adaccc462d48e4647a6a932aa436717a450e2e8c14fb3e23c2dc8c6
|
7
|
+
data.tar.gz: 9af78670d1570d93fabc973ff7e46c3e254560e77864d253dc9bfb9a2128c0cf30d1cca2261aa0b46b4bcc95f2bba4da658bae438ea4825adad333e9e9c3e27f
|
data/README.md
CHANGED
@@ -20,18 +20,20 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install centrifuge
|
22
22
|
|
23
|
+
Compatible version for Centrifuge version 0.8.0 and above are 0.1.0+. Please use 0.0.x versions for older Centrifuge
|
24
|
+
|
23
25
|
## Usage
|
24
26
|
|
25
27
|
`Centrifuge::Client` - is main usable class. Start with:
|
26
28
|
|
27
|
-
client = Centrifute::Client.new(scheme: :http, host: :localhost, port: 80,
|
29
|
+
client = Centrifute::Client.new(scheme: :http, host: :localhost, port: 80, project_key: 'abc', secret: 'cde')
|
28
30
|
|
29
31
|
If you are planning to use only one project, its convenient to set all data and use class methods:
|
30
32
|
|
31
33
|
Centrifuge.scheme = :http
|
32
34
|
Centrifuge.host = 'localhost'
|
33
35
|
Centrifuge.port = 8000
|
34
|
-
Centrifuge.
|
36
|
+
Centrifuge.project_key = 'abc'
|
35
37
|
Centrifuge.secret = 'def'
|
36
38
|
|
37
39
|
There are five methds available:
|
data/lib/centrifuge/client.rb
CHANGED
@@ -9,7 +9,7 @@ module Centrifuge
|
|
9
9
|
host: 'localhost',
|
10
10
|
port: 8000,
|
11
11
|
}
|
12
|
-
attr_accessor :scheme, :host, :port, :
|
12
|
+
attr_accessor :scheme, :host, :port, :project_key, :secret
|
13
13
|
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
|
14
14
|
:keep_alive_timeout
|
15
15
|
|
@@ -17,8 +17,8 @@ module Centrifuge
|
|
17
17
|
|
18
18
|
def initialize(options = {})
|
19
19
|
options = DEFAULT_OPTIONS.merge(options)
|
20
|
-
@scheme, @host, @port, @
|
21
|
-
:scheme, :host, :port, :
|
20
|
+
@scheme, @host, @port, @project_key, @secret = options.values_at(
|
21
|
+
:scheme, :host, :port, :project_key, :secret
|
22
22
|
)
|
23
23
|
set_default_timeouts
|
24
24
|
end
|
@@ -35,7 +35,7 @@ module Centrifuge
|
|
35
35
|
scheme: scheme.to_s,
|
36
36
|
host: host,
|
37
37
|
port: port,
|
38
|
-
path: "/api/#{
|
38
|
+
path: "/api/#{project_key}#{path}"
|
39
39
|
})
|
40
40
|
end
|
41
41
|
|
@@ -59,13 +59,13 @@ module Centrifuge
|
|
59
59
|
Centrifuge::Builder.new('history', { channel: channel }, self).process
|
60
60
|
end
|
61
61
|
|
62
|
-
def token_for(user, timestamp, user_info = "
|
62
|
+
def token_for(user, timestamp, user_info = "")
|
63
63
|
sign("#{user}#{timestamp}#{user_info}")
|
64
64
|
end
|
65
65
|
|
66
66
|
def sign(body)
|
67
|
-
dig = OpenSSL::Digest.new('
|
68
|
-
OpenSSL::HMAC.hexdigest(dig, secret, "#{
|
67
|
+
dig = OpenSSL::Digest.new('sha256')
|
68
|
+
OpenSSL::HMAC.hexdigest(dig, secret, "#{project_key}#{body}")
|
69
69
|
end
|
70
70
|
|
71
71
|
def client
|
data/lib/centrifuge/request.rb
CHANGED
data/lib/centrifuge/version.rb
CHANGED
data/lib/centrifuge.rb
CHANGED
@@ -16,8 +16,8 @@ module Centrifuge
|
|
16
16
|
class << self
|
17
17
|
extend Forwardable
|
18
18
|
|
19
|
-
def_delegators :default_client, :scheme, :host, :port, :
|
20
|
-
def_delegators :default_client, :scheme=, :host=, :port=, :
|
19
|
+
def_delegators :default_client, :scheme, :host, :port, :project_key, :secret
|
20
|
+
def_delegators :default_client, :scheme=, :host=, :port=, :project_key=, :secret=
|
21
21
|
|
22
22
|
# def_delegators :default_client, :authentication_token, :url
|
23
23
|
# def_delegators :default_client, :encrypted=, :url=
|
data/spec/client_spec.rb
CHANGED
@@ -1,46 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Centrifuge::Client do
|
4
|
-
let(:options) { { scheme: :https, host: '
|
4
|
+
let(:options) { { scheme: :https, host: 'centrifugo.herokuapp.com', port: 443, project_key: 'development', secret: 'secret' } }
|
5
5
|
let(:client) { Centrifuge::Client.new(options) }
|
6
6
|
let(:data) { { action: :test } }
|
7
7
|
|
8
8
|
it 'generates url' do
|
9
|
-
expect(client.url.to_s).to eq "https://
|
9
|
+
expect(client.url.to_s).to eq "https://centrifugo.herokuapp.com:443/api/#{client.project_key}"
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'publishes data' do
|
13
|
-
|
14
|
-
|
15
|
-
to_return(status: 200, body: "[{\"body\":true,\"error\":null,\"method\":\"publish\",\"uid\":null}]", headers: {})
|
16
|
-
expect(client.publish("testchannel", data)).to eq [{"body" => true, "error" => nil, "method" => "publish", "uid" => nil}]
|
13
|
+
channel = SecureRandom.hex
|
14
|
+
expect(client.publish(channel, data)).to eq [{"body" => nil, "error" => nil, "method" => "publish"}]
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'unsubscribes user' do
|
20
|
-
|
21
|
-
|
22
|
-
to_return(status: 200, body: "[{\"method\":\"unsubscribe\",\"error\":null,\"uid\":null,\"body\":true}]", headers: {})
|
23
|
-
expect(client.unsubscribe("testchannel", "23")).to eq [{"method"=>"unsubscribe", "error"=>nil, "uid"=>nil, "body"=>true}]
|
18
|
+
channel = SecureRandom.hex
|
19
|
+
expect(client.unsubscribe(channel, "23")).to eq [{"body"=>nil, "error"=>nil, "method"=>"unsubscribe"}]
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'disconnects user' do
|
27
|
-
|
28
|
-
with(body: {"data"=>"{\"method\":\"disconnect\",\"params\":{\"user\":\"23\"}}", "sign"=>"1331a7cc6da5cb747cab3d4cfabc5644"}).
|
29
|
-
to_return(status: 200, body: "[{\"method\":\"disconnect\",\"error\":null,\"uid\":null,\"body\":true}]", headers: {})
|
30
|
-
expect(client.disconnect("23")).to eq [{"method"=>"disconnect", "error"=>nil, "uid"=>nil, "body"=>true}]
|
23
|
+
expect(client.disconnect("23")).to eq [{"body" => nil, "error" => nil, "method" => "disconnect"}]
|
31
24
|
end
|
32
25
|
|
33
26
|
it 'fetches presence info' do
|
34
|
-
|
35
|
-
|
36
|
-
to_return(status: 200, body: "[{\"method\":\"presence\",\"error\":null,\"uid\":null,\"body\":{}}]", headers: {})
|
37
|
-
expect(client.presence("testchannel")).to eq [{"method"=>"presence", "error"=>nil, "uid"=>nil, "body"=>{}}]
|
27
|
+
channel = SecureRandom.hex
|
28
|
+
expect(client.presence(channel)).to eq [{"body" => {"channel" => channel, "data" => {}}, "error" => nil, "method" => "presence"}]
|
38
29
|
end
|
39
30
|
|
40
31
|
it 'fetches history' do
|
41
|
-
|
42
|
-
|
43
|
-
to_return(status: 200, body: "[{\"method\":\"history\",\"error\":null,\"uid\":null,\"body\":[]}]", headers: {})
|
44
|
-
expect(client.history("testchannel")).to eq [{"method"=>"history", "error"=>nil, "uid"=>nil, "body"=>[]}]
|
32
|
+
channel = SecureRandom.hex
|
33
|
+
expect(client.history(channel)).to eq [{"body" => {"channel" => channel, "data" => []}, "error" => nil, "method"=>"history"}]
|
45
34
|
end
|
46
35
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,7 @@ require 'bundler/setup'
|
|
16
16
|
Bundler.setup
|
17
17
|
require 'centrifuge'
|
18
18
|
require 'rspec'
|
19
|
-
require 'webmock/rspec'
|
19
|
+
# require 'webmock/rspec'
|
20
20
|
#
|
21
21
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
22
22
|
RSpec.configure do |config|
|
@@ -43,10 +43,10 @@ RSpec.configure do |config|
|
|
43
43
|
mocks.verify_partial_doubles = true
|
44
44
|
end
|
45
45
|
|
46
|
-
config.before(:each) do
|
47
|
-
|
48
|
-
|
49
|
-
end
|
46
|
+
# config.before(:each) do
|
47
|
+
# WebMock.reset!
|
48
|
+
# WebMock.disable_net_connect!
|
49
|
+
# end
|
50
50
|
|
51
51
|
# The settings below are suggested to provide a good initial experience
|
52
52
|
# with RSpec, but feel free to customize to your heart's content.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: centrifuge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Bovykin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|