PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Twilio/Rest/Api/V2010/Account/Usage/RecordList.php

http://github.com/twilio/twilio-php
PHP | 285 lines | 127 code | 38 blank | 120 comment | 10 complexity | 24047c9bf9bc9b882a57d2af002f0782 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Api\V2010\Account\Usage;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\InstanceContext;
  11. use Twilio\ListResource;
  12. use Twilio\Options;
  13. use Twilio\Rest\Api\V2010\Account\Usage\Record\AllTimeList;
  14. use Twilio\Rest\Api\V2010\Account\Usage\Record\DailyList;
  15. use Twilio\Rest\Api\V2010\Account\Usage\Record\LastMonthList;
  16. use Twilio\Rest\Api\V2010\Account\Usage\Record\MonthlyList;
  17. use Twilio\Rest\Api\V2010\Account\Usage\Record\ThisMonthList;
  18. use Twilio\Rest\Api\V2010\Account\Usage\Record\TodayList;
  19. use Twilio\Rest\Api\V2010\Account\Usage\Record\YearlyList;
  20. use Twilio\Rest\Api\V2010\Account\Usage\Record\YesterdayList;
  21. use Twilio\Serialize;
  22. use Twilio\Stream;
  23. use Twilio\Values;
  24. use Twilio\Version;
  25. /**
  26. * @property AllTimeList $allTime
  27. * @property DailyList $daily
  28. * @property LastMonthList $lastMonth
  29. * @property MonthlyList $monthly
  30. * @property ThisMonthList $thisMonth
  31. * @property TodayList $today
  32. * @property YearlyList $yearly
  33. * @property YesterdayList $yesterday
  34. */
  35. class RecordList extends ListResource {
  36. protected $_allTime = null;
  37. protected $_daily = null;
  38. protected $_lastMonth = null;
  39. protected $_monthly = null;
  40. protected $_thisMonth = null;
  41. protected $_today = null;
  42. protected $_yearly = null;
  43. protected $_yesterday = null;
  44. /**
  45. * Construct the RecordList
  46. *
  47. * @param Version $version Version that contains the resource
  48. * @param string $accountSid A 34 character string that uniquely identifies
  49. * this resource.
  50. */
  51. public function __construct(Version $version, string $accountSid) {
  52. parent::__construct($version);
  53. // Path Solution
  54. $this->solution = ['accountSid' => $accountSid, ];
  55. $this->uri = '/Accounts/' . \rawurlencode($accountSid) . '/Usage/Records.json';
  56. }
  57. /**
  58. * Streams RecordInstance records from the API as a generator stream.
  59. * This operation lazily loads records as efficiently as possible until the
  60. * limit
  61. * is reached.
  62. * The results are returned as a generator, so this operation is memory
  63. * efficient.
  64. *
  65. * @param array|Options $options Optional Arguments
  66. * @param int $limit Upper limit for the number of records to return. stream()
  67. * guarantees to never return more than limit. Default is no
  68. * limit
  69. * @param mixed $pageSize Number of records to fetch per request, when not set
  70. * will use the default value of 50 records. If no
  71. * page_size is defined but a limit is defined, stream()
  72. * will attempt to read the limit with the most
  73. * efficient page size, i.e. min(limit, 1000)
  74. * @return Stream stream of results
  75. */
  76. public function stream(array $options = [], int $limit = null, $pageSize = null): Stream {
  77. $limits = $this->version->readLimits($limit, $pageSize);
  78. $page = $this->page($options, $limits['pageSize']);
  79. return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
  80. }
  81. /**
  82. * Reads RecordInstance records from the API as a list.
  83. * Unlike stream(), this operation is eager and will load `limit` records into
  84. * memory before returning.
  85. *
  86. * @param array|Options $options Optional Arguments
  87. * @param int $limit Upper limit for the number of records to return. read()
  88. * guarantees to never return more than limit. Default is no
  89. * limit
  90. * @param mixed $pageSize Number of records to fetch per request, when not set
  91. * will use the default value of 50 records. If no
  92. * page_size is defined but a limit is defined, read()
  93. * will attempt to read the limit with the most
  94. * efficient page size, i.e. min(limit, 1000)
  95. * @return RecordInstance[] Array of results
  96. */
  97. public function read(array $options = [], int $limit = null, $pageSize = null): array {
  98. return \iterator_to_array($this->stream($options, $limit, $pageSize), false);
  99. }
  100. /**
  101. * Retrieve a single page of RecordInstance records from the API.
  102. * Request is executed immediately
  103. *
  104. * @param array|Options $options Optional Arguments
  105. * @param mixed $pageSize Number of records to return, defaults to 50
  106. * @param string $pageToken PageToken provided by the API
  107. * @param mixed $pageNumber Page Number, this value is simply for client state
  108. * @return RecordPage Page of RecordInstance
  109. */
  110. public function page(array $options = [], $pageSize = Values::NONE, string $pageToken = Values::NONE, $pageNumber = Values::NONE): RecordPage {
  111. $options = new Values($options);
  112. $params = Values::of([
  113. 'Category' => $options['category'],
  114. 'StartDate' => Serialize::iso8601Date($options['startDate']),
  115. 'EndDate' => Serialize::iso8601Date($options['endDate']),
  116. 'IncludeSubaccounts' => Serialize::booleanToString($options['includeSubaccounts']),
  117. 'PageToken' => $pageToken,
  118. 'Page' => $pageNumber,
  119. 'PageSize' => $pageSize,
  120. ]);
  121. $response = $this->version->page('GET', $this->uri, $params);
  122. return new RecordPage($this->version, $response, $this->solution);
  123. }
  124. /**
  125. * Retrieve a specific page of RecordInstance records from the API.
  126. * Request is executed immediately
  127. *
  128. * @param string $targetUrl API-generated URL for the requested results page
  129. * @return RecordPage Page of RecordInstance
  130. */
  131. public function getPage(string $targetUrl): RecordPage {
  132. $response = $this->version->getDomain()->getClient()->request(
  133. 'GET',
  134. $targetUrl
  135. );
  136. return new RecordPage($this->version, $response, $this->solution);
  137. }
  138. /**
  139. * Access the allTime
  140. */
  141. protected function getAllTime(): AllTimeList {
  142. if (!$this->_allTime) {
  143. $this->_allTime = new AllTimeList($this->version, $this->solution['accountSid']);
  144. }
  145. return $this->_allTime;
  146. }
  147. /**
  148. * Access the daily
  149. */
  150. protected function getDaily(): DailyList {
  151. if (!$this->_daily) {
  152. $this->_daily = new DailyList($this->version, $this->solution['accountSid']);
  153. }
  154. return $this->_daily;
  155. }
  156. /**
  157. * Access the lastMonth
  158. */
  159. protected function getLastMonth(): LastMonthList {
  160. if (!$this->_lastMonth) {
  161. $this->_lastMonth = new LastMonthList($this->version, $this->solution['accountSid']);
  162. }
  163. return $this->_lastMonth;
  164. }
  165. /**
  166. * Access the monthly
  167. */
  168. protected function getMonthly(): MonthlyList {
  169. if (!$this->_monthly) {
  170. $this->_monthly = new MonthlyList($this->version, $this->solution['accountSid']);
  171. }
  172. return $this->_monthly;
  173. }
  174. /**
  175. * Access the thisMonth
  176. */
  177. protected function getThisMonth(): ThisMonthList {
  178. if (!$this->_thisMonth) {
  179. $this->_thisMonth = new ThisMonthList($this->version, $this->solution['accountSid']);
  180. }
  181. return $this->_thisMonth;
  182. }
  183. /**
  184. * Access the today
  185. */
  186. protected function getToday(): TodayList {
  187. if (!$this->_today) {
  188. $this->_today = new TodayList($this->version, $this->solution['accountSid']);
  189. }
  190. return $this->_today;
  191. }
  192. /**
  193. * Access the yearly
  194. */
  195. protected function getYearly(): YearlyList {
  196. if (!$this->_yearly) {
  197. $this->_yearly = new YearlyList($this->version, $this->solution['accountSid']);
  198. }
  199. return $this->_yearly;
  200. }
  201. /**
  202. * Access the yesterday
  203. */
  204. protected function getYesterday(): YesterdayList {
  205. if (!$this->_yesterday) {
  206. $this->_yesterday = new YesterdayList($this->version, $this->solution['accountSid']);
  207. }
  208. return $this->_yesterday;
  209. }
  210. /**
  211. * Magic getter to lazy load subresources
  212. *
  213. * @param string $name Subresource to return
  214. * @return \Twilio\ListResource The requested subresource
  215. * @throws TwilioException For unknown subresources
  216. */
  217. public function __get(string $name) {
  218. if (\property_exists($this, '_' . $name)) {
  219. $method = 'get' . \ucfirst($name);
  220. return $this->$method();
  221. }
  222. throw new TwilioException('Unknown subresource ' . $name);
  223. }
  224. /**
  225. * Magic caller to get resource contexts
  226. *
  227. * @param string $name Resource to return
  228. * @param array $arguments Context parameters
  229. * @return InstanceContext The requested resource context
  230. * @throws TwilioException For unknown resource
  231. */
  232. public function __call(string $name, array $arguments): InstanceContext {
  233. $property = $this->$name;
  234. if (\method_exists($property, 'getContext')) {
  235. return \call_user_func_array(array($property, 'getContext'), $arguments);
  236. }
  237. throw new TwilioException('Resource does not have a context');
  238. }
  239. /**
  240. * Provide a friendly representation
  241. *
  242. * @return string Machine friendly representation
  243. */
  244. public function __toString(): string {
  245. return '[Twilio.Api.V2010.RecordList]';
  246. }
  247. }