diff --git a/README.md b/README.md index cf14a25..29133bf 100644 --- a/README.md +++ b/README.md @@ -338,17 +338,17 @@ $client = new Client( | Resource | Support grade | | ---------------------- | ------------- | -| Account | :+1: (except migrate) | -| Starred Files | contribute! | -| Group | contribute! | -| File Share Link | partial | -| Library/Library | partial | -| Library/File | partial | -| Library/Directory | partial | -| Library/Multiple Files | :+1: | -| Avatar | :+1: | -| Events | contribute! | -| Organization | contribute! | +| Account | :large_blue_circle::large_blue_circle::large_blue_circle::white_circle: | +| Starred Files | :white_circle::white_circle::white_circle::white_circle: | +| Group | :large_blue_circle::white_circle::white_circle::white_circle: | +| File Share Link | :large_blue_circle::large_blue_circle::white_circle::white_circle: | +| Library/Library | :large_blue_circle::large_blue_circle::white_circle::white_circle: | +| Library/File | :large_blue_circle::large_blue_circle::white_circle::white_circle: | +| Library/Directory | :large_blue_circle::large_blue_circle::white_circle::white_circle: | +| Library/Multiple Files | :large_blue_circle::large_blue_circle::large_blue_circle::large_blue_circle: | +| Avatar | :large_blue_circle::large_blue_circle::large_blue_circle::large_blue_circle: | +| Events | :white_circle::white_circle::white_circle::white_circle: | +| Organization | :white_circle::white_circle::white_circle::white_circle: | ## Seafile server compatibility diff --git a/bin/examples/group.php b/bin/examples/group.php new file mode 100755 index 0000000..ac06255 --- /dev/null +++ b/bin/examples/group.php @@ -0,0 +1,66 @@ +push( + Middleware::log( + $logger, + new MessageFormatter("{hostname} {req_header_Authorization} - {req_header_User-Agent} - [{date_common_log}] \"{method} {host}{target} HTTP/{version}\" {code} {res_header_Content-Length} req_body: {req_body} response_body: {res_body}") + ) +); + +/** + * Example: + * {"token": "your_token"} + */ +$tokenFile = getenv("HOME") . "/.seafile-php-sdk/api-token.json"; +$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 + ] + ] +); + +$groupResource = new Group($client); +$logger->log(Logger::INFO, "#################### Get all groups "); + +$groups = $groupResource->getAll(); + +foreach ($groups as $group) { + $logger->log(Logger::INFO, "#################### " . sprintf("Group name: %s", $group->name)); +} + +print(PHP_EOL . 'Done' . PHP_EOL); diff --git a/lib/Resource/Group.php b/lib/Resource/Group.php new file mode 100644 index 0000000..9efd6da --- /dev/null +++ b/lib/Resource/Group.php @@ -0,0 +1,41 @@ + + * @copyright 2015 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG + * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/rene-s/seafile-php-sdk + */ +class Group extends AbstractResource +{ + + /** + * List groups + * + * @return GroupType[] + */ + public function getAll() + { + $response = $this->client->request('GET', $this->client->getConfig('base_uri') . '/groups/'); + + $json = json_decode($response->getBody()); + + $groupCollection = []; + + foreach ($json->groups as $group) { + $groupCollection[] = (new GroupType)->fromJson($group); + } + + return $groupCollection; + } +} diff --git a/test/assets/GroupTest_getAll.json b/test/assets/GroupTest_getAll.json new file mode 100644 index 0000000..880a343 --- /dev/null +++ b/test/assets/GroupTest_getAll.json @@ -0,0 +1,21 @@ +{ + "replynum": 0, + "groups": [ + { + "ctime": 1452804381467425, + "creator": "ay@example.com", + "msgnum": 0, + "mtime": 0, + "id": 1, + "name": "A" + }, + { + "ctime": 1452804387552160, + "creator": "bee@example.com", + "msgnum": 0, + "mtime": 0, + "id": 2, + "name": "B" + } + ] +} \ No newline at end of file diff --git a/test/unit/Resource/DirectoryTest.php b/test/unit/Resource/DirectoryTest.php index 4558152..ae8a653 100644 --- a/test/unit/Resource/DirectoryTest.php +++ b/test/unit/Resource/DirectoryTest.php @@ -22,7 +22,7 @@ class DirectoryTest extends TestCase { /** - * getAll() + * Test getAll() * * @return void */ @@ -46,7 +46,7 @@ public function testGetAll() } /** - * getAll() with directory path + * Test getAll() with directory path * * @return void */ diff --git a/test/unit/Resource/GroupTest.php b/test/unit/Resource/GroupTest.php new file mode 100644 index 0000000..ebe62d5 --- /dev/null +++ b/test/unit/Resource/GroupTest.php @@ -0,0 +1,46 @@ + + * @copyright 2015 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG + * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/rene-s/seafile-php-sdk + */ +class GroupTest extends TestCase +{ + /** + * Test getAll() + * + * @return void + */ + public function testGetAll() + { + $groupResource = new Group($this->getMockedClient( + new Response( + 200, + ['Content-Type' => 'application/json'], + file_get_contents(__DIR__ . '/../../assets/GroupTest_getAll.json') + ) + )); + + $groups = $groupResource->getAll(); + + $this->assertInternalType('array', $groups); + + foreach ($groups as $group) { + $this->assertInstanceOf('Seafile\Client\Type\Group', $group); + } + } +} diff --git a/test/unit/Resource/LibraryTest.php b/test/unit/Resource/LibraryTest.php index 463d6e1..effe443 100644 --- a/test/unit/Resource/LibraryTest.php +++ b/test/unit/Resource/LibraryTest.php @@ -22,7 +22,7 @@ class LibraryTest extends TestCase { /** - * getAll() + * Test getAll() * * @return void */