12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php namespace Client\Request;
- abstract class RequestBase implements RequestInterface {
- protected $loaded = false;
- use \Lib\Curl {
- get as protected mget;
- }
- public function __construct($api_url, $api_token) {
- $this->url = $api_url;
- $this->token = $api_token;
- }
- public function load() {
- $jenc = $this->mget("", "");
- $this->json_set_property($this->json_decode($jenc));
- return $this;
- }
- public function get($scope) {
- $s = substr($scope, strrpos($scope, "/") + 1);
- echo sprintf("Scope: %s\b", $s);
- switch ($s) {
- case "repos":
- return new Repos($this->url . $scope, $this->token);
- }
- }
- private function json_decode($jenc) {
- $obj = json_decode($jenc);
- if (($err = json_last_error()) != JSON_ERROR_NONE)
- throw new RequestErrorException(json_last_error_msg(), $err);
- return $obj;
- }
- abstract protected function json_set_property($obj);
- }
- ?>
|