centrifuge 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09218a5c452092b2bd0c00132c2031d8fd21af6b
4
- data.tar.gz: bb4e9c00f0859455b30bbb1dd21e163e6f8bdaed
3
+ metadata.gz: 5c72f7e53d98f1c39fa274dad8db771151df6275
4
+ data.tar.gz: c26967230df365720bcab949250650cd1f368df5
5
5
  SHA512:
6
- metadata.gz: 0f3d5e00f2b98b8449adc2d0ba3cb68ee3fa75ea2f2756c1356f53d7101310cd4b53f9792301a308b130e5d8de8abb8ac8a4c4ded3c4c0aabf9dbd34e29c6056
7
- data.tar.gz: f87ab041ef3e1d061a69d4e525481aa4203dce1f3957277daad053a1003b6dfdfa5d9aa6cfcab952029d0a4d5a84b21cb5001f566f25f3f50e9d738729d66c8e
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, project_id: 'abc', secret: 'cde')
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.project_id = 'abc'
36
+ Centrifuge.project_key = 'abc'
35
37
  Centrifuge.secret = 'def'
36
38
 
37
39
  There are five methds available:
@@ -9,7 +9,7 @@ module Centrifuge
9
9
  host: 'localhost',
10
10
  port: 8000,
11
11
  }
12
- attr_accessor :scheme, :host, :port, :project_id, :secret
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, @project_id, @secret = options.values_at(
21
- :scheme, :host, :port, :project_id, :secret
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/#{project_id}#{path}"
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('md5')
68
- OpenSSL::HMAC.hexdigest(dig, secret, "#{project_id}#{body}")
67
+ dig = OpenSSL::Digest.new('sha256')
68
+ OpenSSL::HMAC.hexdigest(dig, secret, "#{project_key}#{body}")
69
69
  end
70
70
 
71
71
  def client
@@ -38,7 +38,7 @@ module Centrifuge
38
38
  when 401
39
39
  raise AuthenticationError, body
40
40
  when 404
41
- raise Error, "404 Not found (#{@uri.path})"
41
+ raise Error, "404 Not found (#{@uri.path} #{@uri.to_json})"
42
42
  when 407
43
43
  raise Error, "Proxy Authentication Required"
44
44
  else
@@ -1,3 +1,3 @@
1
1
  module Centrifuge
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
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, :project_id, :secret
20
- def_delegators :default_client, :scheme=, :host=, :port=, :project_id=, :secret=
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: 'reddifuge.herokuapp.com', port: 443, project_id: '060748d06d4c411997e1b5255b2d969e', secret: '334e0fd69fc447a1b268d704f021f59c' } }
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://reddifuge.herokuapp.com:443/api/#{client.project_id}"
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
- stub_request(:post, "https://reddifuge.herokuapp.com/api/060748d06d4c411997e1b5255b2d969e").
14
- with(body: {"data"=>"{\"method\":\"publish\",\"params\":{\"channel\":\"testchannel\",\"data\":{\"action\":\"test\"}}}", "sign"=>"9191468cf61debb04768ff1f667a8df8"}).
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
- stub_request(:post, "https://reddifuge.herokuapp.com/api/060748d06d4c411997e1b5255b2d969e").
21
- with(body: {"data"=>"{\"method\":\"unsubscribe\",\"params\":{\"channel\":\"testchannel\",\"user\":\"23\"}}", "sign"=>"613a46c24a54ad546b7bf084c249d8c2"}).
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
- stub_request(:post, "https://reddifuge.herokuapp.com/api/060748d06d4c411997e1b5255b2d969e").
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
- stub_request(:post, "https://reddifuge.herokuapp.com/api/060748d06d4c411997e1b5255b2d969e").
35
- with(body: {"data"=>"{\"method\":\"presence\",\"params\":{\"channel\":\"testchannel\"}}", "sign"=>"9e3db58b7cf9d9eccee4c85ee87e6532"}).
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
- stub_request(:post, "https://reddifuge.herokuapp.com/api/060748d06d4c411997e1b5255b2d969e").
42
- with(body: {"data"=>"{\"method\":\"history\",\"params\":{\"channel\":\"testchannel\"}}", "sign"=>"14413322f1fd26b4256db34941d6cdb7"}).
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
- WebMock.reset!
48
- WebMock.disable_net_connect!
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.5
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-04-01 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient