Class: RabbitMQ::HTTP::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitmq/http/client.rb,
lib/rabbitmq/http/client/version.rb

Constant Summary collapse

VERSION =
"0.3.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, options = {}) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
# File 'lib/rabbitmq/http/client.rb', line 21

def initialize(endpoint, options = {})
  @endpoint = endpoint
  @options  = options

  initialize_connection(endpoint, options)
end

Class Method Details

.connect(endpoint, options = {}) ⇒ Object

API



17
18
19
# File 'lib/rabbitmq/http/client.rb', line 17

def self.connect(endpoint, options = {})
  new(endpoint, options)
end

Instance Method Details

#aliveness_test(vhost) ⇒ Object



312
313
314
315
# File 'lib/rabbitmq/http/client.rb', line 312

def aliveness_test(vhost)
  r = @connection.get("/api/aliveness-test/#{uri_encode(vhost)}")
  r.body["status"] == "ok"
end

#channel_info(name) ⇒ Object



68
69
70
# File 'lib/rabbitmq/http/client.rb', line 68

def channel_info(name)
  decode_resource(@connection.get("/api/channels/#{uri_encode(name)}"))
end

#clear_parameters_of(component, vhost, name) ⇒ Object



306
307
308
# File 'lib/rabbitmq/http/client.rb', line 306

def clear_parameters_of(component, vhost, name)
  decode_resource(@connection.delete("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#clear_permissions_of(vhost, user) ⇒ Object



209
210
211
# File 'lib/rabbitmq/http/client.rb', line 209

def clear_permissions_of(vhost, user)
  decode_resource(@connection.delete("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
end

#clear_policies_of(vhost, name) ⇒ Object



273
274
275
# File 'lib/rabbitmq/http/client.rb', line 273

def clear_policies_of(vhost, name)
  decode_resource(@connection.delete("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#close_connection(name) ⇒ Object



60
61
62
# File 'lib/rabbitmq/http/client.rb', line 60

def close_connection(name)
  decode_resource(@connection.delete("/api/connections/#{uri_encode(name)}"))
end

#connection_info(name) ⇒ Object



56
57
58
# File 'lib/rabbitmq/http/client.rb', line 56

def connection_info(name)
  decode_resource(@connection.get("/api/connections/#{uri_encode(name)}"))
end

#create_vhost(name) ⇒ Object



174
175
176
177
178
179
# File 'lib/rabbitmq/http/client.rb', line 174

def create_vhost(name)
  response = @connection.put("/api/vhosts/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
  end
  decode_resource(response)
end

#declare_queue(vhost, name, attributes) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/rabbitmq/http/client.rb', line 120

def declare_queue(vhost, name, attributes)
  response = @connection.put("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#delete_exchange(vhost, name) ⇒ Object



94
95
96
# File 'lib/rabbitmq/http/client.rb', line 94

def delete_exchange(vhost, name)
  decode_resource(@connection.delete("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#delete_queue(vhost, name) ⇒ Object



128
129
130
# File 'lib/rabbitmq/http/client.rb', line 128

def delete_queue(vhost, name)
  decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#delete_user(name) ⇒ Object



232
233
234
# File 'lib/rabbitmq/http/client.rb', line 232

def delete_user(name)
  decode_resource(@connection.delete("/api/users/#{uri_encode(name)}"))
end

#delete_vhost(name) ⇒ Object



181
182
183
# File 'lib/rabbitmq/http/client.rb', line 181

def delete_vhost(name)
  decode_resource(@connection.delete("/api/vhosts/#{uri_encode(name)}"))
end

#exchange_info(vhost, name) ⇒ Object



82
83
84
# File 'lib/rabbitmq/http/client.rb', line 82

def exchange_info(vhost, name)
  decode_resource(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#get_messages(vhost, name, options) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/rabbitmq/http/client.rb', line 140

def get_messages(vhost, name, options)
  response = @connection.post("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/get") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(options)
  end
  decode_resource_collection(response)
end

#list_bindings(vhost = nil) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/rabbitmq/http/client.rb', line 149

def list_bindings(vhost = nil)
  path = if vhost.nil?
           "/api/bindings"
         else
           "/api/bindings/#{uri_encode(vhost)}"
         end

  decode_resource_collection(@connection.get(path))
end

#list_bindings_between_queue_and_exchange(vhost, queue, exchange) ⇒ Object



159
160
161
# File 'lib/rabbitmq/http/client.rb', line 159

def list_bindings_between_queue_and_exchange(vhost, queue, exchange)
  decode_resource_collection(@connection.get("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}"))
end

#list_bindings_by_destination(vhost, exchange) ⇒ Object



102
103
104
# File 'lib/rabbitmq/http/client.rb', line 102

def list_bindings_by_destination(vhost, exchange)
  decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination"))
end

#list_bindings_by_source(vhost, exchange) ⇒ Object



98
99
100
# File 'lib/rabbitmq/http/client.rb', line 98

def list_bindings_by_source(vhost, exchange)
  decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source"))
end

#list_channelsObject



64
65
66
# File 'lib/rabbitmq/http/client.rb', line 64

def list_channels
  decode_resource_collection(@connection.get("/api/channels"))
end

#list_connectionsObject



52
53
54
# File 'lib/rabbitmq/http/client.rb', line 52

def list_connections
  decode_resource_collection(@connection.get("/api/connections"))
end

#list_definitionsObject



44
45
46
# File 'lib/rabbitmq/http/client.rb', line 44

def list_definitions
  decode_resource(@connection.get("/api/definitions"))
end

#list_exchanges(vhost = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/rabbitmq/http/client.rb', line 72

def list_exchanges(vhost = nil)
  path = if vhost.nil?
           "/api/exchanges"
         else
           "/api/exchanges/#{uri_encode(vhost)}"
         end

  decode_resource_collection(@connection.get(path))
end

#list_extensionsObject



40
41
42
# File 'lib/rabbitmq/http/client.rb', line 40

def list_extensions
  decode_resource_collection(@connection.get("/api/extensions"))
end

#list_nodesObject



32
33
34
# File 'lib/rabbitmq/http/client.rb', line 32

def list_nodes
  decode_resource_collection(@connection.get("/api/nodes"))
end

#list_parameters(component = nil) ⇒ Object



280
281
282
283
284
285
286
287
# File 'lib/rabbitmq/http/client.rb', line 280

def list_parameters(component = nil)
  path = if component
           "/api/parameters/#{uri_encode(component)}"
         else
           "/api/parameters"
         end
  decode_resource_collection(@connection.get(path))
end

#list_parameters_of(component, vhost, name = nil) ⇒ Object



289
290
291
292
293
294
295
296
# File 'lib/rabbitmq/http/client.rb', line 289

def list_parameters_of(component, vhost, name = nil)
  path = if name
           "/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}"
         else
           "/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}"
         end
  decode_resource_collection(@connection.get(path))
end

#list_permissions(vhost = nil) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/rabbitmq/http/client.rb', line 187

def list_permissions(vhost = nil)
  path = if vhost
           "/api/vhosts/#{uri_encode(vhost)}/permissions"
         else
           "/api/permissions"
         end

  decode_resource_collection(@connection.get(path))
end

#list_permissions_of(vhost, user) ⇒ Object



197
198
199
# File 'lib/rabbitmq/http/client.rb', line 197

def list_permissions_of(vhost, user)
  decode_resource(@connection.get("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}"))
end

#list_policies(vhost = nil) ⇒ Object



246
247
248
249
250
251
252
253
254
# File 'lib/rabbitmq/http/client.rb', line 246

def list_policies(vhost = nil)
  path = if vhost
           "/api/policies/#{uri_encode(vhost)}"
         else
           "/api/policies"
         end

  decode_resource_collection(@connection.get(path))
end

#list_policies_of(vhost, name = nil) ⇒ Object



256
257
258
259
260
261
262
263
# File 'lib/rabbitmq/http/client.rb', line 256

def list_policies_of(vhost, name = nil)
  path = if name
           "/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}"
         else
           "/api/policies/#{uri_encode(vhost)}"
         end
  decode_resource_collection(@connection.get(path))
end

#list_queue_bindings(vhost, queue) ⇒ Object



132
133
134
# File 'lib/rabbitmq/http/client.rb', line 132

def list_queue_bindings(vhost, queue)
  decode_resource_collection(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(queue)}/bindings"))
end

#list_queues(vhost = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/rabbitmq/http/client.rb', line 106

def list_queues(vhost = nil)
  path = if vhost.nil?
           "/api/queues"
         else
           "/api/queues/#{uri_encode(vhost)}"
         end

  decode_resource_collection(@connection.get(path))
end

#list_usersObject



215
216
217
# File 'lib/rabbitmq/http/client.rb', line 215

def list_users
  decode_resource_collection(@connection.get("/api/users"))
end

#list_vhostsObject



166
167
168
# File 'lib/rabbitmq/http/client.rb', line 166

def list_vhosts
  decode_resource_collection(@connection.get("/api/vhosts"))
end

#node_info(name) ⇒ Object



36
37
38
# File 'lib/rabbitmq/http/client.rb', line 36

def node_info(name)
  decode_resource(@connection.get("/api/nodes/#{uri_encode(name)}"))
end

#overviewObject



28
29
30
# File 'lib/rabbitmq/http/client.rb', line 28

def overview
  decode_resource(@connection.get("/api/overview"))
end

#purge_queue(vhost, name) ⇒ Object



136
137
138
# File 'lib/rabbitmq/http/client.rb', line 136

def purge_queue(vhost, name)
  decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/contents"))
end

#queue_info(vhost, name) ⇒ Object



116
117
118
# File 'lib/rabbitmq/http/client.rb', line 116

def queue_info(vhost, name)
  decode_resource(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}"))
end

#update_exchange(vhost, name, attributes) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/rabbitmq/http/client.rb', line 86

def update_exchange(vhost, name, attributes)
  response = @connection.put("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#update_parameters_of(component, vhost, name, attributes) ⇒ Object



298
299
300
301
302
303
304
# File 'lib/rabbitmq/http/client.rb', line 298

def update_parameters_of(component, vhost, name, attributes)
  response = @connection.put("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#update_permissions_of(vhost, user, attributes) ⇒ Object



201
202
203
204
205
206
207
# File 'lib/rabbitmq/http/client.rb', line 201

def update_permissions_of(vhost, user, attributes)
  response = @connection.put("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#update_policies_of(vhost, name, attributes) ⇒ Object



265
266
267
268
269
270
271
# File 'lib/rabbitmq/http/client.rb', line 265

def update_policies_of(vhost, name, attributes)
  response = @connection.put("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#update_user(name, attributes) ⇒ Object Also known as: create_user



223
224
225
226
227
228
229
# File 'lib/rabbitmq/http/client.rb', line 223

def update_user(name, attributes)
  response = @connection.put("/api/users/#{uri_encode(name)}") do |req|
    req.headers['Content-Type'] = "application/json"
    req.body = MultiJson.dump(attributes)
  end
  decode_resource(response)
end

#upload_definitions(defs) ⇒ Object

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/rabbitmq/http/client.rb', line 48

def upload_definitions(defs)
  raise NotImplementedError.new
end

#user_info(name) ⇒ Object



219
220
221
# File 'lib/rabbitmq/http/client.rb', line 219

def (name)
  decode_resource(@connection.get("/api/users/#{uri_encode(name)}"))
end

#user_permissions(name) ⇒ Object



236
237
238
# File 'lib/rabbitmq/http/client.rb', line 236

def user_permissions(name)
  decode_resource_collection(@connection.get("/api/users/#{uri_encode(name)}/permissions"))
end

#vhost_info(name) ⇒ Object



170
171
172
# File 'lib/rabbitmq/http/client.rb', line 170

def vhost_info(name)
  decode_resource(@connection.get("/api/vhosts/#{uri_encode(name)}"))
end

#whoamiObject



240
241
242
# File 'lib/rabbitmq/http/client.rb', line 240

def whoami
  decode_resource(@connection.get("/api/whoami"))
end