A set of utilities for working with vk api!

Overview

vk-utils

GitHub license Packagist Stars Packagist Stats

Документация на русском языке

Installation

composer require labile/vk-utils

How to use it?

Simple example

use Astaroth\VkUtils\Client;

$api = new Client;

$response = $api->request('wall.get', ['owner_id' => 1]);

Use Request class

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

use Astaroth\VkUtils\Client;
use Astaroth\VkUtils\Requests\ExecuteRequest;
use Astaroth\VkUtils\Requests\Request;

$api = new Client();
$api->setDefaultToken('PUT ACCESS TOKEN');
$execute = ExecuteRequest::make([
    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

use Astaroth\VkUtils\Client;

$api = new Client('5.110');

Using a token for requests

Set default token in client

use Astaroth\VkUtils\Client;

$api = new Client();

$api->setDefaultToken("PUT TOKEN");

or so

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

use Astaroth\VkUtils\Uploader;
use Astaroth\VkUtils\Uploading\AudioMessage;
use Astaroth\VkUtils\Uploading\Graffiti;
use Astaroth\VkUtils\Uploading\Photo;
use Astaroth\VkUtils\Uploading\Video;

$uploader = new Uploader();
$uploader->setDefaultToken('PUT TOKEN');

$attachments = $uploader->upload
(
    new Photo('https://images.dog.ceo/breeds/sheepdog-english/n02105641_8701.jpg'),
    new Photo('https://images.dog.ceo/breeds/schipperke/n02104365_1292.jpg'),
    new Photo('https://images.dog.ceo/breeds/ovcharka-caucasian/IMG_20190528_194200.jpg'),

    new AudioMessage('meow.mp3'),
    
    (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')
);

Message constructor

use Astaroth\VkUtils\Builders;
use Astaroth\VkUtils\Uploader;
use Astaroth\VkUtils\Uploading\Photo;
use Astaroth\VkUtils\Message;

$token = 'PUT TOKEN';

$uploader = new Uploader();
$message = new Message();

$uploader->setDefaultToken($token);
$message->setDefaultToken($token);


$message = $message->create(
    (new Builders\MessageBuilder())
        ->setUserId(418618)
        ->setMessage('10 Dogs')
        ->setAttachment
        (
            'photo418618_297326744',
            ...$uploader->upload
        (
            new Photo('https://images.dog.ceo/breeds/sheepdog-english/n02105641_8701.jpg'),
            new Photo('https://images.dog.ceo/breeds/schipperke/n02104365_1292.jpg'),
            new Photo('https://images.dog.ceo/breeds/waterdog-spanish/20190208_063211.jpg'),
            new Photo('https://images.dog.ceo/breeds/mountain-swiss/n02107574_2222.jpg'),
            new Photo('https://images.dog.ceo/breeds/husky/n02110185_11783.jpg'),
            new Photo('https://images.dog.ceo/breeds/pointer-germanlonghair/hans3.jpg'),
        )
        ),
    (new Builders\MessageBuilder())
        ->setUserId(418618)
        ->setMessage('2 sms'),

    (new Builders\MessageBuilder())
        ->setUserId(418618)
        ->setMessage('3 sms'),
);

Need more speed?

Turn on parallel requests to VK

use Astaroth\VkUtils\Builders;
use Astaroth\VkUtils\Uploader;
use Astaroth\VkUtils\Message;
use Astaroth\VkUtils\Uploading\Photo;
use Astaroth\VkUtils\Uploading\Video;

$token = 'PUT TOKEN';

$uploader = new Uploader();
$uploader->setDefaultToken($token);

$message = new Message();
$message->setDefaultToken($token);

Uploader::enableParallelRequest();
Message::enableParallelRequest();

//Messages will be sent in parallel!
$message = $message->create(
    (new Builders\MessageBuilder())
        ->setUserId(418618)
        ->setMessage('10 Dogs')
        ->setAttachment
        (
            'photo418618_297326744',
            ...$uploader->upload
        (
            new Photo('https://images.dog.ceo/breeds/mountain-swiss/n02107574_2222.jpg'),
            new Photo('https://images.dog.ceo/breeds/husky/n02110185_11783.jpg'),
            new Photo('https://images.dog.ceo/breeds/pointer-germanlonghair/hans3.jpg'),

            (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 Builders\MessageBuilder())
        ->setUserId(418618)
        ->setMessage('who was Zarathustra? ')
);

You need to be careful with parallel requests, this is how you can get flood control from VKontakte
It is recommended to use Uploader::enableParallelRequest() only with the community token
It is also worth noting that when using Message::enableParallelRequest() messages are sent in a random this can be useful when sending multiple messages with attachments

You might also like...
TEC UTilities (or tut) are a collection of tools for managing plugins.

TEC Utilities TEC UTilities (or tut) are a collection of tools for managing plugins. /^\ L L /

A collection of useful codes and utilities for WordPress plugin development..

WordPress Utils A collection of useful codes and utilities for WordPress plugin development. These simplifies common tasks and promote code reusabilit

A collection of command-line utilities to aid in debugging browser engines.

Browser debug utilities This project contains several scripts that make the process of debugging browser engines much easier (some special cases excep

A plugin for working with popular money libraries in Pest

This package is a plugin for Pest PHP. It allows you to write tests against monetary values provided by either brick/money or moneyphp/money using the same declarative syntax you're used to with Pest's expectation syntax.

A PHPStan package that supports working with Extbase

PHPStan for Extbase This package provides a couple of stubs and services to make your life easier when working with PHPStan and Extbase. Examples clas

A simple package for working with money.

Money A simple package for working with money. Main features: Simple API Livewire integration Custom currency support Highly customizable formatting R

Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people home in decoration positions and others.

Iran-Decoration Platform Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people

I am actively working on this - v1.3 stable-DEV
I am actively working on this - v1.3 stable-DEV

Batch-OBF-php This Obf .bat files v swag ngl only reason im posting the code is cuz i people have said im ratting them by changing the code of the .ba

A library for working with StatsD in PHP

StatsD PHP Library A library for working with StatsD in PHP. Install Via Composer: composer require league/statsd To use the Statsd Service Provider,

Releases(2.1.4)
Owner
null
PHP library with basic objects and more for working with Facebook/Metas Conversions API

PHP library with basic objects and more for working with Facebook/Metas Conversions API Installation The easiest way to install this library is by ins

null 5 Dec 5, 2022
Open-source library used in Gigadrive projects with common PHP utilities

PHP Commons This library provides PHP utilities used in Gigadrive projects, provided for the open-source community. Functions are registered globally

Gigadrive UG 3 Nov 10, 2021
This is php utilities

PHP-UTILITY This is php utilities. Requirements PHP >= 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project director

null 2 Aug 28, 2022
Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

Bippo Indonesia 23 Dec 20, 2022
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022
Utilities to scan PHP code and generate class maps.

composer/class-map-generator Utilities to generate class maps and scan PHP code. Installation Install the latest version with: $ composer require comp

Composer 55 Dec 26, 2022
Demo of symfony/console features to build rich command line utilities

Symfony Console Demo This project is a demonstration of symfony/console features. To run the project with Docker. With bash: docker build -t myconsole

Jérôme Tamarelle 3 Jun 16, 2022
Utilities for concurrent programming of PocketMine-MP plugins.

Utilities for concurrent programming of PocketMine-MP plugins Overview Plugin that implements the pthreads channels and in the future, promises (which

Dmitry Uzyanov 0 Aug 15, 2022
Utilities for the Contentful Rich Text

rich-text.php This library is built to help you with the parsing and rendering of the rich text field type in Contentful. It requires PHP 7.2 and up o

Contentful 8 Oct 1, 2022
Testing utilities for the psr/log package that backs the PSR-3 specification.

FIG - Log Test Testing utilities for the psr/log package that backs the PSR-3 specification. Psr\Log\Test\LoggerInterfaceTest provides a base test cla

PHP-FIG 3 Nov 19, 2022