rabbitmq_http_api_client 1.10.0 → 1.15.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: bcb0d38735668c5d24d9453c2ccacb36a1489b67c37496f8e51edd482cd80c35
4
- data.tar.gz: fa2c2e65299bfc15c18ca63e3e1967e3d15482f46c772c518d35d84d8e688b53
3
+ metadata.gz: 8f9e2a79489994cac18b3d82cbae44444ad8c9f8336918beac33b2027f9a252e
4
+ data.tar.gz: 6ecb5b243fa30f127992fdc1dda6c5b60e69612c2b2bfc0138f3dfb38856e05d
5
5
  SHA512:
6
- metadata.gz: 6ad71e4808cc10fc7425774085c2fc145976a312bedc3fe1ffb0a7eef9bfc154b669db2b709c7ac043895c6bb32557502c556fd862427c82ef3e43a31422ccd9
7
- data.tar.gz: b04199becc89fbdf33623103394999a2724610a9d2808569453fdab4e206fbd4b24b9716b6884aa1de3b18a01516865014e1e823902f8fe3fd98b3cec46b2057
6
+ metadata.gz: 6f92d37c3b8aed5323318cb4a1977d23783576e9e0c2a4add3a3dbf56c47f26777b261a8f9b2a8c260c7a5ece1b2ed4a80d99f7eb03d3d2c6d1a423096b6480b
7
+ data.tar.gz: 2bf80f3b75c092791b1673823d877b1ce8bb49e118550a7da9931a2dea1b8419c4912b122516c0b95292065566bc3c5fd035702e0ca4a864faa6ab93e59f6365
data/ChangeLog.md CHANGED
@@ -1,3 +1,66 @@
1
+ ## Changes Between 1.15.0 and 1.16.0 (unreleased)
2
+
3
+ No changes yet.
4
+
5
+ ## Changes Between 1.14.0 and 1.15.0 (February 16th, 2021)
6
+ ### Content Length Detection Changes
7
+
8
+ When deserialising response bodies, the client now uses actual body length instead of
9
+ the value of the `content-length` header.
10
+
11
+ Contributed by Ryan @rquant Quant.
12
+
13
+ GitHub issue: [#49](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/49)
14
+
15
+ ## Changes Between 1.13.0 and 1.14.0 (July 8th, 2020)
16
+
17
+ ### URI.escape is No Longer Used
18
+
19
+ Deprecated `URI.escape` has been replaced with `Addressable::URI.escape_component`.
20
+ This introduces `addressable` as a new dependency.
21
+
22
+ ### Dependency Bump
23
+
24
+ Note: Faraday will now raise a `Faraday::ResourceNotFound` instead of `Faraday::Error::ResourceNotFound`.
25
+
26
+ GitHub issue: [#45](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/45)
27
+
28
+ Contributed by Niels Jansen.
29
+
30
+ ## Changes Between 1.12.0 and 1.13.0 (March 5th, 2020)
31
+
32
+ ### Pagination Support
33
+
34
+ GitHub issue: [#43](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/43)
35
+
36
+ Contributed by Rustam Sharshenov.
37
+
38
+ ### Dependency Updates
39
+
40
+ GitHub issue: [#42](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/42)
41
+
42
+ Contributed by @hatch-carl.
43
+
44
+
45
+ ## Changes Between 1.11.0 and 1.12.0 (March 12th, 2019)
46
+
47
+ ### Dependency Updates
48
+
49
+ GitHub issue: [#38](https://github.com/ruby-amqp/rabbitmq_http_api_client/pull/38)
50
+
51
+ Contributed by Jon Homan.
52
+
53
+
54
+ ## Changes Between 1.10.0 and 1.11.0 (Dec 25th, 2018)
55
+
56
+ ### effin_utf8 Dependency Dropped
57
+
58
+ This library no longer supports Ruby 1.8 and thus
59
+ doesn't need to depend on the `effin_utf8` gem.
60
+
61
+ Contributed by Luciano Sousa.
62
+
63
+
1
64
  ## Changes Between 1.9.0 and 1.10.0 (Nov 27th, 2018)
2
65
 
3
66
  ### Improved Resource Deserialisation
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2017 Michael Klishin
1
+ Copyright (c) 2012-2020 Michael Klishin
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -18,9 +18,9 @@ and will support more HTTP API features in the future
18
18
 
19
19
  ## Supported Ruby Versions
20
20
 
21
- * CRuby 2.0 through 2.4.x
21
+ * CRuby 2.2 through 2.7.x
22
22
  * JRuby 9K
23
-
23
+
24
24
  ## Supported RabbitMQ Versions
25
25
 
26
26
  * RabbitMQ 3.x
@@ -32,7 +32,7 @@ All versions require [RabbitMQ Management UI plugin](http://www.rabbitmq.com/man
32
32
  Add this line to your application's Gemfile:
33
33
 
34
34
  ``` ruby
35
- gem 'rabbitmq_http_api_client', '>= 1.9.1'
35
+ gem 'rabbitmq_http_api_client', '>= 1.13.0'
36
36
  ```
37
37
 
38
38
  And then execute:
@@ -59,7 +59,7 @@ Use `RabbitMQ::HTTP::Client#connect` to specify RabbitMQ HTTP API endpoint (e.g.
59
59
  require "rabbitmq/http/client"
60
60
 
61
61
  endpoint = "http://127.0.0.1:15672"
62
- client = RabbitMQ::HTTP::Client.new(endpoint, :username => "guest", :password => "guest")
62
+ client = RabbitMQ::HTTP::Client.new(endpoint, username: "guest", password: "guest")
63
63
  ```
64
64
 
65
65
  Alternatively, credentials can be specified in the endpoint URI:
@@ -127,7 +127,7 @@ puts n.proc_used
127
127
  puts n.fd_total
128
128
 
129
129
  # Get Management Plugin extension list
130
- xs = client.list_extensions
130
+ xs = client.list_extensions
131
131
 
132
132
  # List all the entities (vhosts, queues, exchanges, bindings, users, etc)
133
133
  defs = client.list_definitions
@@ -259,7 +259,7 @@ puts b.vhost
259
259
  # List all bindings in a vhost
260
260
  bs = client.list_bindings("/")
261
261
 
262
- # List all binsings between an exchange and a queue
262
+ # List all bindings between an exchange and a queue
263
263
  bs = client.list_bindings_between_queue_and_exchange("/", "collector1.megacorp.local", "log.events")
264
264
  ```
265
265
 
@@ -371,5 +371,4 @@ and rabbitmq-management plugin enabled.
371
371
 
372
372
  Double-licensed under the MIT and Mozilla Public License (same as RabbitMQ).
373
373
 
374
- (c) Michael S. Klishin, 2012-2017.
375
-
374
+ (c) Michael S. Klishin, 2012-2020.
@@ -1,3 +1,4 @@
1
+ require "addressable/uri"
1
2
  require "hashie"
2
3
  require "faraday"
3
4
  require "faraday_middleware"
@@ -57,16 +58,16 @@ module RabbitMQ
57
58
  reduce(Hash.new) { |acc, lnr| acc[lnr.protocol] = lnr.port; acc }
58
59
  end
59
60
 
60
- def list_nodes
61
- decode_resource_collection(@connection.get("nodes"))
61
+ def list_nodes(query = {})
62
+ decode_resource_collection(@connection.get("nodes", query))
62
63
  end
63
64
 
64
65
  def node_info(name)
65
- decode_resource(@connection.get("nodes/#{uri_encode(name)}"))
66
+ decode_resource(@connection.get("nodes/#{encode_uri_path_segment(name)}"))
66
67
  end
67
68
 
68
- def list_extensions
69
- decode_resource_collection(@connection.get("extensions"))
69
+ def list_extensions(query = {})
70
+ decode_resource_collection(@connection.get("extensions", query))
70
71
  end
71
72
 
72
73
  def list_definitions
@@ -81,34 +82,34 @@ module RabbitMQ
81
82
  response.success?
82
83
  end
83
84
 
84
- def list_connections
85
- decode_resource_collection(@connection.get("connections"))
85
+ def list_connections(query = {})
86
+ decode_resource_collection(@connection.get("connections", query))
86
87
  end
87
88
 
88
89
  def connection_info(name)
89
- decode_resource(@connection.get("connections/#{uri_encode(name)}"))
90
+ decode_resource(@connection.get("connections/#{encode_uri_path_segment(name)}"))
90
91
  end
91
92
 
92
93
  def close_connection(name)
93
- decode_resource(@connection.delete("connections/#{uri_encode(name)}"))
94
+ decode_resource(@connection.delete("connections/#{encode_uri_path_segment(name)}"))
94
95
  end
95
96
 
96
- def list_channels
97
- decode_resource_collection(@connection.get("channels"))
97
+ def list_channels(query = {})
98
+ decode_resource_collection(@connection.get("channels", query))
98
99
  end
99
100
 
100
101
  def channel_info(name)
101
- decode_resource(@connection.get("channels/#{uri_encode(name)}"))
102
+ decode_resource(@connection.get("channels/#{encode_uri_path_segment(name)}"))
102
103
  end
103
104
 
104
- def list_exchanges(vhost = nil)
105
+ def list_exchanges(vhost = nil, query = {})
105
106
  path = if vhost.nil?
106
107
  "exchanges"
107
108
  else
108
- "exchanges/#{uri_encode(vhost)}"
109
+ "exchanges/#{encode_uri_path_segment(vhost)}"
109
110
  end
110
111
 
111
- decode_resource_collection(@connection.get(path))
112
+ decode_resource_collection(@connection.get(path, query))
112
113
  end
113
114
 
114
115
  def declare_exchange(vhost, name, attributes = {})
@@ -119,7 +120,7 @@ module RabbitMQ
119
120
  :arguments => {}
120
121
  }.merge(attributes)
121
122
 
122
- response = @connection.put("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
123
+ response = @connection.put("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
123
124
  req.headers['Content-Type'] = 'application/json'
124
125
  req.body = MultiJson.dump(opts)
125
126
  end
@@ -127,40 +128,40 @@ module RabbitMQ
127
128
  end
128
129
 
129
130
  def delete_exchange(vhost, name, if_unused = false)
130
- response = @connection.delete("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
131
+ response = @connection.delete("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
131
132
  req.params["if-unused"] = true if if_unused
132
133
  end
133
134
  decode_resource(response)
134
135
  end
135
136
 
136
137
  def exchange_info(vhost, name)
137
- decode_resource(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
138
+ decode_resource(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
138
139
  end
139
140
 
140
- def list_bindings_by_source(vhost, exchange)
141
- decode_resource_collection(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source"))
141
+ def list_bindings_by_source(vhost, exchange, query = {})
142
+ decode_resource_collection(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(exchange)}/bindings/source", query))
142
143
  end
143
144
 
144
- def list_bindings_by_destination(vhost, exchange)
145
- decode_resource_collection(@connection.get("exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination"))
145
+ def list_bindings_by_destination(vhost, exchange, query = {})
146
+ decode_resource_collection(@connection.get("exchanges/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(exchange)}/bindings/destination", query))
146
147
  end
147
148
 
148
- def list_queues(vhost = nil)
149
+ def list_queues(vhost = nil, query = {})
149
150
  path = if vhost.nil?
150
151
  "queues"
151
152
  else
152
- "queues/#{uri_encode(vhost)}"
153
+ "queues/#{encode_uri_path_segment(vhost)}"
153
154
  end
154
155
 
155
- decode_resource_collection(@connection.get(path))
156
+ decode_resource_collection(@connection.get(path, query))
156
157
  end
157
158
 
158
159
  def queue_info(vhost, name)
159
- decode_resource(@connection.get("queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
160
+ decode_resource(@connection.get("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
160
161
  end
161
162
 
162
163
  def declare_queue(vhost, name, attributes)
163
- response = @connection.put("queues/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
164
+ response = @connection.put("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
164
165
  req.headers['Content-Type'] = "application/json"
165
166
  req.body = MultiJson.dump(attributes)
166
167
  end
@@ -168,46 +169,46 @@ module RabbitMQ
168
169
  end
169
170
 
170
171
  def delete_queue(vhost, name)
171
- decode_resource(@connection.delete("queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
172
+ decode_resource(@connection.delete("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
172
173
  end
173
174
 
174
- def list_queue_bindings(vhost, queue)
175
- decode_resource_collection(@connection.get("queues/#{uri_encode(vhost)}/#{uri_encode(queue)}/bindings"))
175
+ def list_queue_bindings(vhost, queue, query = {})
176
+ decode_resource_collection(@connection.get("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(queue)}/bindings", query))
176
177
  end
177
178
 
178
179
  def purge_queue(vhost, name)
179
- @connection.delete("queues/#{uri_encode(vhost)}/#{uri_encode(name)}/contents")
180
+ @connection.delete("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}/contents")
180
181
  Hashie::Mash.new
181
182
  end
182
183
 
183
184
  def get_messages(vhost, name, options)
184
- response = @connection.post("queues/#{uri_encode(vhost)}/#{uri_encode(name)}/get") do |req|
185
+ response = @connection.post("queues/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}/get") do |req|
185
186
  req.headers['Content-Type'] = "application/json"
186
187
  req.body = MultiJson.dump(options)
187
188
  end
188
189
  decode_resource_collection(response)
189
190
  end
190
191
 
191
- def list_bindings(vhost = nil)
192
+ def list_bindings(vhost = nil, query = {})
192
193
  path = if vhost.nil?
193
194
  "bindings"
194
195
  else
195
- "bindings/#{uri_encode(vhost)}"
196
+ "bindings/#{encode_uri_path_segment(vhost)}"
196
197
  end
197
198
 
198
- decode_resource_collection(@connection.get(path))
199
+ decode_resource_collection(@connection.get(path, query))
199
200
  end
200
201
 
201
- def list_bindings_between_queue_and_exchange(vhost, queue, exchange)
202
- decode_resource_collection(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}"))
202
+ def list_bindings_between_queue_and_exchange(vhost, queue, exchange, query = {})
203
+ decode_resource_collection(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}", query))
203
204
  end
204
205
 
205
206
  def queue_binding_info(vhost, queue, exchange, properties_key)
206
- decode_resource(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}"))
207
+ decode_resource(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}/#{encode_uri_path_segment(properties_key)}"))
207
208
  end
208
209
 
209
210
  def bind_queue(vhost, queue, exchange, routing_key, arguments = [])
210
- resp = @connection.post("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}") do |req|
211
+ resp = @connection.post("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}") do |req|
211
212
  req.headers['Content-Type'] = 'application/json'
212
213
  req.body = MultiJson.dump({:routing_key => routing_key, :arguments => arguments})
213
214
  end
@@ -215,21 +216,21 @@ module RabbitMQ
215
216
  end
216
217
 
217
218
  def delete_queue_binding(vhost, queue, exchange, properties_key)
218
- resp = @connection.delete("bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}")
219
+ resp = @connection.delete("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(exchange)}/q/#{encode_uri_path_segment(queue)}/#{encode_uri_path_segment(properties_key)}")
219
220
  resp.success?
220
221
  end
221
222
 
222
- def list_bindings_between_exchanges(vhost, destination_exchange, source_exchange)
223
- decode_resource_collection(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}"))
223
+ def list_bindings_between_exchanges(vhost, destination_exchange, source_exchange, query = {})
224
+ decode_resource_collection(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}", query))
224
225
  end
225
226
 
226
227
  def exchange_binding_info(vhost, destination_exchange, source_exchange, properties_key)
227
- decode_resource(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}"))
228
+ decode_resource(@connection.get("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}/#{encode_uri_path_segment(properties_key)}"))
228
229
  end
229
230
 
230
231
 
231
232
  def bind_exchange(vhost, destination_exchange, source_exchange, routing_key, arguments = [])
232
- resp = @connection.post("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}") do |req|
233
+ resp = @connection.post("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}") do |req|
233
234
  req.headers['Content-Type'] = 'application/json'
234
235
  req.body = MultiJson.dump({:routing_key => routing_key, :arguments => arguments})
235
236
  end
@@ -237,48 +238,48 @@ module RabbitMQ
237
238
  end
238
239
 
239
240
  def delete_exchange_binding(vhost, destination_exchange, source_exchange, properties_key)
240
- resp = @connection.delete("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}")
241
+ resp = @connection.delete("bindings/#{encode_uri_path_segment(vhost)}/e/#{encode_uri_path_segment(source_exchange)}/e/#{encode_uri_path_segment(destination_exchange)}/#{encode_uri_path_segment(properties_key)}")
241
242
  resp.success?
242
243
  end
243
244
 
244
245
 
245
- def list_vhosts
246
- decode_resource_collection(@connection.get("vhosts"))
246
+ def list_vhosts(query = {})
247
+ decode_resource_collection(@connection.get("vhosts", query))
247
248
  end
248
249
 
249
250
  def vhost_info(name)
250
- decode_resource(@connection.get("vhosts/#{uri_encode(name)}"))
251
+ decode_resource(@connection.get("vhosts/#{encode_uri_path_segment(name)}"))
251
252
  end
252
253
 
253
254
  def create_vhost(name)
254
- response = @connection.put("vhosts/#{uri_encode(name)}") do |req|
255
+ response = @connection.put("vhosts/#{encode_uri_path_segment(name)}") do |req|
255
256
  req.headers['Content-Type'] = "application/json"
256
257
  end
257
258
  decode_resource(response)
258
259
  end
259
260
 
260
261
  def delete_vhost(name)
261
- decode_resource(@connection.delete("vhosts/#{uri_encode(name)}"))
262
+ decode_resource(@connection.delete("vhosts/#{encode_uri_path_segment(name)}"))
262
263
  end
263
264
 
264
265
 
265
266
 
266
- def list_permissions(vhost = nil)
267
+ def list_permissions(vhost = nil, query = {})
267
268
  path = if vhost
268
- "vhosts/#{uri_encode(vhost)}/permissions"
269
+ "vhosts/#{encode_uri_path_segment(vhost)}/permissions"
269
270
  else
270
271
  "permissions"
271
272
  end
272
273
 
273
- decode_resource_collection(@connection.get(path))
274
+ decode_resource_collection(@connection.get(path, query))
274
275
  end
275
276
 
276
277
  def list_permissions_of(vhost, user)
277
- decode_resource(@connection.get("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
278
+ decode_resource(@connection.get("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}"))
278
279
  end
279
280
 
280
281
  def update_permissions_of(vhost, user, attributes)
281
- response = @connection.put("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}") do |req|
282
+ response = @connection.put("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}") do |req|
282
283
  req.headers['Content-Type'] = "application/json"
283
284
  req.body = MultiJson.dump(attributes)
284
285
  end
@@ -286,23 +287,23 @@ module RabbitMQ
286
287
  end
287
288
 
288
289
  def clear_permissions_of(vhost, user)
289
- decode_resource(@connection.delete("permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
290
+ decode_resource(@connection.delete("permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}"))
290
291
  end
291
292
 
292
293
 
293
294
 
294
- def list_users
295
- decode_resource_collection(@connection.get("users"))
295
+ def list_users(query = {})
296
+ decode_resource_collection(@connection.get("users", query))
296
297
  end
297
298
 
298
299
  def user_info(name)
299
- decode_resource(@connection.get("users/#{uri_encode(name)}"))
300
+ decode_resource(@connection.get("users/#{encode_uri_path_segment(name)}"))
300
301
  end
301
302
 
302
303
  def update_user(name, attributes)
303
304
  attributes[:tags] ||= ""
304
305
 
305
- response = @connection.put("users/#{uri_encode(name)}") do |req|
306
+ response = @connection.put("users/#{encode_uri_path_segment(name)}") do |req|
306
307
  req.headers['Content-Type'] = "application/json"
307
308
  req.body = MultiJson.dump(attributes)
308
309
  end
@@ -311,11 +312,11 @@ module RabbitMQ
311
312
  alias create_user update_user
312
313
 
313
314
  def delete_user(name)
314
- decode_resource(@connection.delete("users/#{uri_encode(name)}"))
315
+ decode_resource(@connection.delete("users/#{encode_uri_path_segment(name)}"))
315
316
  end
316
317
 
317
- def user_permissions(name)
318
- decode_resource_collection(@connection.get("users/#{uri_encode(name)}/permissions"))
318
+ def user_permissions(name, query = {})
319
+ decode_resource_collection(@connection.get("users/#{encode_uri_path_segment(name)}/permissions", query))
319
320
  end
320
321
 
321
322
  def whoami
@@ -324,27 +325,27 @@ module RabbitMQ
324
325
 
325
326
 
326
327
 
327
- def list_policies(vhost = nil)
328
+ def list_policies(vhost = nil, query = {})
328
329
  path = if vhost
329
- "policies/#{uri_encode(vhost)}"
330
+ "policies/#{encode_uri_path_segment(vhost)}"
330
331
  else
331
332
  "policies"
332
333
  end
333
334
 
334
- decode_resource_collection(@connection.get(path))
335
+ decode_resource_collection(@connection.get(path, query))
335
336
  end
336
337
 
337
- def list_policies_of(vhost, name = nil)
338
+ def list_policies_of(vhost, name = nil, query = {})
338
339
  path = if name
339
- "policies/#{uri_encode(vhost)}/#{uri_encode(name)}"
340
+ "policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"
340
341
  else
341
- "policies/#{uri_encode(vhost)}"
342
+ "policies/#{encode_uri_path_segment(vhost)}"
342
343
  end
343
- decode_resource_collection(@connection.get(path))
344
+ decode_resource_collection(@connection.get(path, query))
344
345
  end
345
346
 
346
347
  def update_policies_of(vhost, name, attributes)
347
- response = @connection.put("policies/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
348
+ response = @connection.put("policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
348
349
  req.headers['Content-Type'] = "application/json"
349
350
  req.body = MultiJson.dump(attributes)
350
351
  end
@@ -352,32 +353,32 @@ module RabbitMQ
352
353
  end
353
354
 
354
355
  def clear_policies_of(vhost, name)
355
- decode_resource(@connection.delete("policies/#{uri_encode(vhost)}/#{uri_encode(name)}"))
356
+ decode_resource(@connection.delete("policies/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
356
357
  end
357
358
 
358
359
 
359
360
 
360
361
 
361
- def list_parameters(component = nil)
362
+ def list_parameters(component = nil, query = {})
362
363
  path = if component
363
- "parameters/#{uri_encode(component)}"
364
+ "parameters/#{encode_uri_path_segment(component)}"
364
365
  else
365
366
  "parameters"
366
367
  end
367
- decode_resource_collection(@connection.get(path))
368
+ decode_resource_collection(@connection.get(path, query))
368
369
  end
369
370
 
370
- def list_parameters_of(component, vhost, name = nil)
371
+ def list_parameters_of(component, vhost, name = nil, query = {})
371
372
  path = if name
372
- "parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"
373
+ "parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"
373
374
  else
374
- "parameters/#{uri_encode(component)}/#{uri_encode(vhost)}"
375
+ "parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}"
375
376
  end
376
- decode_resource_collection(@connection.get(path))
377
+ decode_resource_collection(@connection.get(path, query))
377
378
  end
378
379
 
379
380
  def update_parameters_of(component, vhost, name, attributes)
380
- response = @connection.put("parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
381
+ response = @connection.put("parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}") do |req|
381
382
  req.headers['Content-Type'] = "application/json"
382
383
  req.body = MultiJson.dump(attributes)
383
384
  end
@@ -385,13 +386,13 @@ module RabbitMQ
385
386
  end
386
387
 
387
388
  def clear_parameters_of(component, vhost, name)
388
- decode_resource(@connection.delete("parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"))
389
+ decode_resource(@connection.delete("parameters/#{encode_uri_path_segment(component)}/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(name)}"))
389
390
  end
390
391
 
391
392
 
392
393
 
393
394
  def aliveness_test(vhost)
394
- r = @connection.get("aliveness-test/#{uri_encode(vhost)}")
395
+ r = @connection.get("aliveness-test/#{encode_uri_path_segment(vhost)}")
395
396
  r.body["status"] == "ok"
396
397
  end
397
398
 
@@ -416,27 +417,26 @@ module RabbitMQ
416
417
  end
417
418
  end
418
419
 
419
- def uri_encode(s)
420
- # correctly escapes spaces, unlike CGI.escape, see ruby-amqp/rabbitmq_http_api_client#28
421
- URI.escape(s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
420
+ def encode_uri_path_segment(segment)
421
+ # Correctly escapes spaces, see ruby-amqp/rabbitmq_http_api_client#28.
422
+ #
423
+ # Note that slashes also must be escaped since this is a single URI path segment,
424
+ # not an entire path.
425
+ Addressable::URI.encode_component(segment, Addressable::URI::CharacterClasses::UNRESERVED)
422
426
  end
423
427
 
424
428
  def decode_resource(response)
425
- case response.headers["content-length"]
426
- when nil then Hashie::Mash.new
427
- when 0 then Hashie::Mash.new
428
- when "0" then Hashie::Mash.new
429
+ if response.body.empty?
430
+ Hashie::Mash.new
429
431
  else
430
- if response.body.empty?
431
- Hashie::Mash.new
432
- else
433
- Hashie::Mash.new(response.body)
434
- end
432
+ Hashie::Mash.new(response.body)
435
433
  end
436
434
  end
437
435
 
438
436
  def decode_resource_collection(response)
439
- response.body.map { |i| Hashie::Mash.new(i) }
437
+ collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')
438
+
439
+ collection.map { |i| Hashie::Mash.new(i) }
440
440
  end
441
441
  end # Client
442
442
  end # HTTP
@@ -1,7 +1,7 @@
1
1
  module RabbitMQ
2
2
  module HTTP
3
3
  class Client
4
- VERSION = "1.10.0"
4
+ VERSION = "1.15.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_http_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klishin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: hashie
14
+ name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.5'
19
+ version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.5'
26
+ version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: multi_json
28
+ name: hashie
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
33
+ version: '4.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: '4.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: faraday
42
+ name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.13.0
47
+ version: '1.15'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.13.0
54
+ version: '1.15'
55
55
  - !ruby/object:Gem::Dependency
56
- name: faraday_middleware
56
+ name: faraday
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.12.0
61
+ version: '1.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.12.0
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
- name: effin_utf8
70
+ name: faraday_middleware
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.0.0
75
+ version: '1.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.0.0
82
+ version: '1.0'
83
83
  description: RabbitMQ HTTP API client for Ruby
84
84
  email:
85
85
  - michael@clojurewerkz.org
@@ -95,9 +95,9 @@ files:
95
95
  homepage: http://github.com/ruby-amqp/rabbitmq_http_api_client
96
96
  licenses:
97
97
  - MIT
98
- - Mozilla Public License
98
+ - MPL-2.0
99
99
  metadata: {}
100
- post_install_message:
100
+ post_install_message:
101
101
  rdoc_options: []
102
102
  require_paths:
103
103
  - lib
@@ -112,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.7.7
117
- signing_key:
115
+ rubygems_version: 3.1.2
116
+ signing_key:
118
117
  specification_version: 4
119
118
  summary: RabbitMQ HTTP API client for Ruby
120
119
  test_files: []