/** * @param string $url relative URL * @return \GuzzleHttp\Message\FutureResponse|\GuzzleHttp\Message\ResponseInterface|\GuzzleHttp\Ring\Future\FutureInterface|null * @throws \Exception * @throws \GuzzleHttp\Exception\ClientException * @throws \InvalidArgumentException */ protected function doGet($url) { if (!$url) { throw new \InvalidArgumentException('URL erforderlich!'); } try { return $this->client->get($url); } catch (ClientException $e) { if ($e->getCode() == 404) { return null; } throw $e; } }
function lxserver_main() { global $gbl, $sgbl, $login, $ghtml; global $argv, $argc; if ($argv[1] === 'slave') { $login = new Client(null, null, 'slave'); $gbl->is_slave = true; $gbl->is_master = false; $rmt = unserialize(lfile_get_contents("__path_slave_db")); $login->password = $rmt->password; $argv[1] = "Running as Slave"; } else { if ($argv[1] === 'master') { $login = new Client(null, null, 'admin'); $gbl->is_master = true; $gbl->is_slave = false; $login->get(); $argv[1] = "Running as Master"; } else { print "Wrong arguments\n"; exit; } } $login->cttype = 'admin'; // Set php script execution timer to unlimited set_time_limit(0); // Start internal socket for remote some_server(); }
/** * Retrieve an array of Publication objects according to a search query. * * @param array $query The query. * @return Publication[] */ public static function find(array $query) { $pubs = Client::get('publication', $query); return array_map(function ($data) { return new self($data); }, $pubs); }
public function getWeatherFor($city) { $client = new Client(['base_uri' => 'http://api.openweathermap.org/data/2.5/', 'timeout' => 2.0]); $response = $client->get('weather?q=' . $city); $contents = $response->getBody()->getContents(); return json_decode($contents); }
/** * Get the mimetype of a file. * * @param string $path * * @return array|false */ public function getMimetype($path) { $stream = tmpfile(); fwrite($stream, $this->client->get($path)); rewind($stream); return ['mimetype' => Util::guessMimeType(stream_get_meta_data($stream)['uri'], stream_get_contents($stream))]; }
function lxserver_main() { global $gbl, $sgbl, $login, $ghtml; global $argv, $argc; // Set time limit to indefinite execution if ($argv[1] === 'slave') { $login = new Client(null, null, 'slave'); //Initthisdef uses the db to load the drivers. NO longer callable in slave. //$login->initThisDef(); $gbl->is_slave = true; $gbl->is_master = false; $rmt = unserialize(lfile_get_contents("__path_slave_db")); $login->password = $rmt->password; $argv[1] = "Running as Slave"; } else { if ($argv[1] === 'master') { $login = new Client(null, null, 'admin'); $gbl->is_master = true; $gbl->is_slave = false; $login->get(); $argv[1] = "Running as Master"; } else { print "Wrong arguments\n"; exit; } } $login->cttype = 'admin'; //set_error_handler("lx_error_handler"); //set_exception_handler("lx_exception_handler"); set_time_limit(0); some_server(); }
/** * @param $url * @return Response */ public function get($url) { $bits = explode('v=', $url); $videoId = end($bits); /** @var ResolveResponse $response */ return parent::get(sprintf(self::API_URL, $this->apiKey, $videoId)); }
/** * @return Response|null */ public function getLastPage() { if ($this->pages['last']) { return $this->client->get(str_replace(Request::API_URL, '', $this->pages['last'])); } return NULL; }
public function create($pid, $name, $identifier = null, $template = null) { if (!$identifier) { $identifier = Identifiers::getIdentifier($name); if (!$identifier) { throw new Exception("Identifier derived from dimension name '{$name}' is not valid. " . "Choose other name or custom identifier."); } } $call = $this->client->get("/gdc/md/{$pid}/data/sets"); $existingDataSets = []; foreach ($call['dataSetsInfo']['sets'] as $r) { $existingDataSets[] = $r['meta']['identifier']; } if (!in_array(Identifiers::getDateDimensionId($name, $template), $existingDataSets)) { $this->client->getDatasets()->executeMaql($pid, sprintf('INCLUDE TEMPLATE "%s" MODIFY (IDENTIFIER "%s", TITLE "%s");', self::getTemplateUrn($template), $identifier, $name)); } }
/** * * @param string $session_id * @return string */ public function read($session_id) { if (isset($this->_cache[$session_id])) { return $this->_cache[$session_id]; } $session_data = $this->_client->get($this->_prefix . $session_id)->data; return $this->_cache[$session_id] = $session_data === null ? '' : $session_data; }
public function create($pid, $name, $identifier = null) { if (!$identifier) { $identifier = Identifiers::getIdentifier($name); if (!$identifier) { throw new Exception("Identifier derived from dimension name '{$name}' is not valid. " . "Choose other name or custom identifier."); } } $call = $this->gdClient->get("/gdc/md/{$pid}/data/sets"); $existingDataSets = []; foreach ($call['dataSetsInfo']['sets'] as $r) { $existingDataSets[] = $r['meta']['identifier']; } if (!in_array(self::getTimeDimensionIdentifier($name), $existingDataSets)) { $this->gdClient->getDatasets()->executeMaql($pid, self::getCreateMaql($identifier, $name)); } }
/** * Perform a GET request, get a decoded JSON response. * Internally verifies an Ed25519 signature. * * @param string $url * @param SignaturePublicKey $publicKey * @param array $params * @return mixed */ public function getSignedJSON(string $url, SignaturePublicKey $publicKey, array $params = []) { $response = $this->client->get($url, $this->params($params, $url)); if ($response instanceof Response) { return $this->parseSignedJSON($response, $publicKey); } return null; }
public function diff($pid, $model) { $uri = "/gdc/projects/{$pid}/model/diff?includeDeprecated=true&includeGrain=true"; $result = $this->client->post($uri, ['diffRequest' => ['targetModel' => $model]]); if (isset($result['asyncTask']['link']['poll'])) { $try = 1; do { sleep(10 * $try); $taskResponse = $this->client->get($result['asyncTask']['link']['poll']); if (!isset($taskResponse['asyncTask']['link']['poll'])) { if (isset($taskResponse['projectModelDiff']['updateScripts'])) { $lessDestructive = []; $moreDestructive = []; // Preserve data if possible foreach ($taskResponse['projectModelDiff']['updateScripts'] as $updateScript) { if ($updateScript['updateScript']['preserveData'] && !$updateScript['updateScript']['cascadeDrops']) { $lessDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!count($lessDestructive) && !$updateScript['updateScript']['preserveData'] && !$updateScript['updateScript']['cascadeDrops']) { $lessDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!$updateScript['updateScript']['preserveData'] && $updateScript['updateScript']['cascadeDrops']) { $moreDestructive = $updateScript['updateScript']['maqlDdlChunks']; } if (!count($moreDestructive) && $updateScript['updateScript']['preserveData'] && $updateScript['updateScript']['cascadeDrops']) { $moreDestructive = $updateScript['updateScript']['maqlDdlChunks']; } } $description = []; foreach ($taskResponse['projectModelDiff']['updateOperations'] as $o) { $description[] = vsprintf($o['updateOperation']['description'], $o['updateOperation']['parameters']); } return ['moreDestructiveMaql' => $moreDestructive, 'lessDestructiveMaql' => $lessDestructive, 'description' => $description]; } else { throw Exception::unexpectedResponseError('Polling of Model diff could not be finished', 'GET', $result['asyncTask']['link']['poll'], $taskResponse); } } $try++; } while (true); } else { throw Exception::unexpectedResponseError('Polling of Model diff could not be started', 'POST', $uri, $result); } return false; }
/** * Retrieve an array of CourseSegmentInstance objects according to * a search query. * * @param array $query The query. * @return CourseSegmentInstance[] */ public static function find(array $query) { if (isset($query['semester']) && $query['semester'] instanceof Semester) { $query['semester'] = $query['semester']->daisyFormat(); } $csis = Client::get("courseSegment", $query); return array_map(function ($data) { return new self($data); }, $csis); }
public function test_set_get() { $client = new Client(); $client->addServers(array('127.0.0.1', 11211), array('127.0.0.1', 11212)); $this->assertFalse($client->isConnected()); $this->assertInstanceOf('\\Memcached', $client->getMemcached()); $this->assertTrue($client->isConnected()); $this->assertEquals(1, $client->set('foobar', 42)); $this->assertEquals(42, $client->get('foobar')); }
/** * Convert foreign id values from string to MongoId. * * @return void */ public function up() { $db = \DB::getMongoDB(); Client::get()->each(function (Client $client) use($db) { // The Client model has a mutator that converts lrs_id values to MongoId objects. $client->lrs_id = $client->lrs_id; $client->save(); }); echo 'Foreign id values in client collection converted from string to MongoId.' . PHP_EOL; }
public static function find($room, \DateTime $start, \DateTime $end = null) { if (is_null($end)) { $end = clone $start; $end->add(new \DateInterval('P1D')); } $events = Client::get('schedule', ['room' => $room, 'start' => $start->format('Y-m-d'), 'end' => $end->format('Y-m-d')]); return array_map(function ($data) { return new static($data); }, $events); }
/** * @inheritdoc */ public function offsetGet($jid) { $job_data = $this->client->get($jid); if ($job_data === false) { $job_data = $this->client->{'recur.get'}($jid); if ($job_data === false) { return null; } } return new Job($this->client, json_decode($job_data, true)); }
public static function get($subscription_id, $subscription_adjustment_id, $client = null) { if ($client == null) { $client = new Client(); } $response = $client->get(sprintf(self::$SUBSCRIPTION_ADJUSTMENT_PATH, $subscription_id) . $subscription_adjustment_id); if ($response[0] == 200) { return new self($response[1], $client); } else { return $response[2]; } }
public static function get($payment_request_id, $payment_id, $client = null) { if ($client == null) { $client = new Client(); } $response = $client->get(sprintf(self::$PAYMENTS_PATH, $payment_request_id) . $payment_id); if ($response[0] == 200) { return new self($response[1], $client); } else { return $response[2]; } }
public function cancelInvitation($pid, $email) { $result = $this->client->get("/gdc/projects/{$pid}/invitations"); foreach ($result['invitations'] as $r) { if (strtolower($r['invitation']['content']['email']) != strtolower($email)) { continue; } if ($r['invitation']['content']['status'] == 'CANCELED') { continue; } $this->client->delete($r['invitation']['links']['self']); } }
public static function get($payment_request_id, $client = null) { if ($client == null) { $client = new Client(); } $response = $client->get(self::$PAYMENT_REQUESTS_PATH . $payment_request_id); if ($response[0] == 200) { $object = new self($response[1], $client); return $object; } else { return $response[2]; } }
public static function findClientsList($id_user = null) { if ($id_user == null) { $clients = Client::get(array('id', 'name')); } else { $clients = Client::where('id_user', '=', $id_user)->get(array('id', 'name')); } $clientsRow = array(); $clientsRow[0] = "Clientes"; foreach ($clients as $client) { $clientsRow[$client->id] = $client->name; } return $clientsRow; }
public function loadData($pid, $dirName) { $uri = "/gdc/md/{$pid}/etl/pull2"; $result = $this->client->post($uri, ['pullIntegration' => $dirName]); if (isset($result['pull2Task']['links']['poll'])) { $try = 1; do { sleep(10 * $try); $taskResponse = $this->client->get($result['pull2Task']['links']['poll']); if (!isset($taskResponse['wTaskStatus']['status'])) { throw Exception::unexpectedResponseError('ETL task could not be checked', 'GET', $result['pull2Task']['links']['poll'], $taskResponse); } $try++; } while ($taskResponse['wTaskStatus']['status'] == 'RUNNING'); if ($taskResponse['wTaskStatus']['status'] == 'ERROR') { $errors = []; if (isset($taskResponse['messages'])) { foreach ($taskResponse['messages'] as $m) { if (isset($m['error'])) { $errors[] = Exception::parseMessage($m['error']); } } } if (isset($taskResponse['wTaskStatus']['messages'])) { foreach ($taskResponse['wTaskStatus']['messages'] as $m) { if (isset($m['error'])) { $errors[] = Exception::parseMessage($m['error']); } } } throw new Exception($errors); } return isset($taskResponse['messages']) ? $taskResponse['messages'] : []; } else { throw Exception::unexpectedResponseError('ETL task failed', 'POST', $uri, $result); } }
public function getDomainUsersYield($domain) { // first page $result = $this->client->get("/gdc/account/domains/{$domain}/users"); if (isset($result['accountSettings']['items'])) { (yield $result['accountSettings']['items']); } // next pages while (isset($result['accountSettings']['paging']['next'])) { $result = $this->client->get($result['accountSettings']['paging']['next']); if (isset($result['accountSettings']['items'])) { (yield $result['accountSettings']['items']); } } }
public function testGet() { $client = new Client('', '', false); $this->assertUrl('/REST/contact', $client->get(Resources::$Contact)); $this->assertFilters(['id' => 2], $client->get(Resources::$Contact, ['filters' => ['id' => 2]])); $response = $client->get(Resources::$ContactGetcontactslists, ['id' => 2]); $this->assertUrl('/REST/contact/2/getcontactslists', $response); // error on sort ! $response = $client->get(Resources::$Contact, ['filters' => ['sort' => 'email+DESC']]); $this->assertUrl('/REST/contact', $response); $this->assertUrl('/REST/contact/2', $client->get(Resources::$Contact, ['id' => 2])); $this->assertUrl('/REST/contact/test@mailjet.com', $client->get(Resources::$Contact, ['id' => '*****@*****.**'])); }
public static function fetchPage($index = 0, $limit = null) { if ($limit == null) { $limit = self::$page_length; } self::$fetch_options['_start'] = strval($index); self::$fetch_options['_limit'] = strval($limit); $data = json_decode(Client::get(self::endpoint(), self::$fetch_options), true); $objects = array(); $datas = []; if (array_key_exists('objects', $data)) { $datas = (array) $data['objects']; } else { $datas = []; } foreach ($datas as $key => $value) { $value = (array) $value; $objects[] = static::factory(['data' => $value]); } return $objects; }
/** * Initiates authentication with the remote service and returns a * array containing the storage system URL, CDN URL (can be empty) * and session token. * * @return array * @throws \Exception|\OpenStackStorage\Exceptions\ResponseError * @throws \OpenStackStorage\Exceptions\AuthenticationError * @throws \OpenStackStorage\Exceptions\AuthenticationFailed * @throws \Exception */ public function authenticate() { $client = new Client(array('timeout' => $this->timeout)); $client->setBaseURL(sprintf('%s://%s:%d/', $this->urlInfo['scheme'], $this->urlInfo['host'], $this->urlInfo['port'])); $client->setUserAgent($this->userAgent); try { $response = $client->get($this->urlInfo['path'], null, $this->headers); } catch (Exceptions\ResponseError $e) { if (401 == $e->getCode()) { // A status code of 401 indicates that the supplied credentials // were not accepted by the authentication service. throw new Exceptions\AuthenticationFailed(); } throw $e; } if (isset($response['headers']['x-auth-token'])) { $authToken = $response['headers']['x-auth-token']; } elseif (isset($response['headers']['x-storage-token'])) { $authToken = $response['headers']['x-storage-token']; } else { $authToken = null; } if (isset($response['headers']['x-storage-url'])) { $storageUrl = $response['headers']['x-storage-url']; } else { $storageUrl = null; } if (!($authToken && $storageUrl)) { throw new Exceptions\AuthenticationError('Invalid response from the authentication service.'); } if (isset($response['headers']['x-cdn-management-url'])) { $cdnUrl = $response['headers']['x-cdn-management-url']; } else { $cdnUrl = null; } return array($storageUrl, $cdnUrl, $authToken); }
/** * Autodetect the nodes in this cluster through Cluster State API */ private function autodetect_parseNodes() { foreach ($this->nodes as $node) { try { $client = new Client('http://' . $node['host'] . ':' . $node['port']); $request = $client->get('/_nodes/http'); $response = $request->send()->json(); foreach ($response['nodes'] as $newNode) { //we don't want http-inaccessible nodes if (!isset($newNode['http_address'])) { continue; } preg_match('/inet\\[\\/([0-9\\.]+):([0-9]+)\\]/i', $newNode['http_address'], $match); $tNode = array('host' => $match[1], 'port' => $match[2]); //use host as key so that we don't add duplicates $this->nodes[$match[1]] = $tNode; } //we have the complete node list, no need to keep checking break; } catch (\Guzzle\Http\Exception\BadResponseException $e) { //error with this node, continue onto the next one } } }
/** * @param string $path * @param array $params * * @return mixed */ public function get($path, array $params = array()) { return $this->client->get($this->preparePath($path), $params); }