public function facebook(Request $request)
 {
     $accessTokenUrl = 'https://graph.facebook.com/v2.5/oauth/access_token';
     $graphApiUrl = 'https://graph.facebook.com/v2.5/me';
     $params = ['code' => $request->input('code'), 'client_id' => $request->input('clientId'), 'redirect_uri' => $request->input('redirectUri'), 'client_secret' => '76cd1014c10586c33f3e13f03929a221'];
     $client = new \GuzzleHttp\Client();
     // Step 1. Exchange authorization code for access token.
     $accessToken = json_decode($client->get($accessTokenUrl, ['query' => $params])->getBody(), true);
     // Step 2. Retrieve profile information about the current user.
     $profile = json_decode($client->get($graphApiUrl, ['query' => $accessToken])->getBody(), true);
     // Step 3a. If user is already signed in then link accounts.
     if ($request->header('Authorization')) {
         $user = User::where('facebook', '=', $profile['id']);
         if ($user->first()) {
             return response()->json(['message' => 'There is already a Facebook account that belongs to you'], 409);
         }
         $token = explode(' ', $request->header('Authorization'))[1];
         $payload = (array) JWT::decode($token, Config::get('jwt.secret'), array('HS256'));
         $user = User::find($payload['sub']);
         $user->facebook = $profile['id'];
         $user->displayName = $user->displayName ?: $profile['name'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     } else {
         $user = User::where('facebook', '=', $profile['id']);
         if ($user->first()) {
             return response()->json(['token' => $this->createToken($user->first())]);
         }
         $user = new User();
         $user->facebook = $profile['id'];
         $user->displayName = $profile['name'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     }
 }
Example #2
0
 public static function getOnlineStreams()
 {
     $streams = [];
     $client = new \GuzzleHttp\Client(['headers' => ['Client-ID' => 'ModpackIndex', 'Accept' => 'application/vnd.twitchtv.v3+json']]);
     $response = $client->get('https://api.twitch.tv/kraken/streams?game=Minecraft&limit=100');
     if ($response->getStatusCode() != 200) {
         return false;
     }
     $raw_body = $response->getBody();
     $decoded_body = json_decode($raw_body);
     $channel_total = $decoded_body->_total;
     foreach ($decoded_body->streams as $stream) {
         $stream_id = $stream->channel->_id;
         $streams[$stream_id] = $stream;
     }
     if ($channel_total > 100) {
         $i = 100;
         while ($i <= $channel_total) {
             $response = $client->get('https://api.twitch.tv/kraken/streams?game=Minecraft&limit=100&offset=' . $i);
             $raw_body = $response->getBody();
             $decoded_body = json_decode($raw_body);
             foreach ($decoded_body->streams as $stream) {
                 $stream_id = $stream->channel->_id;
                 $streams[$stream_id] = $stream;
             }
             $i = $i + 100;
         }
     }
     if (!$decoded_body) {
         return false;
     } else {
         return $streams;
     }
 }
Example #3
0
 public function get()
 {
     if ($this->buildQuery() == null) {
         return $this->client->get($this->buildUrl())->json();
     }
     return $this->client->get($this->buildUrl(), ['query' => $this->buildQuery()])->json();
 }
 public function importMovies(Pio $pio)
 {
     $index = 1;
     $pio_eventclient = $pio->eventClient();
     $http_client = new \GuzzleHttp\Client();
     $es_client = new \Elasticsearch\Client();
     for ($x = 1; $x <= 100; $x++) {
         $movies_url = 'https://api.themoviedb.org/3/movie/popular?api_key=' . env('TMDB_KEY') . '&page=' . $x;
         $movies_response = $http_client->get($movies_url);
         $movies_body = $movies_response->getBody();
         $movies_result = json_decode($movies_body, true);
         $movies = $movies_result['results'];
         if (!empty($movies)) {
             foreach ($movies as $row) {
                 $id = $row['id'];
                 $title = $row['title'];
                 $poster_path = '';
                 if (!empty($row['poster_path'])) {
                     $poster_path = $row['poster_path'];
                 }
                 $moviedetails_url = 'https://api.themoviedb.org/3/movie/' . $id . '?api_key=' . env('TMDB_KEY');
                 $moviedetails_response = $http_client->get($moviedetails_url);
                 $movie_details_body = $moviedetails_response->getBody();
                 $movie = json_decode($movie_details_body, true);
                 $overview = $movie['overview'];
                 $release_date = $movie['release_date'];
                 $genre = '';
                 if (!empty($movie['genres'][0])) {
                     $genre = $movie['genres'][0]['name'];
                 }
                 $popularity = $movie['popularity'];
                 $movie_data = array('itypes' => 1, 'tmdb_id' => $id, 'title' => $title, 'poster_path' => $poster_path, 'overview' => $overview, 'release_date' => $release_date, 'genre' => $genre, 'popularity' => $popularity);
                 $pio_response = $pio_eventclient->setItem($index, $movie_data);
                 //create elasticsearch index
                 $params = array();
                 $params['body'] = $movie_data;
                 $params['index'] = 'movierecommendation_app';
                 $params['type'] = 'movie';
                 $params['id'] = $index;
                 $es_res = $es_client->index($params);
                 /* optional if you want to see what's happening
                 			echo "<pre>";
                 			print_r($pio_response);
                 			echo "</pre>";
                 			echo "---";
                 			echo "<pre>";
                 			print_r($es_res);
                 			echo "</pre>";
                 			echo "<br><br>";
                 			*/
                 $index++;
             }
         }
     }
     return 'awesome!';
 }
 /**
  * Call request
  *
  * @param string $cmd
  * @param array $params
  * @return SimpleXMLElement
  * @throws InvalidObjectException
  */
 public function call($cmd, array $params = [])
 {
     $configParams = $this->getConfigParams();
     $accessToken = $this->getAccessToken();
     $headers['Content-Type'] = 'text/xml';
     $headers['Authorization'] = 'Bearer ' . $accessToken;
     $formParams = ['headers' => $headers, 'query' => $params];
     $fullCommand = $configParams[self::CONFIG_API_URL] . $cmd;
     return simplexml_load_string($this->guzzle->get($fullCommand, $formParams)->getBody());
 }
Example #6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request, $article_id = 0)
 {
     //check if you own the article
     if ($article_id > 0) {
         $token = $request->session()->get('x-auth-token');
         $api = new \GuzzleHttp\Client(['base_uri' => env('API_URL'), 'verify' => false, 'headers' => ['X-Auth-Token' => $token]]);
         $user = json_decode($api->get('me')->getBody(), true);
         $article_data = json_decode($api->get('articles/' . $article_id)->getBody(), true);
         if ($article_data['feed'][0]['owner_id'] != $user['id']) {
             return view('_errors.404');
         }
     }
     return view('write.index')->with('article_id', $article_id);
 }
Example #7
0
 protected function _checkLatestVersion()
 {
     $client = new \GuzzleHttp\Client();
     $response = $client->get(VeerApp::VEERCOREURL . "/releases", ['verify' => false]);
     $res = json_decode($response->getBody());
     return head($res)->tag_name;
 }
Example #8
0
 public function disconnect(Request $request)
 {
     $token = $request->session()->get('x-auth-token');
     $api = new \GuzzleHttp\Client(['base_uri' => env('API_URL'), 'verify' => false, 'headers' => ['X-Auth-Token' => $token]]);
     $checkaccounts = $api->get('connect/disconnect')->getBody();
     return json_decode($checkaccounts, true);
 }
Example #9
0
 public function getGeoInfo($ip)
 {
     $cache = Cache::getInstance();
     $return = $cache->get('geo:' . $ip);
     if ($cache->wasResultFound()) {
         if (DEBUG_BAR) {
             Bootstrap::getInstance()->debugbar['messages']->addMessage("Cached GeoInfo: {$ip}");
         }
         return $return;
     }
     $client = new \GuzzleHttp\Client();
     //'https://geoip.maxmind.com/geoip/v2.1/city/me
     $res = $client->get($this->url . $ip, array('auth' => array($this->user, $this->password)));
     $body = $res->getBody(true);
     $json = json_decode($body);
     $return = array('countryCode' => $json->country->iso_code, 'countryName' => $json->country->names->en, 'state' => $json->subdivisions[0]->names->en, 'city' => $json->city->names->en);
     if (empty($return['city'])) {
         $return['city'] = 'Unknown';
     }
     if (empty($return['state'])) {
         $return['state'] = 'Unknown';
     }
     $cache->set('geo:' . $ip, $return, 3600);
     return $return;
 }
Example #10
0
 protected function getFeed($count = 5)
 {
     try {
         $countKey = $this->cacheKey . $count;
         if (null !== $this->cacheProvider && $this->cacheProvider->contains($countKey)) {
             return $this->cacheProvider->fetch($countKey);
         }
         $client = new \GuzzleHttp\Client();
         $params = ['query' => ['access_token' => $this->accessToken, 'limit' => $count, 'fields' => implode(',', $this->fields)]];
         /*
          * Filter by date range
          */
         if (null !== $this->since && $this->since instanceof \Datetime) {
             $params['query']['since'] = $this->since->getTimestamp();
         }
         if (null !== $this->until && $this->until instanceof \Datetime) {
             $params['query']['until'] = $this->until->getTimestamp();
         }
         $response = $client->get('https://graph.facebook.com/' . $this->pageId . '/posts', $params);
         $body = json_decode($response->getBody());
         if (null !== $this->cacheProvider) {
             $this->cacheProvider->save($countKey, $body->data, $this->ttl);
         }
         return $body->data;
     } catch (ClientException $e) {
         return ['error' => $e->getMessage()];
     }
 }
Example #11
0
 function getCity()
 {
     $client = new \GuzzleHttp\Client();
     $response = $client->get($this->base_url . 'city', ['query' => ['key' => $this->apikey]]);
     $body = $response->json();
     return $body;
 }
 public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = array(), $method = 'POST')
 {
     $client = new \GuzzleHttp\Client();
     if ($method == "POST") {
         try {
             $res = $client->post($endpoint, ['config' => ['curl' => [CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false]], 'headers' => $extraHeaders, 'body' => $requestBody]);
             return (object) array("statusCode" => $res->getStatusCode(), "response" => $res->getBody());
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
             if ($e->hasResponse()) {
                 return (object) array("statusCode" => $e->getResponse()->getStatusCode(), "response" => $e->getResponse()->getBody());
             }
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             return (object) array("statusCode" => "", "response" => "Invalid URL");
         }
     } else {
         try {
             $res = $client->get($endpoint, ['config' => ['curl' => [CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false]]]);
             return (object) array("statusCode" => $res->getStatusCode(), "response" => $res->getBody());
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
             if ($e->hasResponse()) {
                 return (object) array("statusCode" => $e->getResponse()->getStatusCode(), "response" => $e->getResponse()->getBody());
             }
         } catch (\GuzzleHttp\Exception\RequestException $e) {
             return (object) array("statusCode" => "", "response" => "Invalid URL");
         }
     }
 }
Example #13
0
 /**
  * @param string $url
  *
  * @return string
  */
 private function getHTML($url)
 {
     $options = $this->config()->get('browser');
     $guzzle = new \GuzzleHttp\Client();
     $response = $guzzle->get($url, $options);
     return $response->getBody()->getContents();
 }
Example #14
0
 /**
  * Retorna uma lista do recurso especificado
  *
  * @return Lista com todos itens do recurso especificado
  */
 public function allByContaId($conta_id)
 {
     $client = new GuzzleHttp\Client();
     $request = $client->get($this->_apiBase . $this->_className . '?access_token=' . $this->_apiKey . '&conta_id=' . $conta_id);
     $response = $request->getBody();
     return $response;
 }
Example #15
0
 /**
  * 
  * @param string $method
  * @param string $url
  * @param string $params
  * @return mixed
  */
 public function call($method, $url, $params)
 {
     $guzzle = new \GuzzleHttp\Client(array('base_url' => $this->root, 'defaults' => array('headers' => array('X-API-KEY' => $this->apiKey, 'User-Agent' => 'TutoPHP/' . self::API_VERSION))));
     if (isset($this->apiUsername) && !empty($this->apiUsername) && isset($this->apiSecret) && !empty($this->apiSecret)) {
         $_params = array_merge($params, array('auth' => array($this->apiUsername, $this->apiSecret)));
     } else {
         $_params = $params;
     }
     try {
         switch ($method) {
             case 'get':
                 $this->response = $guzzle->get($url, $_params);
                 break;
             case 'post':
                 $this->response = $guzzle->post($url, $_params);
                 break;
         }
     } catch (\GuzzleHttp\Exception\ClientException $ex) {
         $this->response = $ex->getResponse();
         $json = $ex->getResponse()->json();
         if (!isset($json['error'])) {
             throw new Tuto\Tuto_Error('We were unable to decode the JSON response from the Tuto API: ' . $json);
         } else {
             throw $this->castError($json);
         }
         return $json;
     }
     return $this->response->json();
 }
Example #16
0
 /**
  * Fetch data.
  *
  * @param string $path
  * @param array $params
  * @param string $tag
  * @param int $cacheLifetime
  * @param bool $forceFetch
  * @return array|mixed
  */
 public function fetchData($path, $params = [], $tag = '', $cacheLifetime = 0, $forceFetch = false)
 {
     // Set default values.
     $this->code = 200;
     $this->message = '';
     $fetch = true;
     $data = Cache::load($this->prefix, $path, $params, $cacheLifetime);
     if (!$forceFetch && count($data) > 0) {
         $fetch = false;
     }
     if ($fetch) {
         // Build and request data.
         $this->url = $this->buildUrl($path, $params);
         try {
             $client = new \GuzzleHttp\Client();
             $result = $client->get($this->url);
             if ($result->getStatusCode() == 200) {
                 $data = json_decode($result->getBody(), true);
             }
         } catch (\Exception $e) {
             $this->code = $e->getCode();
             $this->message = $e->getMessage();
         }
         // Save cache.
         if ($cacheLifetime > 0) {
             Cache::save($this->prefix, $path, $params, $data);
         }
     }
     // Extract on tag.
     if ($tag != '' && isset($data[$tag])) {
         $data = $data[$tag];
     }
     return $data;
 }
 public function getFacebookCount($link)
 {
     $facebookRequest = "https://api.facebook.com/method/links.getStats?urls=" . $link . "&format=json";
     $client = new \GuzzleHttp\Client(['base_uri' => $facebookRequest, 'timeout' => 2.0]);
     $response = $client->get('')->getBody()->getContents();
     return json_decode($response)[0]->total_count;
 }
Example #18
0
 /**
  * Main application logic
  */
 public static function run()
 {
     try {
         $httpClient = new GuzzleHttp\Client();
         $date = date('Y-m-d-h-i-s', time());
         $response = $httpClient->get(self::FORECAST_IMG_URL);
         $sImg = $response->getBody()->getContents();
         $img = imagecreatefromstring($sImg);
         $color = imagecolorat($img, self::MY_CORDS_X, self::MY_CORDS_Y);
         $rgb = imagecolorsforindex($img, $color);
         $red = $rgb['red'];
         $green = $rgb['green'];
         $blue = $rgb['blue'];
         if (!self::checkDefault($red, $green, $blue) && (self::checkRedLine($red) || self::checkAurora($red, $green, $blue))) {
             // Alert! We have a positive aurora forecast
             file_put_contents(sprintf("%s%s.img", self::ALERT_IMG_ARCHIVE, $date), $sImg);
             $ifHttpClient = new GuzzleHttp\Client();
             $ifHttpClient->get(self::IFTTT_TRIGGER_URL);
         }
         exit(0);
     } catch (\Exception $e) {
         var_dump($e);
         exit(1);
     }
 }
Example #19
0
 public function parse($cms, $cms_options)
 {
     $url = $cms_options['version_page'];
     if (empty($url)) {
         throw new EmptyUrlException("URL must be set for '{$cms}'. We can not parse empty url.");
     }
     // fetch url and get the version id
     $client = new \GuzzleHttp\Client();
     try {
         $res = $client->get($url, array('verify' => false));
     } catch (RequestException $e) {
         $status_code = $e->getCode();
         throw new EmptyUrlException("URL '{$url}'' returned status code: {$status_code}. Was expecting 200.");
     }
     $status_code = $res->getStatusCode();
     if ($res->getStatusCode() != 200) {
         throw new EmptyUrlException("URL '{$url}'' returned status code: {$status_code}. Was expecting 200.");
     }
     $body = $res->getBody();
     // loop through all parsers and try to get the cms value.
     // each CMS should have only one parser so once one parser has committed to do the job don't try the other
     // parsers, they should not match
     $version_found = false;
     foreach ($this->parsers as $parser) {
         // can the parser do anything with this content?
         if ($parser->isParser($cms_options['parser'])) {
             $version_found = $parser->parse($body, $cms_options);
             break;
         }
     }
     return $version_found;
 }
Example #20
0
 /**
  * Lookup entitete direktno preko GuzzleHttp
  * 
  * @param string $entity ime entitete - kratka oblika 
  * @param string $ident ident po katerem povprašujemo
  * @param boolean $returnIdOnly a vrnemo samo id ali pa celi lookup objekt
  * @param string $route dodatek k default lookup url-ju
  * @return typeSkoči po ID entitete 
  */
 public function lookupEntity($entity, $ident, $returnIdOnly = true, $route = '')
 {
     $br = $this->getModule('PhpBrowser');
     $client = new \GuzzleHttp\Client();
     /* @var $a \Codeception\Module\Asserts */
     $a = $this->getModule('Asserts');
     if ($route && substr($route, 0, 1) !== '/') {
         $route = '/' . $route;
     }
     $url = $br->_getUrl() . "/lookup/{$entity}{$route}?";
     if (preg_match(self::ID_RE, $ident)) {
         $url .= "ids={$ident}&page=1&per_page=30";
     } else {
         $url .= "ident=" . urlencode($ident) . "&page=1&per_page=30";
     }
     $res = $client->get($url, ['auth' => [\IfiTest\AuthPage::$admin, \IfiTest\AuthPage::$adminPass]]);
     //        codecept_debug($res->getHeader('content-type')[0]);
     $a->assertEquals('application/json; charset=utf-8', $res->getHeader('content-type')[0], "Lookup {$entity} z identom {$ident} ni vrnil pravega content type");
     $json = $res->getBody();
     $decoded = json_decode($json, true);
     $a->assertEquals(JSON_ERROR_NONE, json_last_error(), "Lookup {$entity} z identom {$ident} ni vrnil pravilnega json-a");
     $a->assertEquals("200", $res->getStatusCode(), "Lookup {$entity} z identom {$ident} ni vrnil pravega statusa ");
     $a->assertTrue(count($decoded['data']) > 0, "Lookup {$entity} z identom {$ident} ni našel entitete.");
     if ($returnIdOnly) {
         return $decoded['data'][0]['id'];
     } else {
         return $decoded['data'][0];
     }
 }
 /**
  * Looks up the location passed in the Google Places API via text search
  * and returns the formatted address string, latitiude, and longitude, if available.
  *
  * @param  string $locationString The string to look up as a Google Places location
  * @param  boolean $keepCountry Whether or not to include the last piece of the formatted address (country)
  * @return array Keys are 'address', 'lat', 'lng'
  */
 public function lookupLocation($locationString, $keepCountry = false)
 {
     $retval = ['address' => null, 'lat' => null, 'lng' => null];
     $googleUrl = $this->getGooglePlaceAPIUrl($locationString);
     $client = new \GuzzleHttp\Client();
     $res = $client->get($googleUrl);
     if ($res->getStatusCode() != 200) {
         // log error?
         return $retval;
     }
     $response = $res->getBody()->getContents();
     $json = json_decode($response);
     // check to make sure we have valid json, and also that there's no error
     if ($json != false && $json->status == "OK") {
         if (count($json->results) > 0) {
             // return the first result, because it's the best match
             $result = $json->results[0];
             // should we keep the country identifier at the end of an address?
             if ($keepCountry) {
                 $retval['address'] = $result->formatted_address;
             } else {
                 $addressPieces = explode(",", $result->formatted_address);
                 array_pop($addressPieces);
                 $retval['address'] = implode(",", $addressPieces);
             }
             if ($result->geometry && $result->geometry->location) {
                 $retval['lat'] = $result->geometry->location->lat;
                 $retval['lng'] = $result->geometry->location->lng;
             }
         }
     }
     return $retval;
 }
Example #22
0
 /**
  * Execute the job.
  *
  */
 public function handle()
 {
     $client = new \GuzzleHttp\Client();
     $res = $client->get("https://www.tulsapolice.org/live-calls-/police-calls-near-you.aspx");
     $data = (string) $res->getBody();
     if ($res->getStatusCode() != 200) {
         throw new \Exception('Couldn\'t retrieve crime data');
     }
     $classes = ['accident' => ['/coll/', '/collision/', '/crash/', '/non inj/'], 'serious' => ['/burglary/', '/robbery/', '/homicide/', '/shooting/', '/shots/', '/theft/', '/missing/', '/intrusion/', '/doa/', '/suicide/', '/holdup/', '/stabbing/', '/assault/', '/weapon/'], 'drunk_driver' => ['/drunk/']];
     preg_match_all('/<td .+>(.+)<\\/td><td>(.+)<\\/td>/sU', $data, $matches);
     $scraped_crimes = [];
     foreach ($matches[1] as $key => $val) {
         foreach ($classes as $class => $patterns) {
             foreach ($patterns as $pattern) {
                 if (preg_match($pattern, strtolower($val))) {
                     $class_val = $class;
                 }
             }
         }
         $crime = ['description' => $val, 'address' => ucwords(strtolower($matches[2][$key])), 'class' => isset($class_val) ? $class_val : 'other'];
         $crimeModel = \App\Crime::firstOrCreate($crime);
         $crimeModel->active = true;
         $crimeModel->save();
         $scraped_crimes[] = $crimeModel->toArray();
         unset($class_val);
     }
     $expired = \App\Crime::where('updated_at', '<', \Carbon\Carbon::now()->subMinutes(6)->toDateTimeString())->update(['active' => false]);
     return ['expired' => $expired, 'scraped' => count($scraped_crimes)];
 }
Example #23
0
 /**
  * file_get_content request with additional params
  * @param $purpose
  * @param $additional_params
  *
  * @return xml?
  */
 private function gRequest($purpose, $additional_params = [])
 {
     $client = new \GuzzleHttp\Client();
     $url = $this->BuildURL($this->BuildQuery($purpose, $additional_params));
     $response = $client->get($url);
     dd($response);
 }
 /**
  * @param string $endpoint
  * @param int $since_time_stamp
  * @return array
  * @throws Exception
  */
 public function getSamplesDataFromEndpointSinceTimestamp($endpoint, $since_time_stamp)
 {
     $client = new GuzzleHttp\Client();
     $response = $client->get($endpoint);
     if ($response->getStatusCode() !== 200) {
         throw new Exception('invalid status code!');
     }
     $content_type = $response->getHeader('content-type');
     if (empty($content_type)) {
         throw new Exception('invalid content type!');
     }
     if ($content_type !== 'application/json') {
         throw new Exception('invalid content type!');
     }
     $json = $response->getBody()->getContents();
     $response = json_decode($json, true);
     if (!isset($response['datapoints'])) {
         throw new Exception('missing response datapoints!');
     }
     $datapoints = array();
     foreach ($response['datapoints'] as $datapoint) {
         if (count($datapoint) != 2) {
             continue;
         }
         $time_stamp = $datapoint[1];
         if ($time_stamp <= $since_time_stamp) {
             continue;
         }
         $datapoints[] = $datapoint;
     }
     return $datapoints;
 }
Example #25
0
 /**
  * @param string $email
  * @return \GuzzleHttp\Message\ResponseInterface
  * @throws Exception
  */
 protected function _getResponse($email)
 {
     $email = (string) $email;
     $client = new \GuzzleHttp\Client(['base_url' => 'http://www.xverify.com']);
     $parameterList = array('email' => $email, 'type' => 'json', 'domain' => $this->_getDomain(), 'apikey' => $this->_getCode());
     $url = '/services/emails/verify/?' . http_build_query($parameterList, '', '&', PHP_QUERY_RFC3986);
     return $client->get($url);
 }
Example #26
0
 private function getPage($target)
 {
     $url_base = Config::get('app.url');
     $url = $url_base . $target;
     $client = new \GuzzleHttp\Client();
     $response = $client->get($url);
     return $response->getStatusCode();
 }
Example #27
0
 public function getGeoInfo($ip)
 {
     $client = new \GuzzleHttp\Client();
     $res = $client->get($this->url . '?key=' . $this->key . '&ip=' . $ip);
     $response = explode(';', $res->getBody());
     $return = array('countryCode' => $response[3], 'countryName' => $response[4], 'state' => $response[5], 'city' => $response[6]);
     return $return;
 }
Example #28
0
 /**
  * Retrieve rounds list
  *
  * @param integer|array $competition_ids
  * @return array
  */
 public function rounds($competition_ids = null)
 {
     if (is_array($competition_ids)) {
         $competition_ids = implode(",", $competition_ids);
     }
     $response = $this->client->get('rounds?competition_ids=' . $competition_ids);
     return $this->getResponse($response);
 }
Example #29
0
 /**
  * Fetch the reputation weights and cache them for 1 day
  * @return mixed
  */
 private function fetchWeights()
 {
     $this->weights = Cache::remember('reputation.weights', 60 * 24, function () {
         $request = $this->guzzle->get('https://raw.githubusercontent.com/AdKats/AdKats/master/adkatsreputationstats.json');
         return $request->json();
     });
     return $this;
 }
 /**
  * Queries getaddress.io for houses with the given postcode
  *
  * @param string $postcode       The postcode to return houses for
  * @param string $houseNumOrName If supplied will limit results to those that contain this value
  *
  * @return petelawrence\getaddress\Address[]
  */
 public function lookup($postcode, $houseNumOrName = '')
 {
     //Create a new Guzzle client
     $guzzleClient = new \GuzzleHttp\Client(['base_uri' => 'https://api.getAddress.io/v2/uk/']);
     //Perform the query
     $response = $guzzleClient->get(sprintf('%s/%s', $postcode, $houseNumOrName), ['auth' => ['api-key', $this->apiKey]]);
     $result = $this->parseResponse($response->getBody()->getContents());
     return $result;
 }