gamez/mite
Composer 安装命令:
composer require gamez/mite
包简介
Interact with mite (https://mite.de) from your PHP application.
关键字:
README 文档
README
Interact with mite from your PHP application.
Requirements
- An account name (The first part of your mite account's domain, e.g. in https://xxx.mite.de)
- An API key (You can find your API key on https://xxx.mite.de/myself)
Please note that the capabilities of the library are limited by the permissions of the used credentials. As an example, a user with the role "Time Tracker" can only access data that has been made available to them and is not allowed to create new customers.
Users with the admin role can see and do (almost) everything.
Installation
In order to use this library, you need a PSR-18 HTTP Client, and a PSR-17 HTTP Message Factory. If you don't already have them available in your project, they will be added to your project's dependencies
composer require gamez/mite
Usage
Basic API client
Once you have created an HTTP Client and Request Factory as described in the installation section, you can create an API client with them:
<?php use Gamez\Mite\Api\HttpApiClientFactory; $apiClientFactory = new HttpApiClientFactory(); $apiClient = $apiClientFactory('my_account', 'api_key');
This API client allows you to make authenticated HTTP requests to the API of your mite account - see mite's REST API documentation for the endpoints you can use.
Simple API
Gamez\Mite\SimpleApi is the easiest and fastest way to access the data in your
mite account. Its methods are named after the available REST API endpoints
and always return arrays of data. You can inspect the available methods by looking at the
source code of the Gamez\Mite\SimpleApi class or by using the
autocompletion features of your IDE.
The Simple API doesn't get in your way when accessing the mite API, but it doesn't provide additional features either. It will, for example, not tell you if you used a wrong query parameter or invalid field value, so you will have to rely on the returned API responses.
For information on which query parameters and field values are allowed, see official mite API documentation
Example
use Gamez\Mite\SimpleApi; /** * @var \Gamez\Mite\Api\ApiClient $apiClient */ $api = SimpleApi::withApiClient($apiClient); $customer = $api->createCustomer([ 'name' => 'My new customer', 'note' => 'He pays better than the old one', ]); echo 'Customer: '.print_r($customer, true); $project = $api->createProject([ 'name' => 'My new customer project', 'customer_id' => $customer['id'], 'budget_type' => 'minutes_per_month', 'budget' => 6000, 'hourly_rate' => 10000, 'active_hourly_rate' => 'hourly_rate', ]); echo 'Project: '.print_r($project, true); $service = $api->createService([ 'name' => 'Customer Support', ]); echo 'Service: '.print_r($service, true); $user = current($api->getActiveUsers()); // For the sake of this example, we use the first available user echo 'User: '.print_r($user, true); $timeEntry = $api->createTimeEntry([ 'date_at' => 'today', 'minutes' => 60, 'user_id' => $user['id'], // Would we omit this, the authenticated user would be used 'project_id' => $project['id'], 'service_id' => $service['id'], 'note' => 'We had some work to do, and we did some work.' ]); echo 'Time Entry: '.print_r($timeEntry, true); // $api->delete($newTimeEntry['id']; $workdaysPerMonthAndUser = $api->getGroupedTimeEntries($groupBy = ['user'], ['at' => 'this_month']); echo 'Workdays per month and user: '.print_r($workdaysPerMonthAndUser, true);
Simple Tracker
Gamez\Mite\SimpleTracker allows you to work with mite's time tracker.
Note: You can only access the tracker of the currently authenticated user (identified by the used API key). It is not possible to modify trackers of other users.
Each action on the tracker returns an array with information about the tracked time entry, but you don't have to inspect the result to know if the action has been successful or not - if an action does not throw an error, it has been successful.
use Gamez\Mite\SimpleApi; use Gamez\Mite\SimpleTracker; /** @var \Gamez\Mite\Api\ApiClient $apiClient */ $api = SimpleApi::withApiClient($apiClient); $tracker = SimpleTracker::withApiClient($apiClient); $sleeping = $api->createTimeEntry(['note' => 'I am sleeping']); $working = $api->createTimeEntry(['note' => 'I switch to this now and then']); $tracker->start($sleeping['id']); sleep(1); // You don't need this sleep, but the example makes more sense this way $tracker->start($working['id']); // This will automatically stop the "sleeping" tracker // No sleep this time, we'll just work for zero seconds $tracker->stop($working['id']); // We stopped working! print_r($tracker->status()); // Sad
Catching errors
All exceptions thrown by this library implement the \Gamez\Mite\Exception\MiteException interface.
Exceptions thrown while using an API Client will throw a \Gamez\Mite\Exception\ApiClientError.
use Gamez\Mite\Exception\ApiClientError; use Gamez\Mite\Exception\MiteException; try { /** @var \Gamez\Mite\Api\ApiClient $apiClient */ $result = $apiClient->get('nice-try'); } catch (ApiClientError $e) { $message = "Something went wrong while accessing {$e->getRequest()->getUri()}"; if ($response = $e->getResponse()) { $message .= " ({$response->getStatusCode()})"; } $message .= ' : '.$e->getMessage(); exit($message); } catch (MiteException $e) { exit('Something not API related went really wrong: '.$e->getMessage()); } // Something went wrong while accessing https://xxx.mite.de/nice-try (404) : // The URI /nice-try could not be found.
Caching HTTP requests
To cache HTTP requests to the API, you can add a caching middleware/plugin to the HTTP client before injecting it into the API client instance. See the documentation of the respective component for instructions on how to do that.
- Guzzle: kevinrob/guzzle-cache-middleware
- HTTPlug: Cache Plugin
Creating your own API client
If you want to create your own API client, implement the \Gamez\Mite\Api\ApiClient interface
and use your implementation.
License
gamez/mite is licensed under the MIT License.
Your use of mite is governed by the Terms of Service for mite..
gamez/mite 适用场景与选型建议
gamez/mite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.14k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「time tracking」 「mite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gamez/mite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gamez/mite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gamez/mite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Adds the EDTF data type to Wikibase
Date component is a set of methods to help with the manipulation of dates.
A PSR-7 compatible library for making CRUD API endpoints
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Delayed Process For Laravel.
统计信息
- 总下载量: 1.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-22