jansenfelipe/loggi-php

PHP到Loggi API的抽象层

1.0.2 2018-02-18 19:15 UTC

This package is auto-updated.

Last update: 2024-09-11 22:38:32 UTC


README

Travis

PHP到Loggi API的抽象层。

阅读更多 https://docs.api.loggi.com/docs

如何使用

首先,安装库

$ composer require jansenfelipe/loggi-php

只需实例化您想要使用的资源。

以下示例中,我正在查找所有的商店

<?php

use JansenFelipe\LoggiPHP\Presto\ShopResource;
use JansenFelipe\LoggiPHP\Presto\OrderResource;
use JansenFelipe\LoggiPHP\Presto\Entities\LocationEntity;

$shopResource = new ShopResource();

$result = $shopResource->all();

foreach ($result as $shop) {
    
    echo $shop->id;
    echo $shop->pk;
    echo $shop->name;
}

/*
 * Now, I will estimate the price to deliver at a certain point
 */

$from = $result[0]; //Get a first shop

$orderResource = new OrderResource();

$to = new LocationEntity();
$to->latitude = -19.8579253;
$to->longitude = -43.94522380000001;

$result = $orderResource->estimation($from, $to);

echo 'Estimated price: '. $result->price;

设置

以上示例假定环境变量 LOGGI_API_URLLOGGI_API_EMAILLOGGI_API_KEY 已配置。

默认情况下,请求将在生产环境中发送。

如果您想,可以手动实例化 LoggiClient 并将其注入资源中。

例如

<?php

use JansenFelipe\LoggiPHP\Presto\ShopResource;
use JansenFelipe\LoggiPHP\LoggiClient;

$client = new LoggiClient(LoggiClient::SANDBOX, 'my-email@gmail.com', 'my-key-api');

$shopResource = new ShopResource($client);

可用资源

  • Presto
    • ShopResource
      • all() : ShopEntity[]
    • OrderResource
      • estimation(from:ShopEntity, to:LocationEntity) : EstimateEntity

实体

独立

您可以在不使用资源的情况下运行查询。只需调用 LoggiClient 类的 executeQuery($query) 方法。

例如,让我们看看Loggi运营的所有城市

<?php

use JansenFelipe\LoggiPHP\LoggiClient;
use JansenFelipe\LoggiPHP\Query;

$client = new LoggiClient(LoggiClient::SANDBOX, 'my-email@gmail.com', 'my-key-api');

$query = new Query([
    'allCities' => [
        'edges' => [
            'node' => ['pk', 'name', 'slug']
        ]
    ]
]);

$response = $client->executeQuery($query);

许可证

MIT许可证(MIT)