public function run() { if (!parent::getApiKey()) { throw new PagarMe_Exception("You need to configure API key before performing requests."); } $this->parameters = array_merge($this->parameters, array("api_key" => parent::getApiKey())); // var_dump($this->parameters); // $this->headers = (PagarMe::live) ? array("X-Live" => 1) : array(); $client = new RestClient(array("method" => $this->method, "url" => $this->full_api_url($this->path), "headers" => $this->headers, "parameters" => $this->parameters)); $response = $client->run(); $decode = json_decode($response["body"], true); if ($decode === NULL) { throw new Exception("Failed to decode json from response.\n\n Response: " . $response); } else { if ($response["code"] == 200) { return $decode; } else { throw PagarMe_Exception::buildWithFullMessage($decode); } } }
public function run() { if (!parent::getApiKey()) { throw new Exception("You need to configure API key before performing requests."); } $this->parameters = array_merge($this->parameters, array("api_key" => parent::getApiKey())); $client = new RestClient(array("method" => $this->method, "url" => $this->fullApiUrl($this->path), "headers" => $this->headers, "parameters" => $this->parameters)); $response = $client->run(); if ($response["code"] == 204) { return true; } $decode = json_decode($response["body"], true); if ($decode === null) { throw new Exception("Failed to decode json from response.\n\n Response: " . $response); } else { if ($response["code"] == 200 || $response["code"] == 201) { return $decode; } else { throw Exception::buildWithFullMessage($decode); } } }