Skip to content

Commit

Permalink
Merge pull request #6 from richardfullmer/httplug
Browse files Browse the repository at this point in the history
Use httplug instead of guzzle 4
  • Loading branch information
richardfullmer authored Oct 18, 2016
2 parents 53baf36 + 66d96f5 commit 3bab8bb
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 79 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PHP RabbitMQ Management Api

A simple object oriented wrapper for the [RabbitMQ Management HTTP Api](http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_0_3/priv/www/api/index.html) in PHP 5.3

Uses [Guzzle](http://guzzlephp.org) for REST requests.
Uses [PHP-HTTP](http://docs.php-http.org/en/latest/index.html) for requests.

Installation
------------
Expand All @@ -14,6 +14,14 @@ Installable through composer via:
$ composer require richardfullmer/rabbitmq-management-api
```

Additionally, you require a [httplug compatible client](http://docs.php-http.org/en/latest/clients.html).

For example, use the guzzle6 adapter:

```bash
$ composer require php-http/guzzle6-adapter
```

Basic Usage
-----------

Expand All @@ -36,7 +44,6 @@ $response = $client->exchanges()->publish('/', 'sample-messages', array(
if ($response['routed']) {
print 'Message delivered';
}

```

License
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
}
],
"require": {
"php": ">=5.3.2",
"guzzle/guzzle": "~3.0"
"php": ">=5.4",
"psr/http-message": "^1.0",
"php-http/client-implementation": "^1.0",
"php-http/client-common": "^1.0",
"php-http/httplug": "^1.0",
"php-http/message-factory": "^1.0",
"php-http/discovery": "^1.0"
},
"autoload": {
"psr-0": {
"RabbitMq\\ManagementApi": "src/"
"psr-4": {
"RabbitMq\\ManagementApi\\": "src/"
}
},
"extra": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Binding extends AbstractApi
public function all($vhost = null)
{
if ($vhost) {
return $this->client->send(array('/api/bindings/{vhost}', array('vhost' => $vhost)));
return $this->client->send(sprintf('/api/bindings/%s', urlencode($vhost)));
} else {
return $this->client->send('/api/bindings');
}
Expand All @@ -37,7 +37,7 @@ public function all($vhost = null)
*/
public function binding($vhost, $exchange, $queue)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{exchange}/q/{queue}', array('vhost' => $vhost, 'exchange' => $exchange, 'queue' => $queue)));
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)));
}

/**
Expand All @@ -52,7 +52,7 @@ public function binding($vhost, $exchange, $queue)
*/
public function exchangeBinding($vhost, $source, $destination)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{source}/e/{destination}', array('vhost' => $vhost, 'source' => $source, 'destination' => $destination)));
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s', urlencode($vhost), urlencode($source), urlencode($destination)));
}

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ public function create($vhost, $exchange, $queue, $routingKey = null, array $arg
$parameters['arguments'] = $arguments;
}

return $this->client->send(array('/api/bindings/{vhost}/e/{exchange}/q/{queue}', array('vhost' => $vhost, 'exchange' => $exchange, 'queue' => $queue)), 'POST', null, $parameters);
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s', urlencode($vhost), urlencode($exchange), urlencode($queue)), 'POST', [], $parameters);
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ public function createExchange($vhost, $source, $destination, $routingKey = null
$parameters['arguments'] = $arguments;
}

return $this->client->send(array('/api/bindings/{vhost}/e/{source}/e/{destination}', array('vhost' => $vhost, 'source' => $source, 'destination' => $destination)), 'POST', null, $parameters);
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s', urlencode($vhost), urlencode($source), urlencode($destination)), 'POST', [], $parameters);
}

/**
Expand All @@ -133,7 +133,7 @@ public function createExchange($vhost, $source, $destination, $routingKey = null
*/
public function get($vhost, $exchange, $queue, $props)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{exchange}/q/{queue}/{props}', array('vhost' => $vhost, 'exchange' => $exchange, 'queue' => $queue, 'props' => $props)));
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($vhost), urlencode($exchange), urlencode($queue), urlencode($props)));
}

/**
Expand All @@ -148,7 +148,7 @@ public function get($vhost, $exchange, $queue, $props)
*/
public function getExchange($vhost, $source, $destination, $props)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{source}/e/{destination}/{props}', array('vhost' => $vhost, 'source' => $source, 'destination' => $destination, 'props' => $props)));
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s/%s', urlencode($vhost), urlencode($source), urlencode($destination), urlencode($props)));
}

/**
Expand All @@ -162,7 +162,7 @@ public function getExchange($vhost, $source, $destination, $props)
*/
public function delete($vhost, $exchange, $queue, $props)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{exchange}/q/{queue}/{props}', array('vhost' => $vhost, 'exchange' => $exchange, 'queue' => $queue, 'props' => $props)), 'DELETE');
return $this->client->send(sprintf('/api/bindings/%s/e/%s/q/%s/%s', urlencode($vhost), urlencode($exchange), urlencode($queue), urlencode($props)), 'DELETE');
}

/**
Expand All @@ -176,6 +176,6 @@ public function delete($vhost, $exchange, $queue, $props)
*/
public function deleteExchange($vhost, $source, $destination, $props)
{
return $this->client->send(array('/api/bindings/{vhost}/e/{source}/e/{destination}/{props}', array('vhost' => $vhost, 'source' => $source, 'destination' => $destination, 'props' => $props)), 'DELETE');
return $this->client->send(sprintf('/api/bindings/%s/e/%s/e/%s/%s', urlencode($vhost), urlencode($source), urlencode($destination), urlencode($props)), 'DELETE');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function all()
*/
public function get($channel)
{
return $this->client->send(array('/api/channels/{channel}', array('channel' => $channel)));
return $this->client->send(sprintf('/api/channels/%s', urlencode($channel)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function all()
*/
public function get($name)
{
return $this->client->send(array('/api/connections/{name}', array('name' => $name)));
return $this->client->send(sprintf('/api/connections/%s', urlencode($name)));
}

/**
Expand All @@ -38,6 +38,6 @@ public function get($name)
*/
public function delete($name)
{
return $this->client->send(array('/api/connections/{name}', array('name' => $name)), 'DELETE');
return $this->client->send(sprintf('/api/connections/%s', urlencode($name)), 'DELETE');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Exchange extends AbstractApi
public function all($vhost = null)
{
if ($vhost) {
return $this->client->send(array('/api/exchanges/{vhost}', array('vhost' => $vhost)));
return $this->client->send(sprintf('/api/exchanges/%s', urlencode($vhost)));
} else {
return $this->client->send('/api/exchanges');
}
Expand All @@ -39,7 +39,7 @@ public function all($vhost = null)
*/
public function get($vhost, $name)
{
return $this->client->send(array('/api/exchanges/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)));
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)));
}

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public function create($vhost, $name, array $exchange)
throw new InvalidArgumentException("Error creating exchange: Exchange key 'type' is mandatory");
}

return $this->client->send(array('/api/exchanges/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)), 'PUT', null, $exchange);
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $exchange);
}

/**
Expand All @@ -79,7 +79,7 @@ public function create($vhost, $name, array $exchange)
*/
public function delete($vhost, $name)
{
return $this->client->send(array('/api/exchanges/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)), 'DELETE');
return $this->client->send(sprintf('/api/exchanges/%s/%s', urlencode($vhost), urlencode($name)), 'DELETE');
}

/**
Expand All @@ -91,7 +91,7 @@ public function delete($vhost, $name)
*/
public function sourceBindings($vhost, $name)
{
return $this->client->send(array('/api/exchanges/{vhost}/{name}/bindings/source', array('vhost' => $vhost, 'name' => $name)));
return $this->client->send(sprintf('/api/exchanges/%s/%s/bindings/source', urlencode($vhost), urlencode($name)));
}

/**
Expand All @@ -103,7 +103,7 @@ public function sourceBindings($vhost, $name)
*/
public function destinationBindings($vhost, $name)
{
return $this->client->send(array('/api/exchanges/{vhost}/{name}/bindings/destination', array('vhost' => $vhost, 'name' => $name)));
return $this->client->send(sprintf('/api/exchanges/%s/%s/bindings/destination', urlencode($vhost), urlencode($name)));
}

/**
Expand Down Expand Up @@ -146,6 +146,6 @@ public function publish($vhost, $name, array $message)
throw new InvalidArgumentException("Error publishing to exchange: Message key 'payload_encoding' is mandatory");
}

return $this->client->send(array('/api/exchanges/{vhost}/{name}/publish', array('vhost' => $vhost, 'name' => $name)), 'POST', null, $message);
return $this->client->send(sprintf('/api/exchanges/%s/%s/publish', urlencode($vhost), urlencode($name)), 'POST', [], $message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function all()
*/
public function get($name, $memory = false)
{
return $this->client->send(array('/api/nodes/{name}{?memory}', array('name' => $name, 'memory' => $memory)));
return $this->client->send(sprintf('/api/nodes/%s%s', urlencode($name), $memory ? '?memory=true' : ''));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function all()
public function get($component, $vhost = null, $name = null)
{
if ($vhost && $name) {
return $this->client->send(array('/api/parameters/{component}/{vhost}/{name}', array('component' => $component, 'vhost' => $vhost, 'name' => $name)));
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)));
} elseif ($vhost) {
return $this->client->send(array('/api/parameters/{component}/{vhost}', array('component' => $component, 'vhost' => $vhost)));
return $this->client->send(sprintf('/api/parameters/%s/%s', urlencode($component), urlencode($vhost)));
} else {
return $this->client->send(array('/api/parameters/{component}', array('component' => $component)));
return $this->client->send(sprintf('/api/parameters/%s', urlencode($component)));
}
}

Expand All @@ -56,7 +56,7 @@ public function get($component, $vhost = null, $name = null)
*/
public function create($component, $vhost, $name, array $parameter)
{
return $this->client->send(array('/api/parameters/{component}/{vhost}/{name}', array('component' => $component, 'vhost' => $vhost, 'name' => $name)), 'PUT', null, $parameter);
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)), 'PUT', [], $parameter);
}

/**
Expand All @@ -69,6 +69,6 @@ public function create($component, $vhost, $name, array $parameter)
*/
public function delete($component, $vhost, $name)
{
return $this->client->send(array('/api/parameters/{component}/{vhost}/{name}', array('component' => $component, 'vhost' => $vhost, 'name' => $name)), 'DELETE');
return $this->client->send(sprintf('/api/parameters/%s/%s/%s', urlencode($component), urlencode($vhost), urlencode($name)), 'DELETE');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function all()
*/
public function get($vhost, $user)
{
return $this->client->send(array('/api/permissions/{vhost}/{user}', array('vhost' => $vhost, 'user' => $user)));
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)));
}

/**
Expand All @@ -52,7 +52,7 @@ public function create($vhost, $user, array $permission)
throw new InvalidArgumentException("Error creating permission: 'configure', 'write', and 'read' permissions must be properly set.");
}

return $this->client->send(array('/api/permissions/{vhost}/{user}', array('vhost' => $vhost, 'user' => $user)), 'PUT', null, $permission);
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)), 'PUT', [], $permission);
}

/**
Expand All @@ -64,7 +64,7 @@ public function create($vhost, $user, array $permission)
*/
public function delete($vhost, $user)
{
return $this->client->send(array('/api/permissions/{vhost}/{user}', array('vhost' => $vhost, 'user' => $user)), 'DELETE');
return $this->client->send(sprintf('/api/permissions/%s/%s', urlencode($vhost), urlencode($user)), 'DELETE');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function all()
public function get($vhost, $name = null)
{
if ($name) {
return $this->client->send(array('/api/policies/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)));
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)));
}

return $this->client->send(array('/api/policies/{vhost}', array('vhost' => $vhost)));
return $this->client->send(sprintf('/api/policies/%s', urlencode($vhost)));
}

/**
Expand All @@ -51,7 +51,7 @@ public function get($vhost, $name = null)
*/
public function create($vhost, $name, array $policy)
{
return $this->client->send(array('/api/policies/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)), 'PUT', null, $policy);
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $policy);
}

/**
Expand All @@ -63,6 +63,6 @@ public function create($vhost, $name, array $policy)
*/
public function delete($vhost, $name)
{
return $this->client->send(array('/api/policies/{vhost}/{name}', array('vhost' => $vhost, 'name' => $name)), 'DELETE');
return $this->client->send(sprintf('/api/policies/%s/%s', urlencode($vhost), urlencode($name)), 'DELETE');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function get($vhost, $name)
*/
public function create($vhost, $name, array $queue)
{
return $this->client->send(sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', null, $queue);
return $this->client->send(sprintf('/api/queues/%s/%s', urlencode($vhost), urlencode($name)), 'PUT', [], $queue);
}

/**
Expand All @@ -74,7 +74,7 @@ public function delete($vhost, $name)

/**
* A list of all bindings on a given queue.
*
*
* @param string $vhost
* @param string $queue
* @return array
Expand Down Expand Up @@ -139,6 +139,6 @@ public function retrieveMessages($vhost, $name, $count = 5, $requeue = true, $en
$parameters['truncate'] = $truncate;
}

return $this->client->send(sprintf('/api/queues/%s/%s/get', urlencode($vhost), urlencode($name)), 'POST', null, $parameters);
return $this->client->send(sprintf('/api/queues/%s/%s/get', urlencode($vhost), urlencode($name)), 'POST', [], $parameters);
}
}
8 changes: 4 additions & 4 deletions src/RabbitMq/ManagementApi/Api/User.php → src/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function all()
*/
public function get($name)
{
return $this->client->send(array('/api/users/{name}', array('name' => $name)));
return $this->client->send(sprintf('/api/users/%s', urlencode($name)));
}

/**
Expand All @@ -49,7 +49,7 @@ public function get($name)
*/
public function create($name, array $user)
{
return $this->client->send(array('/api/users/{name}', array('name' => $name)), 'PUT', null, $user);
return $this->client->send(sprintf('/api/users/%s', urlencode($name)), 'PUT', [], $user);
}

/**
Expand All @@ -60,7 +60,7 @@ public function create($name, array $user)
*/
public function delete($name)
{
return $this->client->send(array('/api/users/{name}', array('name' => $name)), 'DELETE');
return $this->client->send(sprintf('/api/users/%s', urlencode($name)), 'DELETE');
}

/**
Expand All @@ -71,6 +71,6 @@ public function delete($name)
*/
public function permissions($name)
{
return $this->client->send(array('/api/users/{name}/permissions', array('name' => $name)));
return $this->client->send(sprintf('/api/users/%s/permissions', urlencode($name)));
}
}
Loading

0 comments on commit 3bab8bb

Please sign in to comment.