public function probeExchange(Exchange $exchange)
 {
     try {
         if ($exchange->toJson() !== $this->client->getExchange($exchange->vhost, $exchange->name)->toJson()) {
             return self::PROBE_MISCONFIGURED;
         } else {
             return self::PROBE_OK;
         }
     } catch (EntityNotFoundException $e) {
         return self::PROBE_ABSENT;
     }
 }
 public function addExchange(Exchange $exchange)
 {
     if (!$exchange->vhost) {
         throw new InvalidArgumentException('Exchange requires a vhost');
     }
     if (!$exchange->name) {
         throw new InvalidArgumentException('Exchange requires a name');
     }
     $uri = sprintf('/api/exchanges/%s/%s', urlencode($exchange->vhost), urlencode($exchange->name));
     try {
         $response = $this->client->put($uri, array('Content-Type' => 'application/json'), $exchange->toJson())->send();
     } catch (RequestException $e) {
         if ($data = json_decode($e->getResponse()->getBody(true), true)) {
             if (isset($data['reason']) && strpos($data['reason'], '406 PRECONDITION_FAILED') === 0) {
                 throw new PreconditionFailedException('Exchange already exists with different properties', $e->getCode(), $e);
             }
         }
         throw new RuntimeException('Unable to put the exchange', $e->getCode(), $e);
     }
     return $this->getExchange($exchange->vhost, $exchange->name, $exchange);
 }
 public function addExchange(Exchange $exchange)
 {
     if (!$exchange->vhost) {
         throw new InvalidArgumentException('Exchange requires a vhost');
     }
     if (!$exchange->name) {
         throw new InvalidArgumentException('Exchange requires a name');
     }
     return $this->executeRequest('PUT', sprintf('/api/exchanges/%s/%s', urlencode($exchange->vhost), urlencode($exchange->name)), $exchange->toJson())->then(Curry::bind(array($this, 'getExchange'), $exchange->vhost, $exchange->name, $exchange));
 }