rbkubemq 0.0.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 037bd6fcea0ed99f88688ec9ac7c34f71425fba22655b1dfd283f3c30428c0f2
4
- data.tar.gz: 2c63229009a6e41367d013568ea7de34b31fe2829109765758bc88d498009e2e
3
+ metadata.gz: fd2feb3d11caab95efa41a9c63a2e0fd0b2522ec5d2782589b954eeea6d0b548
4
+ data.tar.gz: 6b074e5fc0adbd3579df176ccb8b3d7a87c2aaac1881667af2d0ff2379141692
5
5
  SHA512:
6
- metadata.gz: 35f0b187dbcac8eeaac2a533a45aacac2ff01baccd34844334a7cdeee3491c31f054c14f6b40b04746c75d3e7e1c0feac97a1d000b7bad0fec0163f9a7bab1a4
7
- data.tar.gz: 92e823ed208562b20e59702341c37d23256123e221751ca83dacf0e88f110eb3983fdc9cba2bf1c8d14d2fd6fe39fa0fec406287cc0078c4f5af03751b4a3e64
6
+ metadata.gz: e0f011264cebac6aa0eb4f8ce96ff2d318a9e37a347e2d00b6628c3e1e154aa01564aeb31ecfe21fd93bd39f89d0fa799ed9ed12e093c9c39f612bbc16d70a01
7
+ data.tar.gz: 044db2136aacc0c1103799176a79172e9e2f89c144bb34464af30064c0e77e26885740037e13765e5e2378973da2afd31f5349246f6aca5ad146455464f986ec
data/RBKubeMQ.gemspec CHANGED
@@ -4,13 +4,14 @@ require "rake"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'rbkubemq'
7
- s.version = '0.0.2'
7
+ s.version = '0.1.0'
8
8
  s.authors = ['Stefano Martin']
9
9
  s.email = ['stefano@seluxit.com']
10
10
  s.homepage = 'https://github.com/Seluxit/RBKubeMQ'
11
11
  s.license = 'MIT'
12
12
  s.summary = 'A simple gem for KubeMQ'
13
- s.description = "Ruby driver for RBKubeMQ"
13
+ s.description = "Ruby driver for KubeMQ"
14
+ s.required_ruby_version = '>= 2.5.0'
14
15
  s.platform = Gem::Platform::RUBY
15
16
  s.require_paths = ['lib']
16
17
  s.files = FileList['lib/**/*', 'RBKubeMQ.gemspec', 'Gemfile', 'LICENSE', 'README.md'].to_a
data/README.md CHANGED
@@ -63,26 +63,25 @@ i = 0
63
63
  EM.run do
64
64
  streamer = client.streamer(client_id: "YOUR_CLIENT", channel: "YOUR_CHANNEL",
65
65
  meta: nil, store: false)
66
- ws = streamer.start # Create a websocket by starting it
67
66
 
68
- ws.on :open do |event|
67
+ streamer.on :open do |event|
69
68
  p [:open]
70
69
  end
71
70
 
72
- ws.on :message do |event|
71
+ streamer.on :message do |event|
73
72
  p [:message, RBKubeMQ::Utility.load(event.data)]
74
73
  end
75
74
 
76
- ws.on :close do |event|
75
+ streamer.on :close do |event|
77
76
  p [:close]
78
- ws = nil; EM.stop
77
+ streamer = nil; EM.stop
79
78
  end
80
79
 
81
80
  # Send a message every second
82
81
  timer = EM::PeriodicTimer.new(1) do
83
82
  i += 1
84
83
  puts "SENDING #{i}"
85
- streamer.send(i, meta: "Stream") # Note that we use streamer and not ws to send the stream
84
+ streamer.send(i, meta: "Stream")
86
85
  end
87
86
  end
88
87
  ```
@@ -97,25 +96,24 @@ It cannot be use to send data.
97
96
  EM.run do
98
97
  subscriber = client.subscriber(client_id: "YOUR_CLIENT", channel: "YOUR_CHANNEL",
99
98
  group: "YOUR_GROUP")
100
- ws = subscriber.events
101
99
 
102
- ws.on :open do |event|
100
+ subscriber.on :open do |event|
103
101
  p [:open]
104
102
  end
105
103
 
106
- ws.on :message do |event|
104
+ subscriber.on :message do |event|
107
105
  p [:message, RBKubeMQ::Utility.load(event.data)]
108
106
  end
109
107
 
110
- ws.on :close do |event|
108
+ subscriber.on :close do |event|
111
109
  p [:close]
112
- ws = nil; EM.stop
110
+ subscriber = nil; EM.stop
113
111
  end
114
112
  end
115
113
  ```
116
114
 
117
115
  In the example the subscriber is for events.
118
- You can subscribe to "events_store", "requests", and "queries".
116
+ You can subscribe to "events_store", "commands", and "queries" by specifying "type: events_store" during the initialization.
119
117
 
120
118
  <a name="RKMQUtility"></a>
121
119
  ## RBKubeMQ::Utility
@@ -129,3 +127,13 @@ RBKubeMQ::Utility.load(string) # Parse hash in human format from KubeMQ
129
127
  ## RBKubeMQ::Error
130
128
 
131
129
  RBKubeMQ::Error is used to manage generic errors inside of the gem.
130
+
131
+ ## Test
132
+
133
+ To test, create a file "config.yml" in the "spec" folder with inside:
134
+
135
+ ```ruby
136
+ host: YOUR_KYBEMQ_HOST
137
+ ```
138
+
139
+ Then run the tests with `rspec spec/lib/sender.rb`.
data/lib/helpers/check.rb CHANGED
@@ -4,5 +4,10 @@ module RBKubeMQ
4
4
  return if classes.include?(object.class)
5
5
  raise RBKubeMQ::Error.new("#{name} should be #{classes.map(&:to_s).join(", ")}")
6
6
  end
7
+
8
+ def is_in_list?(value, list, name)
9
+ return if list.include?(value)
10
+ raise RBKubeMQ::Error.new("#{name} should be #{list.join(", ")}")
11
+ end
7
12
  end
8
13
  end
data/lib/streamer.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RBKubeMQ
2
- class Streamer
2
+ class Streamer < Faye::WebSocket::Client
3
3
  include Check
4
4
 
5
5
  def initialize(client:, client_id: nil, channel: nil, meta: nil, store: false)
@@ -9,14 +9,10 @@ module RBKubeMQ
9
9
  @channel = channel
10
10
  @meta = meta.nil? ? meta.to_s : meta
11
11
  @store = store
12
+ super("#{@client.ws}/send/stream")
12
13
  end
13
14
 
14
- attr_accessor :client_id, :channel, :meta, :store
15
-
16
- def start
17
- @ws = Faye::WebSocket::Client.new("#{@client.ws}/send/stream")
18
- @ws
19
- end
15
+ attr_reader :client_id, :channel, :meta, :store
20
16
 
21
17
  def send(message, meta: @meta, store: @store, client_id: @client_id,
22
18
  channel: @channel, id: nil)
@@ -28,7 +24,7 @@ module RBKubeMQ
28
24
  "Body" => message,
29
25
  "Store" => store
30
26
  }
31
- @ws.send(RBKubeMQ::Utility.dump(body))
27
+ super(RBKubeMQ::Utility.dump(body))
32
28
  rescue StandardError => e
33
29
  raise RBKubeMQ::Error.new(e.message)
34
30
  end
data/lib/subscriber.rb CHANGED
@@ -1,53 +1,33 @@
1
1
  module RBKubeMQ
2
- class Subscriber
2
+ class Subscriber < Faye::WebSocket::Client
3
3
  include Check
4
4
 
5
5
  def initialize(client:, client_id: nil, channel: nil, group: nil,
6
- events_store_type_data: 1, events_store_type_value: nil)
6
+ events_store_type_data: 1, events_store_type_value: nil, type: "events")
7
7
  is_class?(client, [RBKubeMQ::Client], "client")
8
+ type = type.to_s
9
+ is_in_list?(type, ["events", "events_store", "commands", "queries"], "type")
8
10
  @client = client
9
11
  @client_id = client_id
10
12
  @channel = channel
11
13
  @group = group
12
14
  @events_store_type_data = events_store_type_data
13
15
  @events_store_type_value = events_store_type_value
14
- end
15
-
16
- attr_accessor :client_id, :channel, :meta, :store, :group,
17
- :events_store_type_data, :events_store_type_value
18
-
19
- def events
20
- url = "#{@client.ws}/subscribe/events?client_id=#{@client_id}&channel=#{@channel}"
21
- url += "&group=#{@group}" unless @group.nil?
22
- url += "&subscribe_type=events"
23
- @ws = Faye::WebSocket::Client.new(url)
24
- @ws
25
- end
26
-
27
- def events_store
28
- url = "#{@client.ws}/subscribe/events?client_id=#{@client_id}&channel=#{@channel}"
16
+ @type = type
17
+ url = "#{@client.ws}/subscribe/"
18
+ case type
19
+ when "events", "events_store"
20
+ url += "events"
21
+ when "commands", "queries"
22
+ url += "requests"
23
+ end
24
+ url += "?client_id=#{@client_id}&channel=#{@channel}"
29
25
  url += "&group=#{@group}" unless @group.nil?
30
- url += "&events_store_type_data=#{@events_store_type_data}"
31
- url += "&events_store_type_value=#{@events_store_type_value}" unless @events_store_type_value.nil?
32
- url += "&subscribe_type=events_store"
33
- @ws = Faye::WebSocket::Client.new(url)
34
- @ws
26
+ url += "&subscribe_type=#{@type}"
27
+ super(url)
35
28
  end
36
29
 
37
- def requests
38
- url = "#{@client.ws}/subscribe/requests?client_id=#{@client_id}&channel=#{@channel}"
39
- url += "&group=#{@group}" unless @group.nil?
40
- url += "&subscribe_type=commands"
41
- @ws = Faye::WebSocket::Client.new(url)
42
- @ws
43
- end
44
-
45
- def queries
46
- url = "#{@client.ws}/subscribe/requests?client_id=#{@client_id}&channel=#{@channel}"
47
- url += "&group=#{@group}" unless @group.nil?
48
- url += "&subscribe_type=queries"
49
- @ws = Faye::WebSocket::Client.new(url)
50
- @ws
51
- end
30
+ attr_reader :client_id, :channel, :meta, :store, :group,
31
+ :events_store_type_data, :events_store_type_value, :type
52
32
  end
53
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbkubemq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -70,7 +70,7 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.10.7
73
- description: Ruby driver for RBKubeMQ
73
+ description: Ruby driver for KubeMQ
74
74
  email:
75
75
  - stefano@seluxit.com
76
76
  executables: []
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: 2.5.0
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="