michaeljamesparsons / metropublisher-php-sdk
一个简单的 MetroPublisher API 包装器。
0.2.1
2018-01-08 03:36 UTC
Requires
- guzzlehttp/guzzle: 6.2.*
- phpdocumentor/reflection-docblock: 3.1.*
Requires (Dev)
- phpunit/phpunit: 5.5.*
This package is not auto-updated.
Last update: 2024-09-24 06:46:45 UTC
README
这是一个完全功能的 MetroPublisherTM REST API SDK。它为您处理了样板 HTTP 客户端请求/响应逻辑,以便您可以立即将 API 应用到您的应用程序中。
安装
推荐通过 composer 进行安装。
composer require michaeljamesparsons/metropublisher-php-sdk
依赖项
如果您使用 composer,这些依赖项将自动安装。
快速入门
<?php use MetroPublisher\MetroPublisher; use MetroPublisher\Api\Models\Article; //Create a new MetroPublisher API instance $metroPublisher = new MetroPublisher("{public key}", "{secret key}"); //Create a new article $article = new Article($metroPublisher); $article->setUuid('41b47ff8-3355-4f69-a867-7232165e6d29') ->setUrlname('lorem-ipsum') ->setTitle('Lorem Ipsum') ->setMetaTitle('Lorem Ipsum') ->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') ->setMetaDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') ->setPrintDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') ->setContent('<p>Quisque sed erat sed ex eleifend sollicitudin eu id ligula.</p>') ->setFeatureImageUuid(null) ->setTeaserImageUuid(null) ->setIssued(new DateTime('now')) ->setEvergreen(true); //Save the article $article->save(); //Delete the article $article->delete();
字典
模型
一个 模型
代表了 MetroPublisher API 中的一个对象。例如,这可以是文章、事件、位置或其他对象。这些对象的属性映射到在 官方 API 资源参考中为该对象定义的字段。
资源模型
资源模型
是一种模型,与非资源模型不同,它可以保存到 API 或从中删除。一些资源模型具有额外的函数,允许它们获取与它们相关的其他模型。并非所有的资源模型都已实现,但我已列出了以下准备好供您使用的模型!
- 文章
- 事件
- 专辑评论
- 书籍评论
- 位置评论
- 位置
- 标签
- 标签类别
- 插槽
- 外部插槽媒体
- 嵌入插槽媒体
- 文件插槽媒体
非资源模型
非资源模型依赖于另一个资源模型的存在。例如,path_history
模型不能从 API 保存或删除。它只是代表另一个模型的数据。
- 路径历史
集合
每个资源模型都有一个相应的集合对象。集合对象允许您获取资源模型的组、单个资源模型或与资源模型相关的模型的组。
<?php use MetroPublisher\Api\Collections\ArticleCollection; $articleCollection = new ArticleCollection($metroPublisher); //Get group of articles $articles = $articleCollection->findAll(); //Get next group of articles $moreArticles = $articleCollection->findAll(2); //Get a single article $singleArticle = $articleCollection->find('e6ebac9c-94cb-11e6-ae22-56b6b6499611');
测试
单元测试位于 /tests
目录中。全面覆盖正在进行。
./vendor/bin/phpunit
待办事项
- 实现 HttpClient 接口
- 缓存解析模型注解
- 支持直接使用 UUID 关联对象
- 使集合可迭代
许可证
在 MIT 许可证下发布。