FL_ML_Rest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. require_once dirname(__FILE__) . '/FL_ML_Rest_Base.php';
  3. class FL_ML_Rest extends FL_ML_Rest_Base
  4. {
  5. var $name = '';
  6. var $id = null;
  7. function __construct($api_key){
  8. parent::__construct();
  9. $this->apiKey = $api_key;
  10. $this->path = $this->getPath();
  11. }
  12. function setPath($path){
  13. $this->path = $this->url . $path;
  14. }
  15. function getPath()
  16. {
  17. return $this->path;
  18. }
  19. function setName($name)
  20. {
  21. $this->name = $name;
  22. }
  23. function setId($id){
  24. $this->id = $id;
  25. if ($this->id)
  26. $this->path = $this->getPath() . '/' . $id . '/';
  27. else
  28. $this->path = $this->getPath() . '/';
  29. return $this;
  30. }
  31. function getAll(){
  32. return $this->execute('GET');
  33. }
  34. function get($data = null){
  35. if (!$this->id)
  36. throw new InvalidArgumentException('ID is not set.');
  37. return $this->execute('GET');
  38. }
  39. function add($data = null){
  40. return $this->execute('POST', $data);
  41. }
  42. function put($data = null){
  43. return $this->execute('PUT', $data);
  44. }
  45. function remove($data = null){
  46. return $this->execute('DELETE');
  47. }
  48. }