requestbase.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php namespace Client\Request;
  2. abstract class RequestBase implements RequestInterface {
  3. protected $loaded = false;
  4. use \Lib\Curl {
  5. get as protected mget;
  6. }
  7. public function __construct($api_url, $api_token) {
  8. $this->url = $api_url;
  9. $this->token = $api_token;
  10. }
  11. public function load() {
  12. $jenc = $this->mget("", "");
  13. $this->json_set_property($this->json_decode($jenc));
  14. return $this;
  15. }
  16. public function get($scope) {
  17. $s = substr($scope, strrpos($scope, "/") + 1);
  18. echo sprintf("Scope: %s\b", $s);
  19. switch ($s) {
  20. case "repos":
  21. return new Repos($this->url . $scope, $this->token);
  22. }
  23. }
  24. private function json_decode($jenc) {
  25. $obj = json_decode($jenc);
  26. if (($err = json_last_error()) != JSON_ERROR_NONE)
  27. throw new RequestErrorException(json_last_error_msg(), $err);
  28. return $obj;
  29. }
  30. abstract protected function json_set_property($obj);
  31. }
  32. ?>