     1: <?php
     2: /**
     3:  * Copyright 2012-2014 Rackspace US, Inc.
     4:  *
     5:  * Licensed under the Apache License, Version 2.0 (the "License");
     6:  * you may not use this file except in compliance with the License.
     7:  * You may obtain a copy of the License at
     8:  *
     9:  * http://www.apache.org/licenses/LICENSE-2.0
    10:  *
    11:  * Unless required by applicable law or agreed to in writing, software
    12:  * distributed under the License is distributed on an "AS IS" BASIS,
    13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14:  * See the License for the specific language governing permissions and
    15:  * limitations under the License.
    16:  */
    17:
    18: namespace OpenCloud\CloudMonitoring\Resource;
    19:
    20: use Guzzle\Http\Exception\ClientErrorResponseException;
    21: use OpenCloud\CloudMonitoring\Exception;
    22: use OpenCloud\Common\Http\Message\Formatter;
    23:
    24: /**
    25:  * Zone class.
    26:  */
    27: class Zone extends ReadOnlyResource
    28: {
    29:     /** @var string */
    30:     private $id;
    31:
    32:     /** @var string Country Code */
    33:     private $country_code;
    34:
    35:     /** @var string */
    36:     private $label;
    37:
    38:     /** @var array List of source IPs */
    39:     private $source_ips;
    40:
    41:     protected static $json_name = false;
    42:     protected static $json_collection_name = 'values';
    43:     protected static $url_resource = 'monitoring_zones';
    44:
    45:     public function traceroute(array $options)
    46:     {
    47:         if (!$this->getId()) {
    48:             throw new Exception\ZoneException(
    49:                 'Please specify a zone ID'
    50:             );
    51:         }
    52:
    53:         if (!isset($options['target']) || !isset($options['target_resolver'])) {
    54:             throw new Exception\ZoneException(
    55:                 'Please specify a "target" and "target_resolver" value'
    56:             );
    57:         }
    58:
    59:         $params = (object) array(
    60:             'target'          => $options['target'],
    61:             'target_resolver' => $options['target_resolver']
    62:         );
    63:         try {
    64:             $response = $this->getService()
    65:                 ->getClient()
    66:                 ->post($this->url('traceroute'), self::getJsonHeader(), json_encode($params))
    67:                 ->send();
    68:
    69:             $body = Formatter::decode($response);
    70:
    71:             return (isset($body->result)) ? $body->result : false;
    72:         } catch (ClientErrorResponseException $e) {
    73:             return false;
    74:         }
    75:     }
    76: }
    77: