request() public method

Run raw request to REST.
public request ( string $method, string $path, array $data = [], array $headers = [] ) : object
$method string Request method: GET, POST, HEAD, OPTIONS, PUT, etc
$path string Path to request
$data array Array of data to send.
$headers array Additional headers.
return object
示例#1
0
 /**
  * Test setting File with raw data
  */
 public function testFileFromJSON()
 {
     $result = $this->api->request('GET', '/files/');
     $file_raw = (array) $result->results[0];
     $file = new File($file_raw['uuid'], $this->api);
     $this->assertEquals($file_raw['uuid'], $file->data['uuid']);
     $file = new File($file_raw['uuid'], $this->api, $file_raw);
     $this->assertEquals($file_raw['uuid'], $file->data['uuid']);
 }
示例#2
0
 /**
  * Test setting File with raw data
  */
 public function testFileFromJSON()
 {
     $api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
     $result = $api->request('GET', '/files/');
     $file_raw = (array) $result->results[0];
     $file = new File($file_raw['uuid'], $api);
     $this->assertEquals($file_raw['uuid'], $file->data['uuid']);
     $file = new File($file_raw['uuid'], $api, $file_raw);
     $this->assertEquals($file_raw['uuid'], $file->data['uuid']);
 }
示例#3
0
// create object instance for Api.
$api = new Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
/**
 * Let's start with widgets.
 * You can get widget url by using this:
* */
print $api->widget->getScriptSrc() . "\n";
/**
 * You can just use method below to get all the code to insert widget
 */
print $api->widget->getScriptTag() . "\n";
/**
 * Ok, lets do some requests. This is request to index (http://api.uploadcare.com).
 * This will return an stdClass with information about urls you can request.
 */
$data = $api->request('GET', '/');
/**
 * Ok, now lets get file list.
 * This request will return stdClass with all files uploaded and some information about files.
 * Each files has:
 *  - size
 *  - upload_date
 *  - last_keep_claim
 *  - on_s3
 *  - made_public
 *  - url
 *  - is_image
 *  - uuid
 *  - original_filename
 *  - removed
 *  - mime_type
示例#4
0
 /**
  * Test request to "files"
  */
 public function testRequestsFiles()
 {
     $api = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
     // this are request to https://api.uploadcare.com/files/ url.
     // no exceptions should be thrown
     try {
         $result = $api->request('GET', '/files/');
         $api->request('HEAD', '/files/');
         $api->request('OPTIONS', '/files/');
     } catch (Exception $e) {
         $this->fail('An unexpected exception thrown');
     }
     // let's check we have an array of raw file data
     $this->assertTrue(is_array($result->results));
     $this->assertGreaterThan(0, count($result->results));
     $file_raw = (array) $result->results[0];
     $this->assertArrayHasKey('size', $file_raw);
     $this->assertArrayHasKey('upload_date', $file_raw);
     $this->assertArrayHasKey('is_image', $file_raw);
     $this->assertArrayHasKey('file_id', $file_raw);
     $this->assertArrayHasKey('original_filename', $file_raw);
     $this->assertArrayHasKey('mime_type', $file_raw);
     // this are requests to https://api.uploadcare.com/files/ url.
     // But this requests are now allowed but this url and we must have an exception
     try {
         $api->request('POST', '/files/');
         $this->fail('We must get an exception but everything worked fine!');
     } catch (Exception $e) {
     }
     try {
         $api->request('PUT', '/files/');
         $this->fail('We must get an exception but everything worked fine!');
     } catch (Exception $e) {
     }
     try {
         $api->request('DELETE', '/files/');
         $this->fail('We must get an exception but everything worked fine!');
     } catch (Exception $e) {
     }
 }