pubcontrol 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pubcontrol.rb +7 -13
- data/lib/pubcontrolset.rb +14 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab97545468d3337e4e281e5d36f515a3acb707d4
|
4
|
+
data.tar.gz: f9649e54bce224b03683182c09583c283b358e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffe3037a12a43e76a5a1fbc09cccda35833c3c5528c04ee66d3ccdb670ae657f0d300a4e88a1410d63e8d83959083a8a9836dfe7cfc68f3cf695fe85093751bc
|
7
|
+
data.tar.gz: cfd4eb7cd7c050d8e67c5741545a1ceba708f0f4e29b32d5c2f7a423ebbe7b26508cfffc408e850d121afc6be63ed32fc05dc5e4d16604038b96f65297c3cf8b
|
data/lib/pubcontrol.rb
CHANGED
@@ -18,7 +18,7 @@ require_relative 'pubcontrolset.rb'
|
|
18
18
|
class PubControl
|
19
19
|
attr_accessor :req_queue
|
20
20
|
|
21
|
-
def initialize(uri
|
21
|
+
def initialize(uri)
|
22
22
|
@uri = uri
|
23
23
|
@lock = Mutex.new
|
24
24
|
@thread = nil
|
@@ -29,7 +29,6 @@ class PubControl
|
|
29
29
|
@auth_basic_pass = nil
|
30
30
|
@auth_jwt_claim = nil
|
31
31
|
@auth_jwt_key = nil
|
32
|
-
@use_ssl = use_ssl
|
33
32
|
end
|
34
33
|
|
35
34
|
def set_auth_basic(username, password)
|
@@ -55,7 +54,7 @@ class PubControl
|
|
55
54
|
uri = @uri
|
56
55
|
auth = gen_auth_header
|
57
56
|
end
|
58
|
-
PubControl.pubcall(uri, auth, [export]
|
57
|
+
PubControl.pubcall(uri, auth, [export])
|
59
58
|
end
|
60
59
|
|
61
60
|
def publish_async(channel, item, callback=nil)
|
@@ -103,23 +102,22 @@ class PubControl
|
|
103
102
|
end
|
104
103
|
@thread_mutex.unlock
|
105
104
|
if reqs.length > 0
|
106
|
-
PubControl.pubbatch(reqs
|
105
|
+
PubControl.pubbatch(reqs)
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
110
109
|
|
111
|
-
def self.pubcall(uri, auth_header, items
|
110
|
+
def self.pubcall(uri, auth_header, items)
|
112
111
|
uri = URI(uri + '/publish/')
|
113
112
|
content = Hash.new
|
114
113
|
content['items'] = items
|
115
|
-
# REVIEW: POST implementation
|
116
114
|
request = Net::HTTP::Post.new(uri.request_uri)
|
117
|
-
# REVIEW: is simply encoding in UTF-8 correct here?
|
118
115
|
request.body = content.to_json
|
119
116
|
if !auth_header.nil?
|
120
117
|
request['Authorization'] = auth_header
|
121
118
|
end
|
122
119
|
request['Content-Type'] = 'application/json'
|
120
|
+
use_ssl = uri.scheme == 'https'
|
123
121
|
response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
|
124
122
|
http.request(request)
|
125
123
|
end
|
@@ -130,7 +128,7 @@ class PubControl
|
|
130
128
|
end
|
131
129
|
end
|
132
130
|
|
133
|
-
def self.pubbatch(reqs
|
131
|
+
def self.pubbatch(reqs)
|
134
132
|
raise 'reqs length == 0' unless reqs.length > 0
|
135
133
|
uri = reqs[0][0]
|
136
134
|
auth_header = reqs[0][1]
|
@@ -141,7 +139,7 @@ class PubControl
|
|
141
139
|
callbacks.push(req[3])
|
142
140
|
end
|
143
141
|
begin
|
144
|
-
PubControl.pubcall(uri, auth_header, items
|
142
|
+
PubControl.pubcall(uri, auth_header, items)
|
145
143
|
result = [true, '']
|
146
144
|
rescue => e
|
147
145
|
result = [false, e.message]
|
@@ -154,7 +152,6 @@ class PubControl
|
|
154
152
|
end
|
155
153
|
|
156
154
|
def self.timestamp_utcnow
|
157
|
-
# REVIEW: gmtime Ruby implementation
|
158
155
|
return Time.now.utc.to_i
|
159
156
|
end
|
160
157
|
|
@@ -182,13 +179,10 @@ class PubControl
|
|
182
179
|
@thread_cond = ConditionVariable.new
|
183
180
|
@thread_mutex = Mutex.new
|
184
181
|
@thread = Thread.new { pubworker }
|
185
|
-
# REVIEW: Ruby threads are daemonic by default
|
186
|
-
#@thread.daemon = true
|
187
182
|
end
|
188
183
|
end
|
189
184
|
|
190
185
|
def queue_req(req)
|
191
|
-
# REVIEW: thread condition implementation
|
192
186
|
@thread_mutex.lock
|
193
187
|
@req_queue.push_back(req)
|
194
188
|
@thread_cond.signal
|
data/lib/pubcontrolset.rb
CHANGED
@@ -45,20 +45,20 @@ class PubControlSet
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def publish(channel, item
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
def publish(channel, item)
|
49
|
+
@pubs.each do |pub|
|
50
|
+
pub.publish(channel, item)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def publish_async(channel, item, callback=nil)
|
55
|
+
cb = nil
|
56
|
+
if !callback.nil?
|
57
|
+
cb = PubControlCallbackHandler.new(@pubs.length, callback).
|
58
|
+
handler_method_symbol
|
59
|
+
end
|
60
|
+
@pubs.each do |pub|
|
61
|
+
pub.publish_async(channel, item, cb)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|