pubcontrol 0.1.2 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pubcontrol.rb +7 -13
  3. data/lib/pubcontrolset.rb +14 -14
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e6fcb8db8ed8cda62abecf09a037501fb5ae547
4
- data.tar.gz: ef00fbf3e4963a288125f5743c9015d85f8d5b52
3
+ metadata.gz: ab97545468d3337e4e281e5d36f515a3acb707d4
4
+ data.tar.gz: f9649e54bce224b03683182c09583c283b358e4c
5
5
  SHA512:
6
- metadata.gz: de5f3cc596bdbffdf7ff2c4bd1b1d6d2419847800e1624c0f942198466d6842bc04113a8cd6b2d8a298eee69dec243627d06f4d3002c07a532e1475f19a758fe
7
- data.tar.gz: 300373c255dde069f23af2aa014814f909367a3748b40399e72824d178aeec831de17a7a8228d714796f7d377da78b2b0d303c2223dd2184c0984f8d1d3bd4f0
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, use_ssl=true)
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], @use_ssl)
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, @use_ssl)
105
+ PubControl.pubbatch(reqs)
107
106
  end
108
107
  end
109
108
  end
110
109
 
111
- def self.pubcall(uri, auth_header, items, use_ssl)
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, use_ssl)
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, use_ssl)
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, blocking=false, callback=nil)
49
- if blocking
50
- @pubs.each do |pub|
51
- pub.publish(channel, item)
52
- end
53
- else
54
- cb = nil
55
- if !callback.nil?
56
- cb = PubControlCallbackHandler.new(@pubs.length, callback).
57
- handler_method_symbol
58
- end
59
- @pubs.each do |pub|
60
- pub.publish_async(channel, item, cb)
61
- end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubcontrol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Bokarius