Exemple #1
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) {
     }
 }
// create object istance for Api.
$api = new Uploadcare_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
 *  - file_id
 *  - original_filename
 *  - removed
 *  - mime_type