public function latLng($lat, $lng) { if (empty($lat) || empty($lng)) { throw new Exceptions\EmptyArgumentsException('Empty arguments.'); } $response = \GuzzleHttp\get('http://maps.googleapis.com/maps/api/geocode/json', ['query' => ['latlng' => $lat . ',' . $lng]]); # check for status in the response switch ($response->json()['status']) { case "ZERO_RESULTS": # indicates that the geocode was successful but returned no results. This may occur if the geocoder was passed a non-existent address. # indicates that the geocode was successful but returned no results. This may occur if the geocoder was passed a non-existent address. case "OVER_QUERY_LIMIT": # indicates that you are over your quota. # indicates that you are over your quota. case "REQUEST_DENIED": # indicates that your request was denied. # indicates that your request was denied. case "INVALID_REQUEST": # generally indicates that the query (address, components or latlng) is missing. # generally indicates that the query (address, components or latlng) is missing. case "UNKNOWN_ERROR": return false; case "OK": # indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned. return new Response($response->json()); } }
public function testCRUD() { // GET ALL (none) $response = GuzzleHttp\get("http://miniapi.local/test/endpoint.php"); $this->assertTrue(is_array($response->json())); $this->assertEquals(0, count($response->json())); // CREATE ONE GuzzleHttp\post("http://miniapi.local/test/endpoint.php", ["json" => ["name" => "fabs"]]); // GET ALL (now 1) $response = GuzzleHttp\get("http://miniapi.local/test/endpoint.php"); $json = $response->json(); $this->assertEquals(1, count($json)); $this->assertEquals(1, $json[0]["id"]); $this->assertEquals('fabs', $json[0]["name"]); // EDIT THE NEWLY CREATED GuzzleHttp\put("http://miniapi.local/test/endpoint.php", ["json" => ["id" => 1, "name" => "laurent"]]); // GET ALL (still 1) $response = GuzzleHttp\get("http://miniapi.local/test/endpoint.php"); $json = $response->json(); $this->assertEquals(1, count($json)); $this->assertEquals(1, $json[0]["id"]); $this->assertEquals('laurent', $json[0]["name"]); // DELETE IT $response = GuzzleHttp\delete("http://miniapi.local/test/endpoint.php/1"); // GET ALL (now 0) $response = GuzzleHttp\get("http://miniapi.local/test/endpoint.php"); $json = $response->json(); $this->assertEquals(0, count($json)); }
/** * Download the temporary Zip to the given file. * * @param string $zipFile * @return $this */ protected function download($zipFile) { $data = json_decode(\GuzzleHttp\get('http://laravel-china.org/download_link.json')->getBody(), true); $response = \GuzzleHttp\get($data['link'])->getBody(); file_put_contents($zipFile, $response); return $this; }
<?php /** * A quick & dirty print desk implementation for the print service. * * @author Laju Morrison <*****@*****.**> */ require './vendor/autoload.php'; define('API_HOST', 'http://127.0.0.1:4000'); define('ACCESS_TOKEN', 'testclient:testsecret'); define('CACHE_DIR', __DIR__ . '/cache'); require_once 'view.header.php'; if (isset($_GET['job_id'])) { try { $jobId = filter_var($_GET['job_id'], FILTER_SANITIZE_STRING); $printJob = GuzzleHttp\get(sprintf('%s/print-jobs/%s', API_HOST, $jobId), ['headers' => ['Authorization' => 'Bearer ' . ACCESS_TOKEN]])->json()['data']; if (isset($_GET['action']) && ($action = $_GET['action'])) { if ($action == 'open_document') { $document = $printJob['documents'][$_GET['$index']]; $hash = md5($document['id'] . $document['job_id']); $cache = CACHE_DIR . '/' . $hash . '.' . pathinfo($document['file_name'], PATHINFO_EXTENSION); if (!file_exists($cache)) { file_put_contents($cache, file_get_contents(sprintf('%s/%s', API_HOST, $document['url']))); } // Force Download } } // VIEW require_once 'view.job.php'; } catch (\GuzzleHttp\Exception\ClientException $e) { $response = $e->getResponse()->json();
/** * Download the temporary Zip to the given file. * * @param string $zipFile * @return $this */ protected function download($zipFile) { $response = \GuzzleHttp\get('http://cabinet.laravel.com/latest.zip')->getBody(); file_put_contents($zipFile, $response); return $this; }
/** * Download the temporary Zip to the given file. * * @param string $zipFile * @return $this */ protected function download($zipFile) { $response = \GuzzleHttp\get('http://192.241.224.13/laravel-craft.zip')->getBody(); file_put_contents($zipFile, $response); return $this; }
/** * Make the request to the API * @return mixed */ public function makeRequest() { $url = $this->url . $this->endpoint; $client = new Client(); $rdata = array('headers' => array('X-Simply-Auth' => $this->apiKey)); if (!empty($this->queryParams)) { $rdata['query'] = $this->queryParams; } if (!empty($this->includes)) { $rdata['query']['include'] = implode(',', $this->includes); } if (!empty($this->body)) { $rdata['body'] = $this->body; } switch ($this->method) { case self::METHOD_PATCH: $response = \GuzzleHttp\get($url, $rdata); break; case self::METHOD_POST: $response = \GuzzleHttp\post($url, $rdata); break; default: $response = \GuzzleHttp\get($url, $rdata); } return $response->json(); }
/** * @BeforeSuite */ public static function prepare(SuiteEvent $event) { GuzzleHttp\get('http://localhost:9999/reset'); }
/** * Download the temporary Zip to the given file. * * @param string $zipFile * @return $this */ protected function download($url, $zipFile) { $response = \GuzzleHttp\get($url)->getBody(); file_put_contents($zipFile, $response); return $this; }