/** * getById() * * @return void */ public function testGetById() { $libraryResource = new Library($this->getMockedClient(new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../../assets/LibraryTest_getById.json')))); self::assertInstanceOf('Seafile\\Client\\Type\\Library', $libraryResource->getById('some_id')); }
$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'); } else { $logger->log(Logger::INFO, "#################### Library is not encrypted: " . $libId); } // list library $logger->log(Logger::INFO, "#################### Listing items of that library..."); $items = $directoryResource->getAll($lib); $logger->log(Logger::INFO, sprintf("\nGot %d items", count($items))); foreach ($items as $item) { printf("%s: %s (%d bytes)\n\n", $item->type, $item->name, $item->size); }
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); $starredFileResource = new StarredFile($client); // get all starred files $logger->log(Logger::INFO, "#################### Getting all starred files"); $dirItems = $starredFileResource->getAll(); if (!empty($dirItems)) { foreach ($dirItems as $dirItem) { var_dump($dirItem); } $logger->log(Logger::INFO, "#################### Unstarring files..."); foreach ($dirItems as $dirItem) { $lib = $libraryResource->getById($dirItem->repo); $starredFileResource->unstar($lib, $dirItem); } $logger->log(Logger::INFO, "#################### Sleeping 10s before starring them again..."); sleep(10); foreach ($dirItems as $dirItem) { $lib = $libraryResource->getById($dirItem->repo); $starredFileResource->star($lib, $dirItem); } } else { $logger->log(Logger::DEBUG, "#################### No starred files found."); } print PHP_EOL . 'Done' . PHP_EOL;