hornet-connector-ruby 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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.rdoc +5 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/hornet-connector-ruby.gemspec +56 -0
- data/init.rb +1 -0
- data/lib/hornet.rb +76 -0
- data/test/hornet-connector-ruby_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +94 -0
data/.document
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2011 Nectify
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hornet-connector-ruby"
|
8
|
+
gem.summary = %Q{Hornet Ruby Connector - Realtime engine for webapps}
|
9
|
+
gem.description = %Q{Hornet Ruby Connector is a connector for Hornet, a realtime engine backed by Redis and Socket.io}
|
10
|
+
gem.email = "robin.komiwes@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/nectify/hornet-connector-ruby"
|
12
|
+
gem.authors = ["Robin Komiwes", "Benjamin Tierny", "Tristan Bourgois", "Maxime Brazeilles"]
|
13
|
+
gem.rubyforge_project = "hornet-connector-ruby"
|
14
|
+
gem.add_dependency 'alphadecimal'
|
15
|
+
end
|
16
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
17
|
+
rubyforge.doc_task = "rdoc"
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
if File.exist?('VERSION')
|
50
|
+
version = File.read('VERSION')
|
51
|
+
else
|
52
|
+
version = ""
|
53
|
+
end
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "hornet-connector-ruby #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hornet-connector-ruby}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Robin Komiwes", "Benjamin Tierny", "Tristan Bourgois", "Maxime Brazeilles"]
|
12
|
+
s.date = %q{2011-06-17}
|
13
|
+
s.description = %q{Hornet Ruby Connector is a connector for Hornet, a realtime engine backed by Redis and Socket.io}
|
14
|
+
s.email = %q{robin.komiwes@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"hornet-connector-ruby.gemspec",
|
28
|
+
"init.rb",
|
29
|
+
"lib/hornet.rb",
|
30
|
+
"test/hornet-connector-ruby_test.rb",
|
31
|
+
"test/test_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/nectify/hornet-connector-ruby}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubyforge_project = %q{hornet-connector-ruby}
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Hornet Ruby Connector - Realtime engine for webapps}
|
39
|
+
s.test_files = [
|
40
|
+
"test/hornet-connector-ruby_test.rb",
|
41
|
+
"test/test_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<alphadecimal>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<alphadecimal>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<alphadecimal>, [">= 0"])
|
55
|
+
end
|
56
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'hornet'
|
data/lib/hornet.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "redis"
|
2
|
+
require "alphadecimal"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Hornet
|
6
|
+
EVENTS = [
|
7
|
+
"hornet:events:connect",
|
8
|
+
"hornet:events:disconnect"
|
9
|
+
]
|
10
|
+
|
11
|
+
def tokenTTL(tokenTTL)
|
12
|
+
@tokenTTL ||= tokenTTL
|
13
|
+
|
14
|
+
@tokenTTL || 120
|
15
|
+
end
|
16
|
+
|
17
|
+
def redis_options(redis_option={})
|
18
|
+
@redis_options ||= redis_option
|
19
|
+
end
|
20
|
+
|
21
|
+
# tokens are the base62 version of the concatenation (string) of :
|
22
|
+
# - unique id on any number of digits
|
23
|
+
#
|
24
|
+
# - current timestamp (in seconds) left padded to be on 10 digits.
|
25
|
+
# i.e. it means any timestamp will look like : 0001234953.
|
26
|
+
# 10 digits are enough to go to Sat Nov 20 18:46:39 +0100 2286 (9999999999)
|
27
|
+
#
|
28
|
+
# - a random number on 5 digits, again, left padded with 0.
|
29
|
+
# This last part is just to increase the complexity of the token.
|
30
|
+
def create_access_token(channel)
|
31
|
+
token_id = redis.incr "hornet:tokens_id"
|
32
|
+
|
33
|
+
token = (token_id.to_s + generate_token_suffix).alphadecimal
|
34
|
+
|
35
|
+
redis.set "hornet:token:" + token, channel
|
36
|
+
|
37
|
+
return token;
|
38
|
+
end
|
39
|
+
|
40
|
+
def disconnectTokens(tokens)
|
41
|
+
disconnectMsg = "token:" + tokens.to_json
|
42
|
+
|
43
|
+
publish("hornet", "disconnect_tokens", disconnectMsg)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def publish(channel, type, message, options)
|
48
|
+
redis.publish("hornet:channel:" + channel.to_s, message.merge(type).merge(options).to_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def subscribe
|
53
|
+
Redis.new(:host => redis_options['redis_host'], :port => redis_options['redis_port']).subscribe(*EVENTS) do |on|
|
54
|
+
on.message do |type, msg|
|
55
|
+
yield(type.gsub(/^hornet:events:/, "").to_sym, JSON.parse(msg))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def redis
|
62
|
+
@redis ||= Redis.new(redis_options)
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
extend self
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def generate_token_suffix
|
72
|
+
time = Time.now.to_i
|
73
|
+
|
74
|
+
("%010d" % time ) + ("%05d" % rand(100000))
|
75
|
+
end
|
76
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hornet-connector-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Robin Komiwes
|
14
|
+
- Benjamin Tierny
|
15
|
+
- Tristan Bourgois
|
16
|
+
- Maxime Brazeilles
|
17
|
+
autorequire:
|
18
|
+
bindir: bin
|
19
|
+
cert_chain: []
|
20
|
+
|
21
|
+
date: 2011-06-17 00:00:00 Z
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: alphadecimal
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Hornet Ruby Connector is a connector for Hornet, a realtime engine backed by Redis and Socket.io
|
38
|
+
email: robin.komiwes@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- hornet-connector-ruby.gemspec
|
55
|
+
- init.rb
|
56
|
+
- lib/hornet.rb
|
57
|
+
- test/hornet-connector-ruby_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
homepage: http://github.com/nectify/hornet-connector-ruby
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: hornet-connector-ruby
|
88
|
+
rubygems_version: 1.8.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Hornet Ruby Connector - Realtime engine for webapps
|
92
|
+
test_files:
|
93
|
+
- test/hornet-connector-ruby_test.rb
|
94
|
+
- test/test_helper.rb
|