megaads/apify-client-php

Apify client for PHP

1.0.14 2021-08-12 09:53 UTC

This package is not auto-updated.

Last update: 2024-11-01 19:17:43 UTC


README

Installation

System requirements

  • PHP: >= 5.6
  • Laravel/ Lumen Framework: 4.* or newer

Require the composer package

`composer require megaads/apify-client-php`

Create query builder

use Megaads\ApifyClient\Client;

$query = Client::endpoint("product", [
    Client::OPTION_API_HOST => "https://api.domain.com",
    Client::OPTION_API_AUTH => "token=dsfqwe123sdf2342c",
    Client::OPTION_REQUEST_HEADER => ["Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"]
]);

Add custom field

Add a custom parameter to request URL

$query->addField("customer_id", 123);

$query->addField("version", "1.0.0");

Get request URL

The simplest method to see the generated request URL

$query->toURL();

Pagination

$query->pageId(0);

$query->pageSize(100);

Sorting

Sort ascending

$query->sort("user_id");

Sort descending

$query->sort("-created_at");

Sort by multiple columns

$query->sort(["user_id", "-created_at"]);

Selection

Select columns from the records. SQL aggregate functions such as COUNT, MAX, MIN, SUM, AVG, SQL aliases are also available

$query->select("id");

$query->select(["content", "user_id", "sum(view_count) as view_sum"]);

Group By

Group the result-set by one or more columns and combine with aggregate functions using Selection

$query->select(["user_id", "sum(view_count) as view_sum"]);

$query->group("user_id");

Filtering

Relationships

Apify provides the ability to embed relational data into the results

For example

$query->embed("cities");

$query->embed(["nation", "districts"]);

Filtering on relationships

$query->filter("nation.location_code", Client::SELECTION_EQUAL, "EU");

$query->filter("districts.name", Client::SELECTION_LIKE, land);

Retrieve data

Find: Retrieve single record

$query->find(1);

Get: Retrieve all records that match the query

$query->get();

Response format

[
    "meta" => [
        "has_next" => true,
        "total_count" => 100,
        "page_count" => 2,
        "page_size" => 50,
        "page_id" => 0
    ],
    "result" => [],
    "status" => "successful"
]

First: Retrieve the first record that matchs the query

$query->first();

Response format

[    
    "result" => [],
    "status" => "successful"
]

Count: Retrieve the number of records that match the query

$query->count();

Response format

[    
    "result" => 50,
    "status" => "successful"
]

Increment/ Decrement: Provides convenient methods for incrementing or decrementing the value of a selected column

$query->select("view_count");

$query->increment();

Response format

[    
    "result" => 1,
    "status" => "successful"
]

Send custom request

use Megaads\ApifyClient\Client;

$query = Client::request("https://api.domain.com/product", 
Client::METHOD_POST, 
[
    "name" => "Hello",
    "code" => "C0001"
],
[
    "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"
]);

License

The Apify is open-sourced software licensed under the MIT license

Contact us/ Instant feedback

Email: info@megaads.vn

Skype: phult.bk