public function logInAs($username) { $crawler = $this->client->request('GET', '/login'); $form = $crawler->filter('button[type=submit]')->form(); $data = ['_username' => $username, '_password' => 'mypassword']; $this->client->submit($form, $data); }
/** * Do login with username * * @param string $username */ private function doLogin($username = '******') { $crawler = $this->client->request('GET', $this->getUrl('fos_user_security_login', array())); $form = $crawler->selectButton('_submit')->form(array('_username' => $username, '_password' => 'qwerty')); $this->client->submit($form); $this->assertTrue($this->client->getResponse()->isRedirect()); $this->client->followRedirects(); }
/** * @param string $query * @param array|null $args * * @return mixed * * @throws AlgoliaException */ public function search($query, $args = null) { if ($args === null) { $args = array(); } $args['query'] = $query; return $this->client->request($this->context, 'POST', '/1/places/query', array(), array('params' => $this->client->buildQuery($args)), $this->context->readHostsArray, $this->context->connectTimeout, $this->context->searchTimeout); }
public function request($method, $path, $data = null, $raw = false) { $start = microtime(true); $response = $this->client->request($method, $path, $data, $raw); $duration = microtime(true) - $start; $this->requests[] = array('duration' => $duration, 'method' => $method, 'path' => rawurldecode($path), 'request' => $data, 'request_size' => strlen($data), 'response_status' => $response->status, 'response' => $response->body, 'response_headers' => $response->headers); $this->totalDuration += $duration; return $response; }
public function run() { $urls = is_array($this->url) ? $this->url : [$this->url]; foreach ($urls as $url) { $response = $this->client->request('GET', $url, ['headers' => ['User-Agent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)']]); $contents[] = (string) $response->getBody(); } return $contents; }
public function request($url, array $parameters = array(), $method = Client::GET, array $headers = array(), array $options = array()) { $key = $this->makeCacheKey($method, $url, $parameters); if ($key) { if ($this->cache->contains($key)) { return $this->cache->fetch($key); } } $result = $this->client->request($url, $parameters, $method, $headers, $options); if ($key) { $this->cache->save($key, $result, $this->lifetime); } return $result; }
public function add(Request $request) { // Ask if we are supplying our own data or requesting it from the server if ($request->has('remote') && ($request->remote = 'true')) { $client = new Client(); $res = $client->request('GET', 'http://fsvaos.net/api/central/aircraft', ['query' => ['icao' => $request->icao]])->getBody(); // Add the airport to the database $data = json_decode($res, true); $aircraft = new Aircraft(); //return dd($data); $aircraft->name = $data[0]['name']; $aircraft->icao = $data[0]['icao']; $aircraft->maxgw = $data[0]['maxgw']; $aircraft->maxpax = $data[0]['maxpax']; $aircraft->range = $data[0]['range']; $aircraft->registration = $request->input('registration'); $aircraft->enabled = true; $aircraft->hub = $request->input('hub'); $aircraft->save(); } else { // insert manual entry system. $aircraft = new Aircraft(); //return dd($data); $aircraft->name = $request->input('name'); $aircraft->icao = $request->input('icao'); $aircraft->maxgw = $request->input('maxgw'); $aircraft->maxpax = $request->input('maxpax'); $aircraft->range = $request->input('range'); $aircraft->registration = $request->input('registration'); $aircraft->enabled = true; $aircraft->hub = $request->input('hub'); $aircraft->save(); } }
/** * assert that putting a fetched resource fails * * @param string $url url * @param Client $client client to use * * @return void */ public function assertPutFails($url, $client) { $client->request('GET', $url); $client->put($url, $client->getResults()); $response = $client->getResponse(); $this->assertEquals(405, $response->getStatusCode()); $this->assertEquals('GET, HEAD, OPTIONS', $response->headers->get('Allow')); }
public function testSuccess() { $this->mockStaticMethod('\\MWHttpRequest', 'canMakeRequests', true); $requestMock = $this->getMock('\\CurlHttpRequest', ['execute', 'getContent'], ['http://example.com'], '', false); $requestMock->expects($this->once())->method('getContent')->willReturn('{}'); $this->mockStaticMethod('\\Http', 'request', $requestMock); $client = new Client('http://example.com', 'id', 'secret'); $this->assertInternalType('object', $client->request('resource', [], [], [])); }
public function testDeleteReferenced() { $page = $this->documentManager->create('page'); $page->setStructureType('hotel_page'); $page->setTitle('Hotels page'); $page->setResourceSegment('/hotels'); $page->getStructure()->bind(['hotels' => [$this->hotel1->getUuid(), $this->hotel2->getUuid()]]); $this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']); $this->documentManager->flush(); $this->client->request('DELETE', '/snippets/' . $this->hotel1->getUuid() . '?_format=text'); $response = $this->client->getResponse(); $this->assertEquals(409, $response->getStatusCode()); }
/** * Execute a request on this resource * * @param mixed $scope * @param mixed $data * @return mixed */ public function request($method, $scope = null, $data = null) { if (is_array($scope)) { $data = $scope; $scope = null; } $url = $scope ? $this->url . '/' . ltrim($scope, '/') : $this->url; $result = self::$client->request($method, $url, $data); if (!$scope && $result instanceof Resource) { // TODO: how should POST be handled here? foreach ($result->data() as $key => $value) { self::offsetSet($key, $value); } } return $scope ? $result : $this; }
/** * Calls the reCAPTCHA siteverify API to verify whether the user passes * CAPTCHA test. * * @param string $response The value of 'g-recaptcha-response' in the submitted form. * @param string $remoteIp The end user's IP address. * @return Response Response from the service. */ public function verify($response, $remoteIp = null) { // Discard empty solution submissions if (empty($response)) { $recaptchaResponse = new Response(false, array('missing-input-response')); return $recaptchaResponse; } $q = []; $q['secret'] = $this->secret; $q['response'] = $response; $q['remoteip'] = $remoteIp; try { $recaptchaResponse = $this->client->request("POST", null, ['form_params' => $q]); } catch (\GuzzleHttp\Exception\RequestException $ex) { $recaptchaResponse = $ex->getResponse(); } return Response::fromJson($recaptchaResponse->getBody()->getContents()); }
/** * @param string $query * @param array|null $params * @param $cursor * * @return mixed */ public function browseFrom($query, $params = null, $cursor = null) { if ($params === null) { $params = []; } foreach ($params as $key => $value) { if (gettype($value) == 'array') { $params[$key] = json_encode($value); } } if ($query != null) { $params['query'] = $query; } if ($cursor != null) { $params['cursor'] = $cursor; } return $this->client->request($this->context, 'GET', '/1/indexes/' . $this->urlIndexName . '/browse', $params, null, $this->context->readHostsArray, $this->context->connectTimeout, $this->context->readTimeout); }
/** * testRequestThrowsExpectedExceptionWhenResponseContainsErrorFlag * * @return void * @covers \QafooLabs\RestClient\RemoteException * @expectedException \QafooLabs\RestClient\RemoteException */ public function testRequestThrowsExpectedExceptionWhenResponseContainsErrorFlag() { $this->writeTestPath(array('error' => true, 'type' => 42, 'message' => 'A message')); $client = new Client($this->server); $client->request('GET', $this->path); }
/** * @param string device * @param string query * @return json events */ public function getEvents($device, $query) { $response = $this->client->request('GET', 'http://api.thingsee.com/v2/events/' . Config::get('thingsee.' . $device . '') . $query, ['headers' => ['Authorization' => 'Bearer ' . $this->accountAuthToken]]); return json_decode($response->getBody(), true); }
/** * @param $objectID * @param $content * @param bool $forwardToReplicas * * @return mixed * * @throws AlgoliaException */ public function saveSynonym($objectID, $content, $forwardToReplicas = false) { return $this->client->request($this->context, 'PUT', '/1/indexes/' . $this->urlIndexName . '/synonyms/' . urlencode($objectID) . '?forwardToReplicas=' . ($forwardToReplicas ? 'true' : 'false'), null, $content, $this->context->writeHostsArray, $this->context->connectTimeout, $this->context->readTimeout); }
public function test_simple() { $cs = new Client(API_ENDPOINT, API_KEY, SECRET_KEY); $result = $cs->request('listVirtualMachines'); var_dump($result); }
/** * Creates a message on conversation of given user * * @param Model\Message $message * @return Model\Message */ public function add(Model\Message $message) { $response = $this->client->request('/appusers/' . $this->appUser->id . '/conversation/messages', 'POST', $message->getPayload()); return new Model\Message($response['message']); }
function request($path, $params = null, $content = null) { if (isset($params)) $params = array_merge ($params, $this->params); else $params = $this->params; if (isset ($this->access_token)) $this->token = new Token( $this->access_token['oauth_token'], $this->access_token['oauth_token_secret']); else unset($this->token); $client = new Client($this->consumer, $this->token); $this->status = 0; $this->response['reason'] = null; try { if (isset($content) and is_array($content)) { $content_params = array(); foreach ($content as $key => $value) { $content_params[] = sprintf('%s=%s', rawurlencode($key), rawurlencode($value)); } $content = implode('&', $content_params); } $resp = $client->request( $this->baseURL.$path, "POST", /*$request->to_header()*/null, $content); if ($json = json_decode($resp)) $resp = $json; if (isset($resp->error_text)) { $this->status = -1; $this->response['body'] = null; $this->response['reason'] = $resp->error_text; } else $this->response['body'] = $resp; } catch (PlurkOAuthException $e) { $this->status = -1; $this->response['reason'] = $e->getMessage(); } return array( 'content' => $this->response['body'], 'code' => $this->status, 'reason' => $this->response['reason'], ); }
public static function getStatus() { return Client::request('user/status', array()); }