zozocorp/worker

The Worker SDK provides methods for all API functions.

v1.0.0 2021-06-05 04:36 UTC

This package is auto-updated.

Last update: 2024-04-05 10:30:06 UTC


README

This is the Worker PHP SDK. This SDK contains methods for easily interacting with the Worker API. Below are examples to get you started. For additional examples, please see our official documentation at https://worker.zozo.vn/

Join the chat at https://gitter.im/worker/worker-php

Installation

To install the SDK, you will need to be using Composer in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer:

curl -sS https://getcomposer.org/installer | php

The Worker API Client is not hard coupled to Guzzle, Buzz or any other library that sends HTTP messages. Instead, it uses the PSR-18 client abstraction. This will give you the flexibility to choose what PSR-7 implementation and HTTP client you want to use.

If you just want to get started quickly you should run the following command:

composer require zozocorp/worker

Usage

You should always use Composer autoloader in your application to automatically load your dependencies. All the examples below assume you've already included this in your file:

require 'vendor/autoload.php';
use Worker\Worker;

Here's how to send a message using the SDK:

// First, instantiate the SDK with your API credentials
$wk = Worker::create('key-example'); // For VI servers

// Now, compose and send your message.
// $wk->messages()->send($domain, $params);
$wk->email()->send('example.com', [
  'from'    => 'bob@example.com',
  'to'      => 'sally@example.com',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);

Attention: $domain must match to the domain you have configured on worker.zozo.vn.

All usage examples

You will find more detailed documentation at /doc and on https://documentation.worker.com.

VERIFY EMAIL

$wk = Worker::create('key-example');
$dns = $wk->email()->verify(['email' => 'ws@zozo.vn']);

If you'd rather work with an array than an object you can inject the ArrayHydrator to the Worker class.

MINIFY

The result of an API call is, by default, a domain object. This will make it easy to understand the response without reading the documentation. One can just read the doc blocks on the response classes. This provides an excellent IDE integration.

MINIFY HTML

$wk = Worker::create('key-example');
$dns = $wk->template()->minify(['template' => '<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CONVERT HTML TO AMP</title>
</head>
<body>
    <p>MINIFY HTML</p>
</body>
</html>']);

If you'd rather work with an array than an object you can inject the ArrayHydrator to the Worker class.

CONVERT HTML TO AMP

$wk = Worker::create('key-example');
$dns = $wk->template()->amp(['template' => '<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CONVERT HTML TO AMP</title>
</head>
<body>
    <p>CONVERT HTML TO AMP</p>
</body>
</html>']);

If you'd rather work with an array than an object you can inject the ArrayHydrator to the Worker class.

MINIFY IMAGES

C1: Use the api post header form data or push directly from the form

$wk = Worker::create('key-example');
$dns = $wk->image()->shrink(['image' => $file]);

C2: use api post images curl

$wk = Worker::create('key-example');
$dns = $wk->image()->shrink(['image' => $_FILES['image']]);

GEO IP

$wk = Worker::create('key-example');
$dns = $wk->ip()->info(['ip' => '125.212.192.170']);

You can also use the NoopHydrator to get a PSR7 Response returned from the API calls.

URL screenshot

$width = 1080;
$height = 650;
$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->url()->screenshot(['url' => $url, 'width' => $width, 'height' => $height]);

You can also use the NoopHydrator to get a PSR7 Response returned from the API calls.

URL screenshot

$width = 1080;
$height = 650;
$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->url()->screenshot(['url' => $url, 'width' => $width, 'height' => $height]);

You can also use the NoopHydrator to get a PSR7 Response returned from the API calls.

URL short

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->url()->screenshot(['url' => $url]);

You can also use the NoopHydrator to get a PSR7 Response returned from the API calls.

SEARCH

Search full text

$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->search(
    [
        'index' => 'index name', 
        'keyword' => 'website giáo dục' , 
        'fields' => array('text', 'title', 'description')
    ]);

Search keyword trending

$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->trendingKeywords(
    [
        'merchant' => 'tên miền doanh nghiệp', 
        'from' => 'thời gian bắt đầu' , 
        'to' => 'thời gian bắt đầu' , 
        'limit' => 'số bản ghi' , 
    ]);

Insert data

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->insert(
    ['index' => 'index name' ,
     'data' => array('text' => 'insert content', 'title' => 'insert content', 'description' => 'insert content')
    ]);

Get data

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->get(
    [
        'index' => 'index name', 
        'id' => 1 , 
    ]);

Delete data

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->delete(
    [
        'index' => 'index name', 
        'id' => 1 , 
    ]);

Create index

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->createIndex(
    [
        'index' => 'index name', 
    ]);

Delete index

$url = 'https://zozo.vn/';
$wk = Worker::create('key-example');
$dns = $wk->elasticsearch()->deleteIndex(
    [
        'index' => 'index name', 
    ]);

Create QR code

TYPE: use type text (name, email, phone, url, meta)

$type = 'text';
$name = 'zozo'; // Field is optional
$email = 'ws@zozo.vn'; // Field is optional
$meta = 'zozo.vn - Nền tảng thiết kế Website bán hàng chuyên nghiệp'; // Field is optional
$url = 'https://zozo.vn/'; // Field is optional
$phone = '0960099999'; // Field is optional

$wk = Worker::create('key-example');
$dns = $wk->qrCode()->encode(['type' => $type, 'content' => $meta]);

TYPE: use type mecard (name, address, phone, email, url)

$type = 'mecard';
$name = 'zozo'; // Field is optional
$email = 'ws@zozo.vn'; // Field is optional
$address = 'Tầng 7, Toà nhà iNET, số 247 Cầu Giấy, phường Dịch Vọng, Quận Cầu Giấy'; // Field is optional
$url = 'https://zozo.vn/'; // Field is optional
$phone = '0960099999'; // Field is optional

$wk = Worker::create('key-example');
$dns = $wk->qrCode()->encode(['type' => $type, 'name' => $name, 'email' => $email, 'address' => $address, 'url' => $url, 'phone' => $phone]);

TYPE: use type vcard (first_name, last_name, title, company, street, province, country, phone, email, url)

$type = 'vcard';
$first_name = 'le'; // Field is optional
$last_name = 'thi'; // Field is optional
$title = 'Nền tảng thiết kế Website bán hàng chuyên nghiệp'; // Field is optional
$company = 'zozo.vn'; // Field is optional
$email = 'ws@zozo.vn'; // Field is optional
$street = 'Tầng 7, Toà nhà iNET, số 247 Cầu Giấy, phường Dịch Vọng, Quận Cầu Giấy'; // Field is optional
$province = 'Hà Nội'; // Field is optional
$country = 'Việt Nam'; // Field is optional
$url = 'https://zozo.vn/'; // Field is optional
$phone = '0960099999'; // Field is optional

$wk = Worker::create('key-example');
$dns = $wk->qrCode()->encode([
    'first_name' => $first_name, 'last_name' => $last_name, 
    'title' => $title, 'company' => $company, 'email' => $email, 
    'street' => $street, 'province' => $province, 'country' => $country,
    'url' => $url, 'phone' => $phone]);