Skip to content

Commit

Permalink
Merge pull request #9 from waifuvault/1.0.5-dev
Browse files Browse the repository at this point in the history
chore: moved the password field from URI param to body param
  • Loading branch information
ernestmarcinko authored May 13, 2024
2 parents e494176 + 25a08ec commit d5fc5ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
26 changes: 10 additions & 16 deletions src/WaifuApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@
*
* @link https://waifuvault.moe/
*
* @phpstan-type FileUpload array{
* file: string,
* filename?: string
* }
* @phpstan-type FileContentUpload array{
* file_contents: string,
* filename: string
* }
* @phpstan-type UrlUpload array{
* url: string
* }
*
* @phpstan-type uploadFileArg array{
* file?: string,
* url?: string,
* filename?: string,
* file_contents?: string,
* expires?:string,
* hide_filename?:bool,
* password?:string,
* one_time_download?:bool
* }&(FileUpload|FileContentUpload|UrlUpload)
* }
*
* @phpstan-type modifyFileArg array{
* token: string,
Expand Down Expand Up @@ -69,7 +61,6 @@ function ($v, $k) {
return in_array($k, array(
'expires',
'hide_filename',
'password',
'one_time_download')) && !is_null($v); // @phpstan-ignore-line
},
ARRAY_FILTER_USE_BOTH
Expand All @@ -79,7 +70,7 @@ function ($v, $k) {
* http_build_query will convert them to 1 or 0 integers, which throws an API Exception
*/
$params = http_build_query(array_map(
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v, // @phpstan-ignore-line
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v,
$params
));
if ($params !== '') {
Expand All @@ -99,13 +90,16 @@ function ($v, $k) {
}
$post_fields['file'] = new CURLStringFile($data, $file_name);
} elseif (isset($args['file_contents'])) {
if (!isset($args['filename']) || $args['filename'] === '') { // @phpstan-ignore-line
if (!isset($args['filename']) || $args['filename'] === '') {
throw new Exception('File name is missing.');
}
$post_fields['file'] = new CURLStringFile($args['file_contents'], $args['filename']);
} else {
throw new Exception('Please provide a url, file or file_contents.');
}
if (isset($args['password']) && $args['password'] !== '') {
$post_fields['password'] = $args['password'];
}
return $this->requestHandler->make(
RequestMethods::PUT,
$url,
Expand Down
3 changes: 1 addition & 2 deletions tests/WaifuTests/WaifuApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\Attributes\UsesClass;

#[CoversClass(WaifuApi::class)]
#[UsesClass(GlobalMock::class)]
class WaifuApiTest extends TestCase {
private WaifuApi $waifu;
private WaifuResponse $waifuResponse;
Expand Down Expand Up @@ -54,7 +53,7 @@ public function testUploadFileExceptions(): void {
foreach ($bad_args as $args) {
try {
// Upload via URL
$this->waifu->uploadFile($args); // @phpstan-ignore-line
$this->waifu->uploadFile($args);
} catch (Exception $e) {
$this->assertSame(Exception::class, get_class($e));
$this->addToAssertionCount(1);
Expand Down

0 comments on commit d5fc5ff

Please sign in to comment.