Skip to content

Commit

Permalink
Merge pull request #28 from Schmidt-DevOps/develop
Browse files Browse the repository at this point in the history
Will be v2.0
  • Loading branch information
rene-s authored Dec 8, 2020
2 parents 9193499 + 05f8e6f commit 7236eff
Show file tree
Hide file tree
Showing 39 changed files with 376 additions and 317 deletions.
5 changes: 3 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ALLOW_LIVE_DATA_MANIPULATION_ON_TEST_SERVER=0
TEST_SERVER="https://not-set.example.com"
TEST_SERVER_AUTHORIZATION_TOKEN="not_set"
TEST_LIB_ID="not_set"
TEST_LIB_PASSWORD="not_set"
TEST_LIB_UNENCRYPTED_ID="not_set"
TEST_LIB_ENCRYPTED_ID="not_set"
TEST_LIB_ENCRYPTED_PASSWORD="not_set"
8 changes: 0 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ before_script:
- mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
- echo "memory_limit = -1" > /usr/local/etc/php/conf.d/test.ini

test:php-7.2:
stage: test
image: php:7.2
script:
- bash ./bin/prepare_tests.sh && bash ./bin/run_tests.sh
tags:
- sdo-docker-runner

test:php-7.3:
stage: test
image: php:7.3
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: php
php:
# using major version aliases

- 7.2
- 7.3
- 7.4

Expand Down
33 changes: 0 additions & 33 deletions Jenkinsfile

This file was deleted.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Get in touch now: https://sdo.sh/DevOps/#contact

## How to get Started

To get started with Seafile PHP SDK, you may either set up your own private Seafile server (see [https://www.seafile.com/en/product/private_server/](https://www.seafile.com/en/product/private_server/)) or obtain seacloud.cc account
[https://seacloud.cc](https://seacloud.cc). Because the SDK is in its infancy it's highly recommended to set up a test server or create a test account.
To get started with Seafile PHP SDK, you may either set up your own private Seafile server (see [https://www.seafile.com/en/product/private_server/](https://www.seafile.com/en/product/private_server/)) or obtain a cloud account. Because the SDK is in its infancy it's highly recommended to set up a test server or create a test account.

It's not advisable yet to use your real server/account if you already got one.

Expand Down Expand Up @@ -80,7 +79,7 @@ First, you need to include the API token (see above):
```php
$client = new Client(
[
'base_uri' => 'https://your.seafile-server.com',
'base_uri' => 'https://your-seafile-server.example.com',
'debug' => false,
'headers' => [
'Authorization' => 'Token ' . $token
Expand Down Expand Up @@ -157,14 +156,14 @@ $success = $libraryResource->decrypt($libId, ['query' => ['password' => $passwor
$fileToUpload = '/path/to/file/to/be/uploaded.zip';
$dir = '/'; // directory in the library to save the file in
$response = $fileResource->upload($lib, $fileToUpload, $dir);
$uploadedFileId = json_decode((string)$response->getBody());
$uploadedFileId = (string)$response->getBody();
```

### Update file

```php
$response = $fileResource->update($lib, $newFilename, '/');
$updatedFileId = json_decode((string)$response->getBody());
$updatedFileId = (string)$response->getBody();
```

### Get file details
Expand Down Expand Up @@ -329,7 +328,7 @@ $stack->push(

$client = new Client(
[
'base_uri' => 'https://your.seafile-server.com',
'base_uri' => 'https://your-seafile-server.example.com',
'debug' => true,
'handler' => $stack,
'headers' => [
Expand All @@ -341,19 +340,19 @@ $client = new Client(

## Issues

- Please let me know of issues.
- `File::upload()`: Parameter `$newFilename` actually does not set a new file name when uploading a file (thanks to https://github.com/FlorientR)

## Dependencies

- PHP >=7.0 64 bits
- PHP >=7.3 64 bits
- Guzzle 6

## Seafile Web API Support Matrix

| Resource | Web API Version | Support grade |
| ---------------------- | --------------- | ------------- |
| Account | v2 | ★★★☆ |
| Avatar | v2 | ★★★★ |
| Avatar | v2.1 | ★★★★ |
| Events | v2 | Yet to be done, [contact me](mailto:[email protected]) |
| File Share Link | v2.1 | ★★★☆ |
| Group | v2 | ★☆☆☆ |
Expand All @@ -372,7 +371,7 @@ Tested with:
- ~~Seafile Server 5.1.3 for generic Linux/Debian Wheezy~~
- ~~Seafile Server 5.1.4 for generic Linux/Ubuntu Xenial~~
- ~~Seafile Server 6.0.3 for generic Linux/Ubuntu Xenial~~
- Seafile Server 6.3.4 for generic Linux/Ubuntu Xenial
- Seafile Server 7.1.4 for Ubuntu 20.04 LTS

## Contributing

Expand Down Expand Up @@ -401,4 +400,4 @@ There are two types of tests:

## License

[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2017 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG
[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2020 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG
11 changes: 9 additions & 2 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# run tests locally or on Jenkins
# run tests locally or in CI/CD pipeline

mkdir -p ./build/logs

Expand All @@ -13,7 +13,14 @@ if [ ! -f $file ] || [ $size -eq 0 ]; then
fi

if [ -f $file ]; then
./vendor/bin/phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=./build/phpcs.xml -v ./src ./test --ignore=./test/bootstrap.php --ignore=./test/ui --standard=$file
./vendor/bin/phpcs \
--report=checkstyle \
--report-file=./build/logs/checkstyle.xml \
--standard=./build/phpcs.xml \
-v ./src ./test \
--ignore=./test/bootstrap.php \
--ignore=./test/ui \
--standard=$file
fi

./vendor/bin/phpcpd ./src ./test --exclude=./test/ui
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"encrypted"
],
"require": {
"php": ">=7.2",
"guzzlehttp/guzzle": "~6.0",
"php": ">=7.3",
"guzzlehttp/guzzle": "~6.0|~7.0",
"nabil1337/case-helper": "~0.1",
"ext-json": "*",
"sdo/bitmask": "^1.0"
Expand Down
7 changes: 4 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"
timeoutForSmallTests="1"
timeoutForMediumTests="3"
timeoutForLargeTests="9"
Expand All @@ -20,8 +20,9 @@
<env name="ALLOW_LIVE_DATA_MANIPULATION_ON_TEST_SERVER" value="0" force="false"/><!-- 1=enabled -->
<env name="TEST_SERVER_AUTHORIZATION_TOKEN" value="not_set" force="false"/><!-- see README.md-->
<env name="TEST_SERVER" value="https://not-set.example.com" force="false"/>
<env name="TEST_LIB_ID" value="not_set" force="false"/>
<env name="TEST_LIB_PASSWORD" value="not_set" force="false"/>
<env name="TEST_LIB_UNENCRYPTED_ID" value="not_set" force="false"/>
<env name="TEST_LIB_ENCRYPTED_ID" value="not_set" force="false"/>
<env name="TEST_LIB_ENCRYPTED_PASSWORD" value="not_set" force="false"/>
<env name="GUZZLE_DEBUG_TO_STDOUT" value="0" force="false"/>
</php>
<testsuites>
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ public function __construct(array $config = [])
* @param array $args Request args
* @return ResponseInterface
*/
public function get($uri, $args): ResponseInterface
public function get($uri, array $options = []): ResponseInterface
{
return parent::get($uri, $args);
return parent::get($uri, $options);
}

/**
* @param string|UriInterface $uri URI for request
* @param array $args Request args
* @return ResponseInterface
*/
public function put($uri, $args): ResponseInterface
public function put($uri, array $options = []): ResponseInterface
{
return parent::put($uri, $args);
return parent::put($uri, $options);
}

/**
* @param string|UriInterface $uri URI for request
* @param array $args Request args
* @return ResponseInterface
*/
public function delete($uri, $args): ResponseInterface
public function delete($uri, array $options = []): ResponseInterface
{
return parent::delete($uri, $args);
return parent::delete($uri, $options);
}
}
14 changes: 8 additions & 6 deletions src/Resource/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
class Account extends Resource
{
const API_VERSION = '2';

/**
* List accounts
*
Expand All @@ -28,7 +30,7 @@ class Account extends Resource
*/
public function getAll(): array
{
$response = $this->client->request('GET', $this->getApiBaseUrl(). '/accounts/');
$response = $this->client->request('GET', $this->getApiBaseUrl() . '/accounts/');

$json = json_decode($response->getBody());

Expand Down Expand Up @@ -56,7 +58,7 @@ public function getByEmail(string $emailAddress): AccountType
$response = $this->client->request(
'GET',
// $emailAddress must not be urlencoded
$this->getApiBaseUrl(). '/accounts/' . $emailAddress . '/'
$this->getApiBaseUrl() . '/accounts/' . $emailAddress . '/'
);

$json = json_decode($response->getBody());
Expand All @@ -76,7 +78,7 @@ public function getInfo(string $emailAddress): TypeInterface
{
$response = $this->client->request(
'GET',
$this->getApiBaseUrl(). '/accounts/' . $emailAddress . '/'
$this->getApiBaseUrl() . '/accounts/' . $emailAddress . '/'
);

$json = json_decode($response->getBody());
Expand Down Expand Up @@ -113,7 +115,7 @@ public function create(AccountType $accountType): bool
$response = $this->client->put(
$uri,
[
'headers' => ['Accept' => 'application/json; charset=utf-8'],
'headers' => ['Accept' => 'application/json; charset=utf-8'],
'multipart' => $accountType->toArray(Type::ARRAY_MULTI_PART),
]
);
Expand Down Expand Up @@ -151,7 +153,7 @@ public function update(AccountType $accountType): bool
$response = $this->client->put(
$uri,
[
'headers' => ['Accept' => 'application/json; charset=utf-8'],
'headers' => ['Accept' => 'application/json; charset=utf-8'],
'multipart' => $accountType->toArray(Type::ARRAY_MULTI_PART),
]
);
Expand All @@ -165,7 +167,7 @@ public function update(AccountType $accountType): bool
* Requires admin permissions
*
* @param AccountType $fromAccountType AccountType instance to update from
* @param AccountType $toAccountType AccountType instance to update to
* @param AccountType $toAccountType AccountType instance to update to
*
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function getAvatar(Type $type, int $size)
}

$response = $this->client->get(
$this->getApiBaseUrl(). '/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/',
$this->getApiBaseUrl() . '/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/',
[]
);

Expand Down
30 changes: 16 additions & 14 deletions src/Resource/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
class Directory extends Resource
{
const API_VERSION = '2';

/**
* Get all items of a directory in a library
*
* @param LibraryType $library Library type
* @param string $dir Directory path
* @param string $dir Directory path
*
* @return DirectoryItem[]
* @throws Exception
Expand Down Expand Up @@ -61,9 +63,9 @@ public function getAll(LibraryType $library, string $dir = '/')
/**
* Check if $dirName exists within $parentDir
*
* @param LibraryType $library Library instance
* @param string $dirItemName DirectoryItem name
* @param string $parentDir Parent directory
* @param LibraryType $library Library instance
* @param string $dirItemName DirectoryItem name
* @param string $parentDir Parent directory
*
* @return bool
* @throws Exception
Expand Down Expand Up @@ -135,10 +137,10 @@ public function create(LibraryType $library, string $dirName, string $parentDir
'POST',
$uri,
[
'headers' => ['Accept' => 'application/json'],
'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
'name' => 'operation',
'name' => 'operation',
'contents' => 'mkdir',
],
],
Expand All @@ -151,8 +153,8 @@ public function create(LibraryType $library, string $dirName, string $parentDir
/**
* Remove a directory
*
* @param LibraryType $library Library instance
* @param string $directoryPath Directory path
* @param LibraryType $library Library instance
* @param string $directoryPath Directory path
*
* @return bool
*/
Expand Down Expand Up @@ -184,9 +186,9 @@ public function remove(LibraryType $library, string $directoryPath)
/**
* Rename a directory
*
* @param LibraryType $library Library object
* @param string $directoryPath Directory path
* @param string $newDirectoryName New directory name
* @param LibraryType $library Library object
* @param string $directoryPath Directory path
* @param string $newDirectoryName New directory name
*
* @return bool
*/
Expand All @@ -208,14 +210,14 @@ public function rename(LibraryType $library, string $directoryPath, string $newD
'POST',
$uri,
[
'headers' => ['Accept' => 'application/json'],
'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
'name' => 'operation',
'name' => 'operation',
'contents' => 'rename',
],
[
'name' => 'newname',
'name' => 'newname',
'contents' => $newDirectoryName,
],
],
Expand Down
Loading

0 comments on commit 7236eff

Please sign in to comment.