Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/labi-le/vk-utils
A set of utilities for working with vk api!
https://github.com/labi-le/vk-utils
php vk vkapi
Last synced: 2 months ago
JSON representation
A set of utilities for working with vk api!
- Host: GitHub
- URL: https://github.com/labi-le/vk-utils
- Owner: labi-le
- License: gpl-3.0
- Created: 2021-09-19T11:10:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T19:27:17.000Z (8 months ago)
- Last Synced: 2024-10-01T10:02:34.148Z (3 months ago)
- Topics: php, vk, vkapi
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vk-utils
[![GitHub license](https://img.shields.io/badge/license-BSD-green.svg)](https://github.com/labi-le/vk-utils/blob/main/LICENSE)
[![Packagist Stars](https://img.shields.io/packagist/stars/labile/vk-utils)](https://packagist.org/packages/labile/vk-utils/stats)
[![Packagist Stats](https://img.shields.io/packagist/dt/labile/vk-utils)](https://packagist.org/packages/labile/vk-utils/stats)[Документация на русском языке](README_RU.md)
## Installation
`composer require labile/vk-utils`
## How to use it?
### Simple request
```php
use Astaroth\VkUtils\Client;$api = new Client;
$response = $api->request('wall.get', ['owner_id' => 1]);
```### Use Request class
```php
use Astaroth\VkUtils\Client;
use Astaroth\VkUtils\Requests\Request;$api = new Client;
$request = new Request('wall.get', ['owner_id' => 1]);
$response = $api->send($request);
```### Use ExecuteRequest class
Sending multiple requests at the same time
```php
use Astaroth\VkUtils\Execute;
use Astaroth\VkUtils\Requests\Request;$api = new Execute;
$api->setDefaultToken('PUT ACCESS TOKEN');
$execute = [
new Request('wall.get', ['owner_id' => 1]),
new Request('wall.get', ['owner_id' => 2]),
// ...more request
new Request('wall.get', ['owner_id' => 25]),
];$response = $api->send($execute);
```### Using the required api version
```php
use Astaroth\VkUtils\Client;$api = new Client('5.131');
```### Using a token for requests
Set default token in client
```php
use Astaroth\VkUtils\Client;$api = new Client();
$api->setDefaultToken("PUT TOKEN");
```or so
```php
use Astaroth\VkUtils\Requests\Request;
use Astaroth\VkUtils\Client;$api = new Client;
// The token in the request takes precedence over setDefaultToken
$request = new Request('wall.get', ['owner_id' => 1], "some_token");
```### Constructors
#### Attachment upload constructor
```php
use Astaroth\VkUtils\Builders\Attachments\Message\Graffiti;
use Astaroth\VkUtils\Builders\Attachments\Photo;
use Astaroth\VkUtils\Builders\Attachments\Video;
use Astaroth\VkUtils\Uploader;
use Astaroth\VkUtils\Builders\Attachments\Message\AudioMessage;$uploader = new Uploader();
$uploader->setDefaultToken('PUT TOKEN');$attachments = $uploader->upload
(
new Photo("dog.jpg"),new AudioMessage('meow.mp3'),
//downloading from the link temporarily does not work
(new Video('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4'))
->setName('4 Biggers Escapes')
->setDescription('The video has nothing interesting, just an example')
->setWallpost(true),new Graffiti('cat.png')
);
```#### Builder
```php
use Astaroth\VkUtils\Builders;
use Astaroth\VkUtils\Builders\Message;
use Astaroth\VkUtils\Builders\Post;$token = 'PUT TOKEN';
$builder = new \Astaroth\VkUtils\Builder();
$builders[] = (new Message)
->setMessage("hi me name is lola! im lol")
->setPeerId(418618);$builders[] = (new Post)
->setMessage("hello subscribers")$response = $builder->create(...$builders)
);
```