O:39:"phpDocumentor\Descriptor\FileDescriptor":20:{s:7:" * hash";s:32:"15f369db3e2d2aec83d1b99f6bea87af";s:9:" * source";s:2398:"<?php

namespace OpenCloud\CloudMonitoring\Resource;

use OpenCloud\CloudMonitoring\Exception;

/**
 * Metric class.
 * 
 * @extends ReadOnlyResource
 */
class Metric extends ReadOnlyResource implements ResourceInterface
{

    protected static $json_name = 'metrics';
    protected static $json_collection_name = 'values';
    protected static $url_resource = 'metrics';
    
    protected $dataPointParams = array(
    	'from',
    	'to',
    	'points',
    	'resolution',
    	'select'
    );

    public function baseUrl()
    {
    	return $this->Parent()->Url($this->Parent()->id . '/'. $this->ResourceName());
    }

	public function fetchDataPoints($metricName, array $options = array())
	{
		$url = $this->Url($metricName . '/plot');

		$parts = array();

		// Timestamps
		foreach (array('to', 'from', 'points') as $param) {
			if (isset($options[$param])) {
				$parts[$param] = $options[$param];
			}
		}

		if (!isset($parts['to'])) {
			throw new Exception\MetricException(sprintf(
				'Please specify a "to" value'
			));
		}

		if (!isset($parts['from'])) {
			throw new Exception\MetricException(sprintf(
				'Please specify a "from" value'
			));
		}

		if (isset($options['resolution'])) {
			$allowedResolutions = array('FULL', 'MIN5', 'MIN20', 'MIN60', 'MIN240', 'MIN1440');
			if (!in_array($options['resolution'], $allowedResolutions)) {
				throw new Exception\MetricException(sprintf(
					'%s is an invalid resolution type. Please use one of the following: %s',
					$options['resolution'],
					implode(', ', $allowedResolutions)
				));
			}
			$parts['resolution'] = $options['resolution'];
		}

		if (isset($options['select'])) {
			$allowedStats = array('average', 'variance', 'min', 'max');
			if (!in_array($options['select'], $allowedResolutions)) {
				throw new Exception\MetricException(sprintf(
					'%s is an invalid stat type. Please use one of the following: %s',
					$options['select'],
					implode(', ', $allowedStats)
				));
			}
			$parts['select'] = $options['select'];
		}

		if (!isset($parts['points']) && !isset($parts['resolution'])) {
			throw new Exception\MetricException(sprintf(
				'Please specify at least one point or resolution value'
			));
		}

		$url .= "?to={$parts['to']}";
		unset($parts['to']);
		foreach ($parts as $type => $val) {
			$url .= "&$type=$val";
		}

		return $this->Service()->Collection(get_class(), $url);
	}
	
}";s:20:" * namespace_aliases";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:11:" * includes";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:12:" * constants";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:12:" * functions";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:10:" * classes";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:6:"Metric";O:40:"phpDocumentor\Descriptor\ClassDescriptor":17:{s:9:" * parent";s:52:"\OpenCloud\CloudMonitoring\Resource\ReadOnlyResource";s:13:" * implements";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:53:"\OpenCloud\CloudMonitoring\Resource\ResourceInterface";s:53:"\OpenCloud\CloudMonitoring\Resource\ResourceInterface";}}s:11:" * abstract";b:0;s:8:" * final";b:0;s:12:" * constants";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:13:" * properties";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:4:{s:9:"json_name";O:43:"phpDocumentor\Descriptor\PropertyDescriptor":15:{s:9:" * parent";r:14;s:8:" * types";N;s:10:" * default";s:9:"'metrics'";s:9:" * static";b:1;s:13:" * visibility";s:9:"protected";s:8:" * fqsen";s:53:"\OpenCloud\CloudMonitoring\Resource\Metric::json_name";s:7:" * name";s:9:"json_name";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:15;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50007";s:7:" * line";i:15;s:10:" * context";a:1:{i:0;s:10:"$json_name";}}}}}s:20:"json_collection_name";O:43:"phpDocumentor\Descriptor\PropertyDescriptor":15:{s:9:" * parent";r:14;s:8:" * types";N;s:10:" * default";s:8:"'values'";s:9:" * static";b:1;s:13:" * visibility";s:9:"protected";s:8:" * fqsen";s:64:"\OpenCloud\CloudMonitoring\Resource\Metric::json_collection_name";s:7:" * name";s:20:"json_collection_name";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:16;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50007";s:7:" * line";i:16;s:10:" * context";a:1:{i:0;s:21:"$json_collection_name";}}}}}s:12:"url_resource";O:43:"phpDocumentor\Descriptor\PropertyDescriptor":15:{s:9:" * parent";r:14;s:8:" * types";N;s:10:" * default";s:9:"'metrics'";s:9:" * static";b:1;s:13:" * visibility";s:9:"protected";s:8:" * fqsen";s:56:"\OpenCloud\CloudMonitoring\Resource\Metric::url_resource";s:7:" * name";s:12:"url_resource";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:17;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50007";s:7:" * line";i:17;s:10:" * context";a:1:{i:0;s:13:"$url_resource";}}}}}s:15:"dataPointParams";O:43:"phpDocumentor\Descriptor\PropertyDescriptor":15:{s:9:" * parent";r:14;s:8:" * types";N;s:10:" * default";s:53:"array('from', 'to', 'points', 'resolution', 'select')";s:9:" * static";b:0;s:13:" * visibility";s:9:"protected";s:8:" * fqsen";s:59:"\OpenCloud\CloudMonitoring\Resource\Metric::dataPointParams";s:7:" * name";s:15:"dataPointParams";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:19;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50007";s:7:" * line";i:19;s:10:" * context";a:1:{i:0;s:16:"$dataPointParams";}}}}}}}s:10:" * methods";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:2:{s:7:"baseUrl";O:41:"phpDocumentor\Descriptor\MethodDescriptor":16:{s:9:" * parent";r:14;s:11:" * abstract";b:0;s:8:" * final";b:0;s:9:" * static";b:0;s:13:" * visibility";s:6:"public";s:12:" * arguments";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:8:" * fqsen";s:53:"\OpenCloud\CloudMonitoring\Resource\Metric::baseUrl()";s:7:" * name";s:7:"baseUrl";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:27;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50008";s:7:" * line";i:27;s:10:" * context";a:1:{i:0;s:9:"baseUrl()";}}}}}s:15:"fetchDataPoints";O:41:"phpDocumentor\Descriptor\MethodDescriptor":16:{s:9:" * parent";r:14;s:11:" * abstract";b:0;s:8:" * final";b:0;s:9:" * static";b:0;s:13:" * visibility";s:6:"public";s:12:" * arguments";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:2:{s:11:"$metricName";O:43:"phpDocumentor\Descriptor\ArgumentDescriptor":13:{s:8:" * types";a:0:{}s:10:" * default";N;s:14:" * byReference";b:0;s:8:" * fqsen";s:0:"";s:7:" * name";s:11:"$metricName";s:12:" * namespace";N;s:10:" * package";N;s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:0;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}}s:8:"$options";O:43:"phpDocumentor\Descriptor\ArgumentDescriptor":13:{s:8:" * types";a:1:{i:0;s:5:"array";}s:10:" * default";s:7:"array()";s:14:" * byReference";b:0;s:8:" * fqsen";s:0:"";s:7:" * name";s:8:"$options";s:12:" * namespace";N;s:10:" * package";N;s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:0;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}}}}s:8:" * fqsen";s:61:"\OpenCloud\CloudMonitoring\Resource\Metric::fetchDataPoints()";s:7:" * name";s:15:"fetchDataPoints";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:0:"";s:7:" * line";i:32;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:2:{s:5:"param";a:0:{}s:8:"internal";N;}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:40:"phpDocumentor\Descriptor\Validator\Error":4:{s:11:" * severity";s:5:"error";s:7:" * code";s:13:"PPC:ERR-50008";s:7:" * line";i:32;s:10:" * context";a:1:{i:0;s:17:"fetchDataPoints()";}}}}}}}s:8:" * fqsen";s:42:"\OpenCloud\CloudMonitoring\Resource\Metric";s:7:" * name";s:6:"Metric";s:12:" * namespace";s:35:"\OpenCloud\CloudMonitoring\Resource";s:10:" * package";s:0:"";s:10:" * summary";s:13:"Metric class.";s:14:" * description";s:0:"";s:7:" * path";r:1;s:7:" * line";i:12;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{s:7:"extends";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:1:{i:0;O:38:"phpDocumentor\Descriptor\TagDescriptor":2:{s:7:" * name";s:7:"extends";s:14:" * description";s:16:"ReadOnlyResource";}}}}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}}}}s:13:" * interfaces";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:9:" * traits";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:10:" * markers";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:8:" * fqsen";s:0:"";s:7:" * name";s:10:"Metric.php";s:12:" * namespace";N;s:10:" * package";s:0:"";s:10:" * summary";s:0:"";s:14:" * description";s:0:"";s:7:" * path";s:45:"OpenCloud/CloudMonitoring/Resource/Metric.php";s:7:" * line";i:0;s:7:" * tags";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}s:9:" * errors";O:35:"phpDocumentor\Descriptor\Collection":1:{s:8:" * items";a:0:{}}}