PHP code example of ernestmarcinko / waifuvault-php-api

1. Go to this page and download the library: Download ernestmarcinko/waifuvault-php-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ernestmarcinko / waifuvault-php-api example snippets


use ErnestMarcinko\WaifuVault\WaifuApi;

// WaifuResponse object:

ErnestMarcinko\WaifuVault\WaifuResponse (4) {
  ["token"]=> string(36) "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
  ["url"]=> string(74) "https://waifuvault.moe/f/{timestamp}/{filename}.{file_ext}"
  ["retentionPeriod"]=> string(39) "334 days 20 hours 16 minutes 23 seconds",
  ["options"] ErnestMarcinko\WaifuVault\WaifuResponseOptions (4) {
	["hideFilename"]=> bool(false),
	["oneTimeDownload"]=> bool(false),
	["protected"]=> bool(false),
  }
}

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->uploadFile(array(
	'url' =>   'https://waifuvault.moe/assets/custom/images/08.png',
));
var_dump($response);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->uploadFile(array(
	'file' =>   __DIR__ . '/image.jpg',
));
var_dump($response);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->uploadFile(array(
	'file_contents' => file_get_contents(__DIR__ . '/image.jpg'),
	'filename' => 'image.jpg',
));
var_dump($response);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->getFileInfo('someToken');
var_dump($response);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->getFileInfo('someToken');
var_dump($response->retentionPeriod); // 328 days 18 hours 51 minutes 31 seconds

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->deleteEntry('someToken');

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->uploadFile(array(
	'url' => 'https://waifuvault.moe/assets/custom/images/08.png',
	'password' => 'epic'
));
$contents = $waifu->getFile(array(
	'token' => $response->token,
	'password' => 'epic'
));
var_dump($contents);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$contents = $waifu->getFile(array(
	'filename' => '/1710111505084/08.png'
));
var_dump($contents);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->modifyEntry(array(
	'token' => 'token',
	'password' => 'apple'
));
var_dump($response->protected);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->modifyEntry(array(
	'token' => 'token',
	'password' => 'newPass'
	'previousPassword' => 'apple'
));
var_dump($response->protected);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->modifyEntry(array(
	'token' => 'token',
	'customExpiry' => "1d"
));
var_dump($response->retentionPeriod);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();
$response = $waifu->modifyEntry(array(
	'token' => 'token',
	'password' => ''
	'previousPassword' => 'apple'
));
var_dump($response->protected);

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi();

// which is equivalent to:

$waifu = new WaifuApi( new WaifuRequestHandler() );

use ErnestMarcinko\WaifuVault\RequestMethods;
use ErnestMarcinko\WaifuVault\RequestHandler;

class MyCustomWaifuRequestHandler implements RequestHandler {
	public function make(
		RequestMethods $method,
		string $endpoint,
		array|null $header = null,
		array|string|bool|null $post_fields = null
	): static {
		// do your thing here
		return $this;
	}

	public function getWaifu(): WaifuResponse {
		return new WaifuResponse();
	}
	
	public function getTrue(): true {
		return true;
	}

	public function getRaw(): string {
		return 'raw file content';
	}
}

use ErnestMarcinko\WaifuVault\WaifuApi;

$waifu = new WaifuApi( new MyCustomWaifuRequestHandler() );