centrifuge 0.0.1
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Guardfile +77 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +2 -0
- data/centrifuge.gemspec +30 -0
- data/lib/centrifuge/builder.rb +36 -0
- data/lib/centrifuge/client.rb +73 -0
- data/lib/centrifuge/request.rb +49 -0
- data/lib/centrifuge/version.rb +3 -0
- data/lib/centrifuge.rb +43 -0
- data/spec/client_spec.rb +46 -0
- data/spec/spec_helper.rb +98 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e4c60c2017ed840a854c4cb498ba8846ffc43f4a
|
4
|
+
data.tar.gz: 75bf9f657b98acc2b954267e83a4fbb940e210f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de2852d46ce56a14bb2267bc344c13681911e072ef5d071038bec3d378d0898790e105e879097bf19ae77c20d28f334f0f9a0d9f54078db7082fcab00fbf9713
|
7
|
+
data.tar.gz: 06639e6c2c819ee7b28ac12adf0499a728737f9e385540c53b816cc2761a00d777d23580b214d92fb32a398e0c72c5c56660fde9450b7ae5ead0d493368bc466
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), the you will want to move the Guardfile
|
18
|
+
## to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
36
|
+
require "guard/rspec/dsl"
|
37
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
38
|
+
|
39
|
+
# Feel free to open issues for suggestions and improvements
|
40
|
+
|
41
|
+
# RSpec files
|
42
|
+
rspec = dsl.rspec
|
43
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
44
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
45
|
+
watch(rspec.spec_files)
|
46
|
+
|
47
|
+
# Ruby files
|
48
|
+
ruby = dsl.ruby
|
49
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
50
|
+
|
51
|
+
# Rails files
|
52
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
53
|
+
dsl.watch_spec_files_for(rails.app_files)
|
54
|
+
dsl.watch_spec_files_for(rails.views)
|
55
|
+
|
56
|
+
watch(rails.controllers) do |m|
|
57
|
+
[
|
58
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
59
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
60
|
+
rspec.spec.("acceptance/#{m[1]}")
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
# Rails config changes
|
65
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
66
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
67
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
68
|
+
|
69
|
+
# Capybara features specs
|
70
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
71
|
+
|
72
|
+
# Turnip features and steps
|
73
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
74
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
75
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
76
|
+
end
|
77
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Oleg Bovykin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Centrifuge
|
2
|
+
[](https://codeclimate.com/github/arrowcircle/centrifuge-ruby)
|
3
|
+
[](https://travis-ci.org/arrowcircle/centrifuge-ruby)
|
4
|
+
|
5
|
+
Ruby gem for [Centrifuge](https://github.com/centrifugal/centrifuge) real-time messaging broker
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'centrifuge'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install centrifuge
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
`Centrifuge::Client` - is main usable class. Start with:
|
26
|
+
|
27
|
+
client = Centrifute::Client.new(scheme: :http, host: :localhost, port: 80, project_id: 'abc', secret: 'cde')
|
28
|
+
|
29
|
+
If you are planning to use only one project, its convenient to set all data and use class methods:
|
30
|
+
|
31
|
+
Centrifuge.scheme = :http
|
32
|
+
Centrifuge.host = 'localhost'
|
33
|
+
Centrifuge.port = 8000
|
34
|
+
Centrifuge.project_id = 'abc'
|
35
|
+
Centrifuge.secret = 'def'
|
36
|
+
|
37
|
+
There are five methds available:
|
38
|
+
|
39
|
+
### Publish
|
40
|
+
|
41
|
+
Sends message to all connected users:
|
42
|
+
|
43
|
+
client.publish('teshchannel', { data: :foo })
|
44
|
+
|
45
|
+
You can also use class methods if you set all necessary config data:
|
46
|
+
|
47
|
+
Centrifuge.publish('testchannel', { data: :foo })
|
48
|
+
|
49
|
+
### Unsubscribe
|
50
|
+
|
51
|
+
Unsubscribes user from channel:
|
52
|
+
|
53
|
+
client.unsubscribe('testchannel', 'user#23')
|
54
|
+
|
55
|
+
`user#23` - is string identificator of user.
|
56
|
+
|
57
|
+
### Disconnect
|
58
|
+
|
59
|
+
Disconnects user from Centrifuge:
|
60
|
+
|
61
|
+
client.disconnect('user#23')
|
62
|
+
|
63
|
+
### Presence
|
64
|
+
|
65
|
+
Gets presence info of the channel:
|
66
|
+
|
67
|
+
client.presence('testchannel')
|
68
|
+
|
69
|
+
### History
|
70
|
+
|
71
|
+
Gets message history of the channel:
|
72
|
+
|
73
|
+
client.history('test_channel')
|
74
|
+
|
75
|
+
### Other API
|
76
|
+
|
77
|
+
Other API methods, like projects and channels management are unavailable now.
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/centrifugal/centrifuge-ruby/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/centrifuge.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'centrifuge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "centrifuge"
|
8
|
+
spec.version = Centrifuge::VERSION
|
9
|
+
spec.authors = ["Oleg Bovykin"]
|
10
|
+
spec.email = ["oleg.bovykin@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby gem for Centrifuge real-time messaging broker}
|
12
|
+
spec.description = %q{Ruby gem for Centrifuge real-time messaging broker}
|
13
|
+
spec.homepage = "https://github.com/arrowcircle/centrifuge-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'httpclient'
|
22
|
+
spec.add_dependency 'multi_json'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'centrifuge/request'
|
2
|
+
|
3
|
+
module Centrifuge
|
4
|
+
class Builder
|
5
|
+
attr_accessor :method, :data, :client
|
6
|
+
|
7
|
+
def initialize(method, data, client)
|
8
|
+
@method, @data, @client = method, data, client
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
12
|
+
body = { data: json(method, data) }
|
13
|
+
body.merge!(sign: sign(body[:data]))
|
14
|
+
Centrifuge::Request.new(client.client, 'POST', client.url, nil, body).send
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def json(method, params)
|
20
|
+
MultiJson.dump({ method: method, params: params })
|
21
|
+
end
|
22
|
+
|
23
|
+
def sign(body)
|
24
|
+
dig = OpenSSL::Digest.new('md5')
|
25
|
+
OpenSSL::HMAC.hexdigest(dig, secret, "#{project_id}#{body}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def project_id
|
29
|
+
client.project_id
|
30
|
+
end
|
31
|
+
|
32
|
+
def secret
|
33
|
+
client.secret
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'centrifuge/builder'
|
4
|
+
|
5
|
+
module Centrifuge
|
6
|
+
class Client
|
7
|
+
DEFAULT_OPTIONS = {
|
8
|
+
scheme: 'http',
|
9
|
+
host: 'localhost',
|
10
|
+
port: 8000,
|
11
|
+
}
|
12
|
+
attr_accessor :scheme, :host, :port, :project_id, :secret
|
13
|
+
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
|
14
|
+
:keep_alive_timeout
|
15
|
+
|
16
|
+
## CONFIGURATION ##
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
options = DEFAULT_OPTIONS.merge(options)
|
20
|
+
@scheme, @host, @port, @project_id, @secret = options.values_at(
|
21
|
+
:scheme, :host, :port, :project_id, :secret
|
22
|
+
)
|
23
|
+
set_default_timeouts
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_default_timeouts
|
27
|
+
@connect_timeout = 5
|
28
|
+
@send_timeout = 5
|
29
|
+
@receive_timeout = 5
|
30
|
+
@keep_alive_timeout = 30
|
31
|
+
end
|
32
|
+
|
33
|
+
def url(path = nil)
|
34
|
+
URI::Generic.build({
|
35
|
+
scheme: scheme.to_s,
|
36
|
+
host: host,
|
37
|
+
port: port,
|
38
|
+
path: "/api/#{project_id}#{path}"
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
def publish(channel, data)
|
43
|
+
Centrifuge::Builder.new('publish', { channel: channel, data: data }, self).process
|
44
|
+
end
|
45
|
+
|
46
|
+
def unsubscribe(channel, user)
|
47
|
+
Centrifuge::Builder.new('unsubscribe', { channel: channel, user: user }, self).process
|
48
|
+
end
|
49
|
+
|
50
|
+
def disconnect(user)
|
51
|
+
Centrifuge::Builder.new('disconnect', { user: user }, self).process
|
52
|
+
end
|
53
|
+
|
54
|
+
def presence(channel)
|
55
|
+
Centrifuge::Builder.new('presence', { channel: channel }, self).process
|
56
|
+
end
|
57
|
+
|
58
|
+
def history(channel)
|
59
|
+
Centrifuge::Builder.new('history', { channel: channel }, self).process
|
60
|
+
end
|
61
|
+
|
62
|
+
def client
|
63
|
+
@client ||= begin
|
64
|
+
HTTPClient.new.tap do |http|
|
65
|
+
http.connect_timeout = @connect_timeout
|
66
|
+
http.send_timeout = @send_timeout
|
67
|
+
http.receive_timeout = @receive_timeout
|
68
|
+
http.keep_alive_timeout = @keep_alive_timeout
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module Centrifuge
|
4
|
+
class Request
|
5
|
+
attr_accessor :client, :verb, :uri, :body, :head, :params
|
6
|
+
|
7
|
+
def initialize(client, verb, uri, params, body = nil, head = {})
|
8
|
+
@client, @verb, @uri, @params, @body = client, verb, uri, params, body
|
9
|
+
@head = head
|
10
|
+
end
|
11
|
+
|
12
|
+
def send
|
13
|
+
response = request_or_rescue
|
14
|
+
body = response.body ? response.body.chomp : nil
|
15
|
+
handle_response(response.code.to_i, body)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def request_or_rescue
|
21
|
+
begin
|
22
|
+
response = client.request(verb, uri, params, body, head)
|
23
|
+
rescue HTTPClient::BadResponseError, HTTPClient::TimeoutError, SocketError, Errno::ECONNREFUSED => original_error
|
24
|
+
error = Centrifuge::HTTPError.new("#{original_error.message} (#{original_error.class})")
|
25
|
+
error.original_error = original_error
|
26
|
+
raise error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_response(status_code, body)
|
31
|
+
case status_code
|
32
|
+
when 200
|
33
|
+
return MultiJson.load(body)
|
34
|
+
when 202
|
35
|
+
return true
|
36
|
+
when 400
|
37
|
+
raise Error, "Bad request: #{body}"
|
38
|
+
when 401
|
39
|
+
raise AuthenticationError, body
|
40
|
+
when 404
|
41
|
+
raise Error, "404 Not found (#{@uri.path})"
|
42
|
+
when 407
|
43
|
+
raise Error, "Proxy Authentication Required"
|
44
|
+
else
|
45
|
+
raise Error, "Unknown error (status code #{status_code}): #{body}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/centrifuge.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "centrifuge/version"
|
2
|
+
require "centrifuge/client"
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Centrifuge
|
6
|
+
class Error < RuntimeError; end
|
7
|
+
class AuthenticationError < Error; end
|
8
|
+
class ConfigurationError < Error; end
|
9
|
+
class HTTPError < Error; attr_accessor :original_error; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
def_delegators :default_client, :scheme, :host, :port, :project_id, :secret
|
15
|
+
def_delegators :default_client, :scheme=, :host=, :port=, :project_id=, :secret=
|
16
|
+
|
17
|
+
# def_delegators :default_client, :authentication_token, :url
|
18
|
+
# def_delegators :default_client, :encrypted=, :url=
|
19
|
+
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
|
20
|
+
|
21
|
+
# def_delegators :default_client, :get, :get_async, :post, :post_async
|
22
|
+
def_delegators :default_client, :publish
|
23
|
+
# def_delegators :default_client, :webhook, :channel, :[]
|
24
|
+
|
25
|
+
attr_writer :logger
|
26
|
+
|
27
|
+
def logger
|
28
|
+
@logger ||= begin
|
29
|
+
log = Logger.new($stdout)
|
30
|
+
log.level = Logger::INFO
|
31
|
+
log
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_client
|
36
|
+
@default_client ||= Centrifuge::Client.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if ENV['CENTRIFUGE_URL']
|
41
|
+
self.url = ENV['CENTRIFUGE_URL']
|
42
|
+
end
|
43
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Centrifuge::Client do
|
4
|
+
let(:options) { { scheme: :https, host: 'reddifuge.herokuapp.com', port: 443, project_id: '060748d06d4c411997e1b5255b2d969e', secret: '334e0fd69fc447a1b268d704f021f59c' } }
|
5
|
+
let(:client) { Centrifuge::Client.new(options) }
|
6
|
+
let(:data) { { action: :test } }
|
7
|
+
|
8
|
+
it 'generates url' do
|
9
|
+
expect(client.url.to_s).to eq "https://reddifuge.herokuapp.com:443/api/#{client.project_id}"
|
10
|
+
end
|
11
|
+
|
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}]
|
17
|
+
end
|
18
|
+
|
19
|
+
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}]
|
24
|
+
end
|
25
|
+
|
26
|
+
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}]
|
31
|
+
end
|
32
|
+
|
33
|
+
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"=>{}}]
|
38
|
+
end
|
39
|
+
|
40
|
+
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"=>[]}]
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
require 'bundler/setup'
|
16
|
+
Bundler.setup
|
17
|
+
require 'centrifuge'
|
18
|
+
require 'rspec'
|
19
|
+
require 'webmock/rspec'
|
20
|
+
#
|
21
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
22
|
+
RSpec.configure do |config|
|
23
|
+
# rspec-expectations config goes here. You can use an alternate
|
24
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
25
|
+
# assertions if you prefer.
|
26
|
+
config.expect_with :rspec do |expectations|
|
27
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
28
|
+
# and `failure_message` of custom matchers include text for helper methods
|
29
|
+
# defined using `chain`, e.g.:
|
30
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
31
|
+
# # => "be bigger than 2 and smaller than 4"
|
32
|
+
# ...rather than:
|
33
|
+
# # => "be bigger than 2"
|
34
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
35
|
+
end
|
36
|
+
|
37
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
38
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
39
|
+
config.mock_with :rspec do |mocks|
|
40
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
41
|
+
# a real object. This is generally recommended, and will default to
|
42
|
+
# `true` in RSpec 4.
|
43
|
+
mocks.verify_partial_doubles = true
|
44
|
+
end
|
45
|
+
|
46
|
+
config.before(:each) do
|
47
|
+
WebMock.reset!
|
48
|
+
WebMock.disable_net_connect!
|
49
|
+
end
|
50
|
+
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
53
|
+
|
54
|
+
# These two settings work together to allow you to limit a spec run
|
55
|
+
# to individual examples or groups you care about by tagging them with
|
56
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
57
|
+
# get run.
|
58
|
+
# config.filter_run :focus
|
59
|
+
# config.run_all_when_everything_filtered = true
|
60
|
+
|
61
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
62
|
+
# For more details, see:
|
63
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
64
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
65
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
66
|
+
# config.disable_monkey_patching!
|
67
|
+
|
68
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
69
|
+
# be too noisy due to issues in dependencies.
|
70
|
+
config.warnings = false
|
71
|
+
|
72
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
73
|
+
# file, and it's useful to allow more verbose output when running an
|
74
|
+
# individual spec file.
|
75
|
+
if config.files_to_run.one?
|
76
|
+
# Use the documentation formatter for detailed output,
|
77
|
+
# unless a formatter has already been configured
|
78
|
+
# (e.g. via a command-line flag).
|
79
|
+
config.default_formatter = 'doc'
|
80
|
+
end
|
81
|
+
|
82
|
+
# Print the 10 slowest examples and example groups at the
|
83
|
+
# end of the spec run, to help surface which specs are running
|
84
|
+
# particularly slow.
|
85
|
+
config.profile_examples = 10
|
86
|
+
|
87
|
+
# Run specs in random order to surface order dependencies. If you find an
|
88
|
+
# order dependency and want to debug it, you can fix the order by providing
|
89
|
+
# the seed, which is printed after each run.
|
90
|
+
# --seed 1234
|
91
|
+
config.order = :random
|
92
|
+
|
93
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
94
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
95
|
+
# test failures related to randomization by passing the same `--seed` value
|
96
|
+
# as the one that triggered the failure.
|
97
|
+
Kernel.srand config.seed
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: centrifuge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Bovykin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Ruby gem for Centrifuge real-time messaging broker
|
112
|
+
email:
|
113
|
+
- oleg.bovykin@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- centrifuge.gemspec
|
127
|
+
- lib/centrifuge.rb
|
128
|
+
- lib/centrifuge/builder.rb
|
129
|
+
- lib/centrifuge/client.rb
|
130
|
+
- lib/centrifuge/request.rb
|
131
|
+
- lib/centrifuge/version.rb
|
132
|
+
- spec/client_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: https://github.com/arrowcircle/centrifuge-ruby
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.5
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Ruby gem for Centrifuge real-time messaging broker
|
158
|
+
test_files:
|
159
|
+
- spec/client_spec.rb
|
160
|
+
- spec/spec_helper.rb
|