public function existsResource($uri) { $client = new Client(); $request = $client->options($this->getServiceUrl($uri), array("User-Agent" => "Marmotta Client Library (PHP)")); // set authentication if given in configuration if (!_isset($this->config->getUsername())) { $request->setAuth($this->config->getUsername(), $this->config->getPassword()); } $response = $request->send(); if ($response->hasHeader("Access-Control-Allow-Methods")) { if ($response->getHeader("Access-Control-Allow-Methods") == "POST") { return False; } else { if (strpos($response->getHeader("Access-Control-Allow-Methods"), "GET")) { return True; } else { return False; } } } else { return False; } }
public function testUriArrayAllowsCustomTemplateVariables() { $client = new Client(); $vars = array('var' => 'hi'); $this->assertEquals('/hi', (string) $client->createRequest('GET', array('/{var}', $vars))->getUrl()); $this->assertEquals('/hi', (string) $client->get(array('/{var}', $vars))->getUrl()); $this->assertEquals('/hi', (string) $client->put(array('/{var}', $vars))->getUrl()); $this->assertEquals('/hi', (string) $client->post(array('/{var}', $vars))->getUrl()); $this->assertEquals('/hi', (string) $client->head(array('/{var}', $vars))->getUrl()); $this->assertEquals('/hi', (string) $client->options(array('/{var}', $vars))->getUrl()); }
require '../vendor/autoload.php'; use Guzzle\Http\Client; use Faker\Factory; $faker = Factory::create(); $client = new Client('http://localhost/comphppuebla/guzzle/api'); $acceptJson = ['Accept' => 'application/json']; $acceptXml = ['Accept' => 'application/xml']; $request = $client->get('contacts/1', $acceptXml); $response = $request->send(); echo "\nGET /contacts/1\n"; echo $response->getBody(); $contact = ['name' => $faker->firstName, 'last_name' => $faker->lastName]; $request = $client->post('contacts', $acceptJson, http_build_query($contact)); $response = $request->send(); echo "\n\nPOST /contacts\n"; echo $response->getBody(); $newName = $faker->firstName; $contact = ['name' => $newName]; $request = $client->put('contacts/2', $acceptXml, http_build_query($contact)); $response = $request->send(); echo "\n\nPUT /contacts/2 (New name is {$newName})\n"; echo $response->getBody(); echo "Last modified time: {$response->getLastModified()}"; $request = $client->delete('contacts/3'); $response = $request->send(); echo "\n\nDELETE /contacts/3\n"; echo "Status code: {$response->getStatusCode()}"; $request = $client->options('contacts/4'); $response = $request->send(); echo "\n\nOPTIONS /contacts/4\n"; echo "Valid methods are: {$response->getAllow()}";