定制 jackwh/nylas-v3-api-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jackwh/nylas-v3-api-php

Composer 安装命令:

composer require jackwh/nylas-v3-api-php

包简介

Nylas API v3 PHP SDK client

README 文档

README

PHP API clients for the Nylas V3 API.

This is an experimental package and is not officially endorsed by Nylas. I've released this as their PHP SDK is no longer actively maintained, and the only other PHP clients available are for V2. Please refer to the notes below for how the API clients were generated.

Installation and Usage

Install the project using Composer:

composer require "jackwh/nylas-v3-api-php":"dev-main"

You can then use the relevant API clients like so:

use JackWH\NylasV3;

$accessToken = '**********';
$grantId     = '##########';

$api = new NylasV3\EmailCalendar\Api\CalendarApi(
    new \GuzzleHttp\Client(),
    NylasV3\EmailCalendar\Configuration::getDefaultConfiguration()->setAccessToken($accessToken)
);

$result = $api->getCalendars($grantId, limit: 10);

In this example you'll receive back a NylasV3\EmailCalendar\Model\GetCalendars200Response object, with entries mapped to NylasV3\EmailCalendar\Model\Calendar objects. When converted to JSON the output will look something like this:

{
    "request_id": "17262346...",
    "data": [
        {
            "name": "My Calendar",
            "timezone": "Europe\/London",
            "hex_color": "#0e61b9",
            "hex_foreground_color": "#ffffff",
            "grant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "id": "example.com_vj9230@group.calendar.google.com",
            "object": "calendar",
            "is_primary": false,
            "read_only": false,
            "is_owned_by_user": true
        },
        {
            "description": "Holidays and Observances in United Kingdom",
            "name": "Holidays in United Kingdom",
            "timezone": "Europe\/London",
            "hex_color": "#711a76",
            "hex_foreground_color": "#ffffff",
            "grant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "id": "en.uk#holiday@group.v.calendar.google.com",
            "object": "calendar",
            "is_primary": false,
            "read_only": true,
            "is_owned_by_user": false
        }
    ],
    "next_cursor": "EiIKDAj..."
}

About This Repository

As there's no official v3 API client for PHP, I've done my best to semi-automatically generate this one. There were a few hoops to jump through, I'm sure there must be an easier/simpler way to do this (if anybody knows, please explain!). Here's how I went about it...

  1. Export OpenAPI specs from Nylas' documentation for each API, and save to api_specs/yaml.
  2. Take the YAML specs and convert them to JSON, place these alongside the originals in api_specs/yaml.
  3. Due to a bug in the PHP OpenAPI generator, we need to dereference $ref pointers using the npm script below. This calls the api_specs/utilities/dereference-json.js script, which recursively dereferences all $ref pointers in each JSON OpenAPI spec. The final JSON specs are saved to api_specs:
npm run dereference-json
  1. Finally we can generate client code for each of the APIs using the OpenAPI Generator:
openapi-generator generate -g php-nextgen \
  -o src/api/administration/ \
  -i api_specs/administration.json \
  --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true,REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
  --invoker-package="JackWH\\NylasV3\\Administration" \
  --additional-properties=composerPackageName="jackwh/nylas-v3-api-php",variableNamingConvention="snake_case"
openapi-generator generate -g php-nextgen \
  -o src/api/email-calendar/ \
  -i api_specs/email-calendar.json \
  --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true,REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
  --invoker-package="JackWH\\NylasV3\\EmailCalendar" \
  --additional-properties=composerPackageName="jackwh/nylas-v3-api-php",variableNamingConvention="snake_case"
openapi-generator generate -g php-nextgen \
  -o src/api/scheduler/ \
  -i api_specs/scheduler.json \
  --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true,REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
  --invoker-package="JackWH\\NylasV3\\Scheduler" \
  --additional-properties=composerPackageName="jackwh/nylas-v3-api-php",variableNamingConvention="snake_case"

Changes to the OpenAPI spec

Any small changes I've made to the OpenAPI specs since first generating the clients are detailed below:

  • email-calendar.yaml:
    • Remove "minItems": *" constraints from Event participants and Draft to arrays, as the generated client was throwing InvalidArgumentExceptions when trying to serialize these objects. (I assume this was an error from the original spec.)

jackwh/nylas-v3-api-php 适用场景与选型建议

jackwh/nylas-v3-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「JackWH」 「nylas」 「nylas-v3-api-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jackwh/nylas-v3-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jackwh/nylas-v3-api-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 jackwh/nylas-v3-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 73
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-13