1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Util.php";
6: use \Saklient\Util;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
8: use \Saklient\Cloud\Client;
9: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
10: use \Saklient\Errors\SaklientException;
11:
12: class Activity {
13:
14: 15: 16: 17: 18: 19:
20: protected $_client;
21:
22: 23: 24: 25: 26: 27:
28: protected $_sourceId;
29:
30: 31: 32: 33: 34: 35:
36: protected function _apiPathPrefix()
37: {
38: return null;
39: }
40:
41: 42: 43: 44: 45: 46:
47: protected function _apiPathSuffix()
48: {
49: return "/monitor";
50: }
51:
52: 53: 54: 55: 56: 57: 58: 59:
60: protected function _addSample($atStr, $data)
61: {
62: Util::validateArgCount(func_num_args(), 2);
63: Util::validateType($atStr, "string");
64: }
65:
66: 67: 68: 69: 70:
71: public function __construct(\Saklient\Cloud\Client $client)
72: {
73: Util::validateArgCount(func_num_args(), 1);
74: Util::validateType($client, "\\Saklient\\Cloud\\Client");
75: $this->_client = $client;
76: }
77:
78: 79: 80: 81: 82: 83:
84: public function setSourceId($id)
85: {
86: Util::validateArgCount(func_num_args(), 1);
87: Util::validateType($id, "string");
88: $this->_sourceId = $id;
89: }
90:
91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
103: public function _fetch(NativeDate $startDate=null, NativeDate $endDate=null)
104: {
105: Util::validateType($startDate, "NativeDate");
106: Util::validateType($endDate, "NativeDate");
107: $query = (object)[];
108: if ($startDate != null) {
109: $query->{"Start"} = Util::date2str($startDate);
110: }
111: if ($endDate != null) {
112: $query->{"End"} = Util::date2str($endDate);
113: }
114: $path = $this->_apiPathPrefix() . "/" . Util::urlEncode($this->_sourceId) . $this->_apiPathSuffix();
115: $data = $this->_client->request("GET", $path);
116: if ($data == null) {
117: return null;
118: }
119: $data = $data->{"Data"};
120: if ($data == null) {
121: return null;
122: }
123: $dates = new \ArrayObject(array_keys((array)$data));
124: $dates = Util::sortArray($dates);
125: foreach ($dates as $date) {
126: $this->_addSample($date, $data->{$date});
127: }
128: return $this;
129: }
130:
131:
132:
133: }
134:
135: