TimeRangeResource.php 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Parent class for usage resources that expose a single date, eg 'Today', 'ThisMonth', etc
  4. * @author Kevin Burke <kevin@twilio.com>
  5. * @license http://creativecommons.org/licenses/MIT/ MIT
  6. * @link http://pear.php.net/package/Services_Twilio
  7. */
  8. class Services_Twilio_TimeRangeResource extends Services_Twilio_UsageResource {
  9. /**
  10. * Return a UsageRecord corresponding to the given category.
  11. *
  12. * @param string $category The category of usage to retrieve. For a full
  13. * list of valid categories, please see the documentation at
  14. * http://www.twilio.com/docs/api/rest/usage-records#usage-all-categories
  15. * @return Services_Twilio_Rest_UsageRecord
  16. * @throws Services_Twilio_RestException
  17. */
  18. public function getCategory($category) {
  19. $page = $this->getPage(0, 1, array(
  20. 'Category' => $category,
  21. ));
  22. $items = $page->getItems();
  23. if (!is_array($items) || count($items) === 0) {
  24. throw new Services_Twilio_RestException(
  25. 400, "Usage record data is unformattable.");
  26. }
  27. return $items[0];
  28. }
  29. }