mirror of
https://github.com/danog/tg-file-decoder.git
synced 2024-11-30 04:38:58 +01:00
Add docs
This commit is contained in:
parent
76a91ab437
commit
b7d4a2e10f
1
.gitignore
vendored
1
.gitignore
vendored
@ -124,3 +124,4 @@ coverage
|
||||
tempConv
|
||||
extracted.json
|
||||
tools
|
||||
docs
|
||||
|
@ -14,7 +14,7 @@
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8",
|
||||
"phpunit/phpunit": "^8|^6",
|
||||
"amphp/php-cs-fixer-config": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -240,6 +240,15 @@ class FileId
|
||||
{
|
||||
return UniqueFileId::fromFileId($this);
|
||||
}
|
||||
/**
|
||||
* Get unique bot API file ID from file ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUniqueBotAPI(): string
|
||||
{
|
||||
return UniqueFileId::fromFileId($this)->getUniqueBotAPI();
|
||||
}
|
||||
/**
|
||||
* Get bot API file ID.
|
||||
*
|
||||
@ -247,7 +256,7 @@ class FileId
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->toBotAPI();
|
||||
return $this->getBotAPI();
|
||||
}
|
||||
/**
|
||||
* Get bot API file ID version.
|
||||
|
41
src/type.php
41
src/type.php
@ -37,21 +37,60 @@ const PHOTO = 2;
|
||||
*/
|
||||
const VOICE = 3;
|
||||
/**
|
||||
* VIdeo messages.
|
||||
* Video.
|
||||
*/
|
||||
const VIDEO = 4;
|
||||
/**
|
||||
* Document
|
||||
*/
|
||||
const DOCUMENT = 5;
|
||||
/**
|
||||
* Secret chat document
|
||||
*/
|
||||
const ENCRYPTED = 6;
|
||||
/**
|
||||
* Temporary document
|
||||
*/
|
||||
const TEMP = 7;
|
||||
/**
|
||||
* Sticker
|
||||
*/
|
||||
const STICKER = 8;
|
||||
/**
|
||||
* Music
|
||||
*/
|
||||
const AUDIO = 9;
|
||||
/**
|
||||
* GIF
|
||||
*/
|
||||
const ANIMATION = 10;
|
||||
/**
|
||||
* Encrypted thumbnail
|
||||
*/
|
||||
const ENCRYPTED_THUMBNAIL = 11;
|
||||
/**
|
||||
* Wallpaper
|
||||
*/
|
||||
const WALLPAPER = 12;
|
||||
/**
|
||||
* Round video
|
||||
*/
|
||||
const VIDEO_NOTE = 13;
|
||||
/**
|
||||
* Passport raw file
|
||||
*/
|
||||
const SECURE_RAW = 14;
|
||||
/**
|
||||
* Passport file
|
||||
*/
|
||||
const SECURE = 15;
|
||||
/**
|
||||
* Background
|
||||
*/
|
||||
const BACKGROUND = 16;
|
||||
/**
|
||||
* Size
|
||||
*/
|
||||
const SIZE = 17;
|
||||
const NONE = 18;
|
||||
|
||||
|
@ -10,9 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
use const danog\Decoder\FULL_UNIQUE_MAP;
|
||||
use const danog\Decoder\TYPES_IDS;
|
||||
|
||||
|
||||
\define('MULTIPART_BOUNDARY', '--------------------------'.\microtime(true));
|
||||
|
||||
class IntegrationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
@ -23,6 +20,7 @@ class IntegrationTest extends TestCase
|
||||
*/
|
||||
public function testAll(string $type, string $fileIdStr, string $uniqueFileIdStr)
|
||||
{
|
||||
var_dump($fileIdStr, $uniqueFileIdStr);
|
||||
$fileId = FileId::fromBotAPI($fileIdStr);
|
||||
$this->assertSame($type, $fileId->getTypeName());
|
||||
|
||||
@ -35,11 +33,23 @@ class IntegrationTest extends TestCase
|
||||
$this->assertSame($uniqueFileIdStr, $fileId->getUnique()->getUniqueBotAPI());
|
||||
}
|
||||
|
||||
public function provideFileIdsAndType(): array
|
||||
public function provideFileIdsAndType(): \Generator
|
||||
{
|
||||
$result = [];
|
||||
$dest = \getenv('DEST');
|
||||
$token = \getenv('TOKEN');
|
||||
foreach ($this->provideChats() as $chat) {
|
||||
$result = \json_decode(\file_get_contents("https://api.telegram.org/bot$token/getChat?chat_id=$chat"), true)['result']['photo'];
|
||||
yield [
|
||||
'profile_photo',
|
||||
$result['small_file_id'],
|
||||
$result['small_file_unique_id'],
|
||||
];
|
||||
yield [
|
||||
'profile_photo',
|
||||
$result['big_file_id'],
|
||||
$result['big_file_unique_id'],
|
||||
];
|
||||
}
|
||||
foreach ($this->provideUrls() as $type => $url) {
|
||||
if ($type === 'video_note') {
|
||||
\copy($url, \basename($url));
|
||||
@ -62,13 +72,13 @@ class IntegrationTest extends TestCase
|
||||
$botResult = [$botResult];
|
||||
}
|
||||
foreach ($botResult as $subResult) {
|
||||
$result []= [
|
||||
yield [
|
||||
$type,
|
||||
$subResult['file_id'],
|
||||
$subResult['file_unique_id']
|
||||
];
|
||||
if (isset($subResult['thumb'])) {
|
||||
$result []= [
|
||||
yield [
|
||||
'thumbnail',
|
||||
$subResult['thumb']['file_id'],
|
||||
$subResult['thumb']['file_unique_id']
|
||||
@ -78,6 +88,10 @@ class IntegrationTest extends TestCase
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function provideChats(): array
|
||||
{
|
||||
return [\getenv('DEST'), '@MadelineProto'];
|
||||
}
|
||||
public function provideUrls(): array
|
||||
{
|
||||
return [
|
||||
|
Loading…
Reference in New Issue
Block a user