/** * Returns PageSpeed score, page statistics, and PageSpeed formatted results for specified URL * * @param string $url * @param string $locale * @param string $strategy * @param optional array $extraParams * @return array * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public function getResults($url, $locale = 'en_US', $strategy = 'desktop', array $extraParams = null) { if (0 === preg_match('#http(s)?://.*#i', $url)) { throw new InvalidArgumentException('Invalid URL'); } $client = new \Guzzle\Service\Client($this->gateway); /** @var $request \Guzzle\Http\Message\Request */ $request = $client->get('runPagespeed'); $request->getQuery()->set('prettyprint', false)->set('url', $url)->set('locale', $locale)->set('strategy', $strategy); if (isset($extraParams)) { $query = $request->getQuery(); foreach ($extraParams as $key => $value) { $query[$key] = $value; } } try { $response = $request->send(); $response = $response->getBody(); $response = json_decode($response, true); return $response; } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) { $response = $e->getResponse(); $response = $response->getBody(); $response = json_decode($response); throw new RuntimeException($response->error->message, $response->error->code); } }
function getContent() { if (!$this->enabled) { return json_encode(array()); } require_once dirname(__DIR__) . '/vendor/guzzle/guzzle.phar'; $time = time(); $url = $this->getUrl(); $client = new Guzzle\Service\Client($url); $request = $client->get($url); $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, $this->curlConnectTimeout); $request->getCurlOptions()->set(CURLOPT_TIMEOUT, $this->curlTimeout); try { $response = $request->send(); } catch (\Guzzle\Http\Exception\BadResponseException $e) { if ($this->logging) { file_put_contents($this->logFilePath, 'time: ' . (time() - $time) . ', url: ' . $url . ', exception: ' . $e->getMessage() . "\n", FILE_APPEND); } return '[]'; } $content = $response->getBody(true); if ($this->logging) { file_put_contents($this->logFilePath, 'time: ' . (time() - $time) . ', url: ' . $url . ', response: ' . $content . "\n", FILE_APPEND); } return $content; }
public function create($job, $data) { $dropboxClient = new \Guzzle\Service\Client('https://' . Config::get('app.dropbox_host') . '/'); $request = $dropboxClient->get('localize/' . $data['entry']['id']); $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false); // for testing ONLY! $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false); // for testing ONLY! $response = $request->send()->json(); if ($response['success']) { $job->delete(); } else { dd($response); // TODO: logging of error $job->release(); } }
protected function _callMethod($command, $options) { $client = $this->_client; if (null === $client) { $client = new \Guzzle\Service\Client(static::URL_REST); } /** @var $request \Guzzle\Http\Message\Request */ $request = $client->get($command, array('App-Key' => $this->getToken())); $request->setAuth($this->getUsername(), $this->getPassword()); $response = $request->send(); // Execute the request and decode the json result into an associative array $response = @json_decode($response->getBody(), true); // Check JSON parsing errors if (!$response) { throw new \Exception("Error: Response is not JSON valid"); } // Check for errors returned by the API if (!$response || isset($response['error'])) { throw new \Exception("Error: " . $response['error']['errormessage']); } return $response; }
<?php include 'headers.php'; require_once 'guzzle.phar'; // http://server_ip:server_port/library/sections/sectionID/all - skip the sections and just get them all $server_ip = $_GET['server_ip']; $server_port = $_GET['server_port']; $sectionID = $_GET['sectionID']; $token = $_GET['token']; $client = new Guzzle\Service\Client('http://' . $server_ip); $commandURL = '/library/sections/' . $sectionID . '/all?' . TOKEN_PARAM . '=' . $token; $request = $client->get($commandURL, array('Content-Length' => 0, HEADER_PLATFORM => VALUE_PLATFORM, HEADER_PLATFORM_VERSION => VALUE_PLATFORM_VERSION, HEADER_PROVIDES => VALUE_PROVIDES, HEADER_PRODUCT => VALUE_PRODUCT, HEADER_VERSION => VALUE_VERSION, HEADER_DEVICE => VALUE_DEVICE, HEADER_CLIENT => VALUE_CLIENT)); $request->setPort($server_port); //$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false); //$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false); $response = $client->send($request); echo $response->getBody();
private function sendSMS($number, $sender, $msg) { $phonenumber = $number; $phonenumber = str_replace('+', '', $phonenumber); if (strlen($phonenumber) == "11") { $phonenumber = "88" . $phonenumber; } if (strlen($phonenumber) == "13") { if (preg_match("/^88017/i", "{$phonenumber}") or preg_match("/^88016/i", "{$phonenumber}") or preg_match("/^88015/i", "{$phonenumber}") or preg_match("/^88011/i", "{$phonenumber}") or preg_match("/^88018/i", "{$phonenumber}") or preg_match("/^88019/i", "{$phonenumber}")) { $myaccount = urlencode("supersoft"); $mypasswd = urlencode("0qMLQO"); $sendBy = urlencode($sender); $api = "http://api.infobip.com/api/v3/sendsms/plain?user="******"&password="******"&sender=" . $sendBy . "&SMSText=" . $msg . "&GSM=" . $phonenumber . "&type=longSMS"; $client = new \Guzzle\Service\Client($api); // Get your response: $response = $client->get()->send(); $body = $response->xml(); $status = $body->result->status; if ($status == "0") { return "SMS SEND"; } return $status; } else { return "Invalid Number"; } } else { return "Invalid Number"; } }
|-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::resource('entity', 'EntitiesController'); Route::get('/', function () { return view('welcome'); }); Route::get('/about', 'PagesController@about'); Route::post('/user/register/', 'UsersController@create'); Route::get('/csrf', function () { return csrf_token(); }); Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]); Route::post('authenticate', 'AuthenticateController@authenticate'); Route::get('authenticate/user', 'AuthenticateController@getAuthenticatedUser'); /*Route::get('/entity/{entityName}', function($entityName){ //$entity_client = new Guzzle\Service\Client('http://en.wikipedia.org/w/api.php?pllimit=2&action=query&prop=extracts&format=jsonfm&formatversion=2&redirects=1&exintro=&explaintext=titles='); //$response = $entity_client->get($entityName)->send(); //echo $response->getBody(); $wikipedia = new \Casinelli\Wikipedia\Wikipedia; return $wikipedia->search("Rome")->getSentences(5); });*/ Route::get('users/{username}', function ($username) { $username_client = new Guzzle\Service\Client('https://api.github.com/'); $response = $username_client->get("users/{$username}")->send(); echo $response->getBody(); });
/** * Get Intervals of Average Response Time and Uptime During a Given Interval * * @param int $checkId * @param string $resolution * @return array */ public function getPerformanceSummary($checkId, $resolution = 'hour') { $client = new \Guzzle\Service\Client('https://api.pingdom.com/api/2.0'); /** @var $request \Guzzle\Http\Message\Request */ $request = $client->get('summary.performance/' . $checkId, array('App-Key' => $this->token)); $request->setAuth($this->username, $this->password); $request->getQuery()->set('resolution', $resolution); $request->getQuery()->set('includeuptime', 'true'); $response = $request->send(); $response = json_decode($response->getBody(), true); return $response['summary'][$resolution . 's']; }