Пример #1
0
 *   "testLibPassword": "******"
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
    throw new Exception($tokenFile . ' is not readable or does not exist.');
}
if (!is_readable($cfgFile)) {
    throw new Exception($cfgFile . ' is not readable or does not exist.');
}
$token = json_decode(file_get_contents($tokenFile));
$cfg = json_decode(file_get_contents($cfgFile));
$client = new Client(['base_uri' => $cfg->baseUri, 'debug' => true, 'handler' => $stack, 'headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Token ' . $token->token]]);
$libraryResource = new Library($client);
$directoryResource = new Directory($client);
$fileResource = new File($client);
// get all libraries available
$logger->log(Logger::INFO, "#################### Getting all libraries");
$libs = $libraryResource->getAll();
foreach ($libs as $lib) {
    printf("Name: %s, ID: %s, is encrypted: %s\n", $lib->name, $lib->id, $lib->encrypted ? 'YES' : 'NO');
}
$libId = $cfg->testLibId;
// get specific library
$logger->log(Logger::INFO, "#################### Getting lib with ID " . $libId);
$lib = $libraryResource->getById($libId);
$lib->password = $cfg->testLibPassword;
// library is encrypted and thus we provide a password
if ($lib->encrypted) {
    $success = $libraryResource->decrypt($libId, ['query' => ['password' => $cfg->testLibPassword]]);
    $logger->log(Logger::INFO, "#################### Decrypting library " . $libId . ' was ' . ($success ? '' : 'un') . 'successful');
Пример #2
0
 /**
  * test getFileDetail()
  *
  * @return void
  */
 public function testGetFileDetail()
 {
     $fileResource = new File($this->getMockedClient(new Response(200, ['Content-Type' => 'application/json'], '{"id": "cd8ec413c72388149911c84b046642da2ca4b935", "mtime": 1444760758, "type": "file", ' . '"name": "Seafile-PHP-SDK_Test_Upload_jt64pq.txt", "size": 32}')));
     $response = $fileResource->getFileDetail(new Library(), '/Seafile-PHP-SDK_Test_Upload_jt64pq.txt');
     $this->assertInstanceOf('Seafile\\Type\\DirectoryItem', $response);
     $this->assertInstanceOf('DateTime', $response->mtime);
     $this->assertSame('Seafile-PHP-SDK_Test_Upload_jt64pq.txt', $response->name);
     $this->assertSame('file', $response->type);
     $this->assertequals('32', $response->size);
 }