hornet-connector-ruby 0.3.0 → 0.3.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.
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'alphadecimal', '1.1.1'
4
4
  gem 'redis'
5
- gem 'json'
5
+ gem 'json'
data/README.md CHANGED
@@ -2,22 +2,13 @@
2
2
 
3
3
  ## Description
4
4
 
5
- [Hornet](https://github.com/nectify/hornet) is a realtime engine that let you enhance your web application by connecting users together. [Hornet](https://github.com/nectify/hornet) is a publish/suscribe system extremely easy to use, secure and scalable. Well, [Hornet](https://github.com/nectify/hornet) will integrates very well your own existing application, no matter what language or framework you're using.
5
+ This is the Ruby connector for [Hornet](https://github.com/nectify/hornet) realtime engine.
6
6
 
7
- [Hornet](https://github.com/nectify/hornet) is powered by NodeJs, Socket.io and is backed by Redis.
8
-
9
- The current library is a connector, a piece of software that will make your application able to talk with [Hornet](https://github.com/nectify/hornet). See Hornet README for the connector specification
10
-
11
-
12
- ### Hornet philosophy: core engine and connectors
7
+ [Hornet](https://github.com/nectify/hornet) is a realtime engine that let you enhance your web application by connecting users together. [Hornet](https://github.com/nectify/hornet) is a easy, secure and scalable publish/suscribe system. [Hornet](https://github.com/nectify/hornet) will integrates your own existing application, no matter what language or framework you're using.
13
8
 
14
- Hornet is intented to act as a hub for your existing web application, offering the possibility to keep a pool of connected users and broadcasting messages to them in realtime. That's where NodeJS is goot at.
15
-
16
- The connector is a small library that your existing application will use to connect your clients to Hornet and to broadcast message to them. When a client access a page with realtime features on it, your web application will generates a connection token to let the client subscribe to a hornet channel.
17
-
18
- When you want to broadcast a message to a specific channel, you'll also use the hornet connector to publish it. Using Redis publish/subscribe mechanism, Hornet core engines will be notified by this new message and transfer it to subscribed clients.
9
+ [Hornet](https://github.com/nectify/hornet) is powered by NodeJs, Socket.io and is backed by Redis.
19
10
 
20
- Hornet messages should always be JSON valid objects, containing at least the "type" attribute.
11
+ See [Hornet](https://github.com/nectify/hornet) README for more information about Hornet and the connector specification
21
12
 
22
13
  ## Connector Installation
23
14
 
@@ -27,5 +18,4 @@ Add the following dependency in your Gemfile:
27
18
 
28
19
  ## License
29
20
 
30
- This project is distributed under Apache 2 License. See LICENSE.txt for more information.
31
-
21
+ This project is distributed under Apache 2 License. See LICENSE.txt for more information.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hornet-connector-ruby"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robin Komiwes", "Benjamin Tierny", "Tristan Bourgois", "Maxime Brazeilles"]
@@ -14,7 +14,7 @@ module Hornet
14
14
  @token_TTL || 120
15
15
  end
16
16
 
17
- def redis_options(redis_option={})
17
+ def redis_options( redis_option = {} )
18
18
  @redis_options ||= redis_option
19
19
  end
20
20
 
@@ -27,20 +27,36 @@ module Hornet
27
27
  #
28
28
  # - a random number on 5 digits, again, left padded with 0.
29
29
  # This last part is just to increase the complexity of the token.
30
- def create_access_token(channel)
30
+ def create_access_token( *args )
31
31
  token_id = redis.incr "hornet:tokens_id"
32
32
 
33
33
  token = (token_id.to_s + generate_token_suffix).to_i.alphadecimal
34
34
 
35
35
  key = "hornet:token:" + token
36
+ if args[0].is_a? Hash
37
+ opts = args[0]
36
38
 
37
- redis.set key, channel
39
+ if opts[:channels]
40
+
41
+ opts[:channels].each do |channel|
42
+ redis.sadd key, channel
43
+ end
44
+
45
+ elsif opts[:channel]
46
+ redis.sadd key, opts[:channel]
47
+ end
48
+
49
+ else
50
+ puts '*** DEPRECATED : Please use :channel => "#{args[0]}" instead of "#{args[0]}" ***'
51
+ redis.sadd key, args[0]
52
+ end
38
53
 
39
54
  redis.expire key, token_TTL
40
55
 
41
- return token;
56
+ return token
42
57
  end
43
58
 
59
+
44
60
  def disconnect_tokens(tokens)
45
61
  disconnectMsg = "token:" + tokens.to_json
46
62
 
@@ -48,8 +64,26 @@ module Hornet
48
64
  end
49
65
 
50
66
 
51
- def publish(channel, type, message, options = {})
52
- redis.publish("hornet:channel:" + channel.to_s, message.merge(:type => type).merge(options).to_json)
67
+ def publish( *args )
68
+ if args[0].is_a? Hash
69
+ opts = args[0]
70
+ opts[:options] ||= {}
71
+
72
+ if opts[:channels]
73
+
74
+ opts[:channels].each do |channel|
75
+ redis.publish("hornet:channel:" + channel.to_s, opts[:message].merge( :type => opts[:type], :channel => channel.to_s ).merge(opts[:options]).to_json )
76
+ end
77
+
78
+ elsif opts[:channel]
79
+ redis.publish("hornet:channel:" + opts[:channel].to_s, opts[:message].merge( :type => opts[:type], :channel => opts[:channel].to_s ).merge(opts[:options]).to_json )
80
+ end
81
+
82
+ else
83
+ puts '*** DEPRECATED : Please use :type , :channel(s) :message :options instead of direct args ***'
84
+ args[3] ||= {}
85
+ redis.publish("hornet:channel:" + args[0].to_s, args[2].merge( :type => args[1].to_s, :channel => args[0].to_s ).merge( args[3] ).to_json)
86
+ end
53
87
  end
54
88
 
55
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hornet-connector-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,7 @@ date: 2012-01-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: alphadecimal
19
- requirement: &70312994167200 !ruby/object:Gem::Requirement
19
+ requirement: &70358017108060 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - =
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 1.1.1
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70312994167200
27
+ version_requirements: *70358017108060
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: redis
30
- requirement: &70312994165460 !ruby/object:Gem::Requirement
30
+ requirement: &70358017107400 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70312994165460
38
+ version_requirements: *70358017107400
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: json
41
- requirement: &70312994164740 !ruby/object:Gem::Requirement
41
+ requirement: &70358017106700 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70312994164740
49
+ version_requirements: *70358017106700
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: alphadecimal
52
- requirement: &70312994386180 !ruby/object:Gem::Requirement
52
+ requirement: &70358017106180 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '0'
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *70312994386180
60
+ version_requirements: *70358017106180
61
61
  description: Hornet Ruby Connector is a connector for Hornet, a realtime engine backed
62
62
  by Redis and Socket.io
63
63
  email: robin.komiwes@gmail.com