/** * Injects the livereload script. * * @param Response $response A Response instance */ protected function injectScript(Response $response) { if (function_exists('mb_stripos')) { $posrFunction = 'mb_strripos'; $substrFunction = 'mb_substr'; } else { $posrFunction = 'strripos'; $substrFunction = 'substr'; } $content = $response->getContent(); $pos = $posrFunction($content, '</body>'); if (false !== $pos) { $script = "livereload.js"; if ($this->checkServerPresence) { // GET is required, as livereload apparently does not support HEAD requests ... $request = $this->httpClient->get($script); try { $checkResponse = $this->httpClient->send($request); if ($checkResponse->getStatusCode() !== 200) { return; } } catch (CurlException $e) { // If error is connection failed, we assume the server is not running if ($e->getCurlHandle()->getErrorNo() === 7) { return; } throw $e; } } $content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos); $response->setContent($content); } }
/** * @param string $id */ public function delete($id) { $url = $this->getConnectionUrl($id); $request = $this->client->delete($this->client->getBaseUrl() . $url, $this->HEADERS); $response = $request->send(); $this->statusCodeValidator->validate(200, $url, $request, $response); }
/** * @return Connection[] */ public function findAll() { $url = $this->getConnectionsUrl(); $request = $this->client->get($this->client->getBaseUrl() . $url); $response = $request->send(); $this->statusCodeValidator->validate(200, $url, $request, $response); return $this->mapJsonToConnectionDescriptors($response->getBody(true)); }
/** * Get data * * @param string $request * * @return array */ protected function get($request) { $response = $this->client->get($this->prefix . $this->getLocale() . $request)->send(); if ($response->isError()) { throw new \RuntimeException('Failed execute request "' . $request . '" to the server "' . $this->client->getBaseUrl() . '"'); } return json_decode($response->getBody(true), true); }
/** * Get data from path. * * @param string $path * * @return array */ public function get($path) { $response = $this->client->get($this->api_prefix . $path)->send(); if ($response->isError()) { throw new \RuntimeException('Failed to query the server ' . $this->client->getBaseUrl()); } $body = json_decode($response->getBody(true), true); if (json_last_error() !== JSON_ERROR_NONE || !is_array($body)) { throw new \RuntimeException('Invalid response from the server ' . $this->client->getBaseUrl()); } return $body; }
public function getBaseUrl($expand = true) { $baseUrl = parent::getBaseUrl(false); $url = $baseUrl; if ($this->tokens instanceof AccessToken) { $url .= strpos($url, '?') ? '&' : '?'; $url .= http_build_query(array('access_token' => $this->tokens->access_token)); } $this->setBaseUrl($url); $return = parent::getBaseUrl($expand); $this->setBaseUrl($baseUrl); return $return; }
public function testCreatesRequestsWithDefaultValues() { $client = new Client($this->getServer()->getUrl() . 'base'); // Create a GET request $request = $client->createRequest(); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals($client->getBaseUrl(), $request->getUrl()); // Create a DELETE request $request = $client->createRequest('DELETE'); $this->assertEquals('DELETE', $request->getMethod()); $this->assertEquals($client->getBaseUrl(), $request->getUrl()); // Create a HEAD request with custom headers $request = $client->createRequest('HEAD', 'http://www.test.com/'); $this->assertEquals('HEAD', $request->getMethod()); $this->assertEquals('http://www.test.com/', $request->getUrl()); // Create a PUT request $request = $client->createRequest('PUT'); $this->assertEquals('PUT', $request->getMethod()); // Create a PUT request with injected config $client->getConfig()->set('a', 1)->set('b', 2); $request = $client->createRequest('PUT', '/path/{a}?q={b}'); $this->assertEquals($request->getUrl(), $this->getServer()->getUrl() . 'path/1?q=2'); }
/** * Overwrites the base URL defined in $client. * You can restore the base URL by calling restoreBaseUrl(). * * @param string $base_url */ protected function setBaseUrl($base_url) { $this->cachedBaseUrl = $this->client->getBaseUrl(); $base_url = rtrim($this->config->endpoint, '/') . '/' . ltrim($base_url, '/'); $this->client->setBaseUrl($base_url); }
public function getBaseUri() { return $this->client->getBaseUrl(); }
private function setLatence(BaseClient $client) { $latenceClient = new BaseClient($client->getBaseUrl()); $response = $latenceClient->get('auth/time')->send(); $this->latence = time() - (int) $response->getBody(true); }
protected function setId($str) { $str = str_replace($this->curl->getBaseUrl() . $this->uri . '/', '', $str); $str = str_replace('/commit', '', $str); $this->id = $str; }