Source.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Pingpp;
  3. class Source extends ApiResource
  4. {
  5. /**
  6. * @return string The instance URL for this resource. It needs to be special
  7. * cased because it doesn't fit into the standard resource pattern.
  8. */
  9. public function instanceUrl()
  10. {
  11. $id = $this['id'];
  12. if (!$id) {
  13. $class = get_class($this);
  14. $msg = "Could not determine which URL to request: $class instance "
  15. . "has invalid ID: $id";
  16. throw new Error\InvalidRequest($msg, null);
  17. }
  18. if ($this['customer']) {
  19. $parent = $this['customer'];
  20. $base = Customer::classUrl();
  21. $path = 'sources';
  22. } else {
  23. return null;
  24. }
  25. $parent = Util\Util::utf8($parent);
  26. $id = Util\Util::utf8($id);
  27. $parentExtn = urlencode($parent);
  28. $extn = urlencode($id);
  29. return "$base/$parentExtn/$path/$extn";
  30. }
  31. /**
  32. * @param array|null $params
  33. * @param array|string|null $opts
  34. *
  35. * @return Source The deleted source.
  36. */
  37. public function delete($params = null, $opts = null)
  38. {
  39. return $this->_delete($params, $opts);
  40. }
  41. /**
  42. * @param array|string|null $opts
  43. *
  44. * @return Source The saved source.
  45. */
  46. public function save($opts = null)
  47. {
  48. return $this->_save($opts);
  49. }
  50. }