fanout 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fanout.rb +24 -6
- data/lib/jsonobjectformat.rb +5 -0
- 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: c00a6654cc9a1afe647949d47e308e7e26a9cd3c
|
4
|
+
data.tar.gz: 779264dc8a6f2b90ee91ee53b4bcf91a12f15c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc3caeb96825aa789e7493abe3a06c5d56412703aeb09b7c3a443d5bb53c4416c3e4f39ca9e2da10f6732b2e8047a13cf74e5d10c3720b1834908e54aeb36b6
|
7
|
+
data.tar.gz: 2f030df94aa915a6c5f2a55e52d6929e72a45206163c00a2cb38b941bfc0d7ed6c14c3daf7faf8654590bd162788ec7d03630a032e0422b30090ce49c525fe51
|
data/lib/fanout.rb
CHANGED
@@ -10,7 +10,19 @@ require 'thread'
|
|
10
10
|
require 'pubcontrol'
|
11
11
|
require_relative 'jsonobjectformat.rb'
|
12
12
|
|
13
|
+
# The Fanout class is used for publishing messages to Fanout.io and is
|
14
|
+
# configured with a Fanout.io realm and associated key. SSL can either
|
15
|
+
# be enabled or disabled. As a convenience, the realm and key
|
16
|
+
# can also be configured by setting the 'FANOUT_REALM' and 'FANOUT_KEY'
|
17
|
+
# environmental variables. Note that unlike the PubControl class
|
18
|
+
# there is no need to call the finish method manually, as it will
|
19
|
+
# automatically be called when the calling program exits.
|
13
20
|
class Fanout
|
21
|
+
|
22
|
+
# Initialize with a specified realm, key, and a boolean indicating wther
|
23
|
+
# SSL should be enabled or disabled. Note that if the realm and key
|
24
|
+
# are omitted then the initialize method will use the 'FANOUT_REALM'
|
25
|
+
# and 'FANOUT_KEY' environmental variables.
|
14
26
|
def initialize(realm=nil, key=nil, ssl=true)
|
15
27
|
if realm.nil?
|
16
28
|
realm = ENV['FANOUT_REALM']
|
@@ -21,14 +33,21 @@ class Fanout
|
|
21
33
|
@realm = realm
|
22
34
|
@key = key
|
23
35
|
@ssl = ssl
|
24
|
-
at_exit { finish }
|
25
36
|
end
|
26
37
|
|
38
|
+
# Synchronously publish the specified data to the specified channel for
|
39
|
+
# the configured Fanout.io realm. Optionally provide an ID and previous
|
40
|
+
# ID to send along with the message.
|
27
41
|
def publish(channel, data, id=nil, prev_id=nil)
|
28
42
|
pub = get_pubcontrol
|
29
43
|
pub.publish(channel, Item.new(JsonObjectFormat.new(data), id, prev_id))
|
30
44
|
end
|
31
45
|
|
46
|
+
# Asynchronously publish the specified data to the specified channel for
|
47
|
+
# the configured Fanout.io realm. Optionally provide an ID and previous ID
|
48
|
+
# to send along with the message, as well a callback method that will be
|
49
|
+
# called after publishing is complete and passed the result and error message
|
50
|
+
# if an error was encountered.
|
32
51
|
def publish_async(channel, data, id=nil, prev_id=nil, callback=nil)
|
33
52
|
pub = get_pubcontrol
|
34
53
|
pub.publish_async(channel, Item.new(JsonObjectFormat.new(data), id,
|
@@ -37,11 +56,9 @@ class Fanout
|
|
37
56
|
|
38
57
|
private
|
39
58
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
59
|
+
# An internal method used for retrieving the PubControl instance. The
|
60
|
+
# PubControl instance is saved as a thread variable and if an instance
|
61
|
+
# is not available when this method is called then one will be created.
|
45
62
|
def get_pubcontrol
|
46
63
|
if Thread.current['pubcontrol'].nil?
|
47
64
|
if @ssl
|
@@ -52,6 +69,7 @@ class Fanout
|
|
52
69
|
pub = PubControlClient.new(
|
53
70
|
'%s://api.fanout.io/realm/%s' % [scheme, @realm])
|
54
71
|
pub.set_auth_jwt({'iss' => @realm}, Base64.decode64(@key))
|
72
|
+
at_exit { pub.finish }
|
55
73
|
Thread.current['pubcontrol'] = pub
|
56
74
|
end
|
57
75
|
return Thread.current['pubcontrol']
|
data/lib/jsonobjectformat.rb
CHANGED
@@ -7,15 +7,20 @@
|
|
7
7
|
|
8
8
|
require 'pubcontrol'
|
9
9
|
|
10
|
+
# The JSON object format used for publishing messages to Fanout.io.
|
10
11
|
class JsonObjectFormat < Format
|
12
|
+
|
13
|
+
# Initialize with a value representing the message to be sent.
|
11
14
|
def initialize(value)
|
12
15
|
@value = value
|
13
16
|
end
|
14
17
|
|
18
|
+
# The name of the format.
|
15
19
|
def name
|
16
20
|
return 'json-object'
|
17
21
|
end
|
18
22
|
|
23
|
+
# The method used to export the format data.
|
19
24
|
def export
|
20
25
|
return @value
|
21
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Bokarius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pubcontrol
|