arueckauer/harvest-api

使用OAuth访问令牌的Harvest 2 API

0.3.0 2022-06-23 08:37 UTC

This package is auto-updated.

Last update: 2024-09-23 13:08:26 UTC


README

重要:此包正在开发中,因此尚未完全实现或测试。不是生产就绪!

使用OAuth访问令牌的Harvest 2 API

请参阅https://github.com/arueckauer/harvest-api以获取背景信息。

入门

通过composer安装

composer require arueckauer/harvest-api

使用方法

初始化

Zend Expressive

将您的Harvest账户配置放置在config/autoload/application.local.php中(用您的账户凭证替换示例数据)

<?php

declare(strict_types = 1);

return [
    arueckauer\HarvestApi\ClientFactory::class => [
        'config' => [
            'headers' => [
                'Authorization'      => 'Bearer $ACCESS_TOKEN',
                'Harvest-Account-Id' => '$ACCOUNT_ID',
                'User-Agent'         => 'MyApp (yourname@example.com)',
            ],
        ],
    ],
];

通过CLI创建处理程序(用您的处理程序名称替换示例类名)

composer expressive handler:create "App\Handler\HarvestApi"

这将为您创建一个处理程序类及其工厂,并将这些注册到config/autoload/zend-expressive-tooling-factories.global.php中。

将构造函数注入添加到创建的处理程序类中。然后在新建的工厂中从容器中获取Harvest客户端对象并将其传递给处理程序类的构造函数 - src/App/src/Handler/HarvestApiFactory.php

<?php

declare(strict_types=1);

namespace App\Handler;

use Psr\Container\ContainerInterface;

class HarvestApiFactory
{
    public function __invoke(ContainerInterface $container) : HarvestApi
    {
        return new HarvestApi($container->get(\arueckauer\HarvestApi\Client::class));
    }
}

其他上下文

<?php

// public/index.php
    
require_once __DIR__ . '/../vendor/autoload.php';

$headers = [
    'Authorization'      => 'Bearer $ACCESS_TOKEN',
    'Harvest-Account-Id' => '$ACCOUNT_ID',
    'User-Agent'         => 'MyApp (yourname@example.com)',
];
$client = new \arueckauer\HarvestApi\Client($headers);

测试

进行中

许可

MIT许可。请参阅LICENSE

贡献

请阅读并遵守我们的行为准则

提交错误

此包仍在开发中,因此可能会遇到不完整的功能和错误。如果您遇到任何困难,请在此GitHub上免费打开一个问题。

拉取请求

欢迎通过拉取请求进行贡献。

致谢

此包深受bestit/harvest-api的启发,当时该API支持Harvest API V1。

待办事项

要检查实现的当前状态,请查看CHECKLIST开放问题