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.2.0"

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



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

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



294
295
296
# File 'lib/rabbitmq/http/client.rb', line 294

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



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

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



261
262
263
# File 'lib/rabbitmq/http/client.rb', line 261

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



162
163
164
165
166
167
# File 'lib/rabbitmq/http/client.rb', line 162

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



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

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_queue(vhost, name) ⇒ Object



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

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

#delete_user(name) ⇒ Object



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

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

#delete_vhost(name) ⇒ Object



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

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



128
129
130
131
132
133
134
# File 'lib/rabbitmq/http/client.rb', line 128

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



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

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



147
148
149
# File 'lib/rabbitmq/http/client.rb', line 147

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



90
91
92
# File 'lib/rabbitmq/http/client.rb', line 90

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



86
87
88
# File 'lib/rabbitmq/http/client.rb', line 86

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



268
269
270
271
272
273
274
275
# File 'lib/rabbitmq/http/client.rb', line 268

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



277
278
279
280
281
282
283
284
# File 'lib/rabbitmq/http/client.rb', line 277

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



175
176
177
178
179
180
181
182
183
# File 'lib/rabbitmq/http/client.rb', line 175

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



185
186
187
# File 'lib/rabbitmq/http/client.rb', line 185

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

#list_policies(vhost = nil) ⇒ Object



234
235
236
237
238
239
240
241
242
# File 'lib/rabbitmq/http/client.rb', line 234

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



244
245
246
247
248
249
250
251
# File 'lib/rabbitmq/http/client.rb', line 244

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



120
121
122
# File 'lib/rabbitmq/http/client.rb', line 120

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



94
95
96
97
98
99
100
101
102
# File 'lib/rabbitmq/http/client.rb', line 94

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



203
204
205
# File 'lib/rabbitmq/http/client.rb', line 203

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

#list_vhostsObject



154
155
156
# File 'lib/rabbitmq/http/client.rb', line 154

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



124
125
126
# File 'lib/rabbitmq/http/client.rb', line 124

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

#queue_info(vhost, name) ⇒ Object



104
105
106
# File 'lib/rabbitmq/http/client.rb', line 104

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

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



286
287
288
289
290
291
292
# File 'lib/rabbitmq/http/client.rb', line 286

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



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

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



253
254
255
256
257
258
259
# File 'lib/rabbitmq/http/client.rb', line 253

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



211
212
213
214
215
216
217
# File 'lib/rabbitmq/http/client.rb', line 211

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



207
208
209
# File 'lib/rabbitmq/http/client.rb', line 207

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

#user_permissions(name) ⇒ Object



224
225
226
# File 'lib/rabbitmq/http/client.rb', line 224

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

#vhost_info(name) ⇒ Object



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

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

#whoamiObject



228
229
230
# File 'lib/rabbitmq/http/client.rb', line 228

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