-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rene Schmidt
committed
Jan 14, 2016
1 parent
fb8bd5f
commit 97230d2
Showing
7 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* Attention: This example script will modify the test library! Do not run this script | ||
* unless you are prepared for that. | ||
*/ | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use Seafile\Client\Resource\Group; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Middleware; | ||
use GuzzleHttp\MessageFormatter; | ||
use Monolog\Logger; | ||
use Seafile\Client\Http\Client; | ||
|
||
$logger = new Logger('Logger'); | ||
|
||
$stack = HandlerStack::create(); | ||
$stack->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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Seafile\Client\Resource; | ||
|
||
use \Seafile\Client\Type\Group as GroupType; | ||
|
||
/** | ||
* Handles everything regarding Seafile groups. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category API | ||
* @package Seafile\Resource | ||
* @author Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG <[email protected]> | ||
* @copyright 2015 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG <[email protected]> | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"replynum": 0, | ||
"groups": [ | ||
{ | ||
"ctime": 1452804381467425, | ||
"creator": "[email protected]", | ||
"msgnum": 0, | ||
"mtime": 0, | ||
"id": 1, | ||
"name": "A" | ||
}, | ||
{ | ||
"ctime": 1452804387552160, | ||
"creator": "[email protected]", | ||
"msgnum": 0, | ||
"mtime": 0, | ||
"id": 2, | ||
"name": "B" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Seafile\Client\Tests\Resource; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Seafile\Client\Resource\Group; | ||
use Seafile\Client\Tests\TestCase; | ||
|
||
/** | ||
* Group resource test | ||
* | ||
* PHP version 5 | ||
* | ||
* @category API | ||
* @package Seafile\Resource | ||
* @author Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG <[email protected]> | ||
* @copyright 2015 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG <[email protected]> | ||
* @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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
class LibraryTest extends TestCase | ||
{ | ||
/** | ||
* getAll() | ||
* Test getAll() | ||
* | ||
* @return void | ||
*/ | ||
|