kly/onesdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kly/onesdk

Composer 安装命令:

composer require kly/onesdk

包简介

One SDK Publisher php package

README 文档

README

Scrutinizer Code Quality Build Status Code Intelligence Status

This SDK is created for easier intergration and API usage of ONE APP.

For publisher only

Prerequisite

  • PHP Version >=5.3.3

Installation

If you are using composer you could get it with composer require kly/onesdk and you are all set. Load up the autoloader and Call the classes or factory you need.

Usage

To use this SDK, there are several basic steps that should be done :

  1. Create and load credentials (client_id and client_secret or separated one use access_token)
  2. Instance your content into \One\Model\Article object
  3. Attach any necessary details (Photos, Videos, Galleries, Or extra Pages)
  4. Instance \One\Publisher Object
  5. Send your Article object through submitArticle method on Publisher

These are some examples code to perform those steps :

Load credentials

Refer to loadTestEnv() method.

Instance publisher object

$env = \loadTestEnv();
        $this->publisher = new Publisher(
            $env['YOUR_CLIENT_ID'],
            $env['YOUR_CLIENT_SECRET']
        );

Publish

If you want to publish an article, there are several steps should be done :

  1. Instance article object
$article = new Article(
            'Eius ad odit voluptatum occaecati ducimus rerum.',
            'Facilis occaecati sequi animi corrupti. Ex sit voluptates accusamus. Quidem eum magnam veniam odio totam aut. Nobis possimus totam quasi tempora consectetur iste. Repellendus est veritatis quibusdam dicta. Sapiente modi perferendis quidem repudiandae voluptates.',
            'https://www.zahn.de/home/',
            'dummy-' . rand(0, 999),
            Article::TYPE_TEXT,
            Article::CATEGORY_BISNIS,
            "Hans-Friedrich Hettner B.Sc.",
            "Dolorum expedita repellendus ipsam. Omnis cupiditate enim. Itaque alias doloribus eligendi.",
            "distinctio",
            "2013-05-25"
        );
  1. Attach if article contains some attachments

Article supports multiple kind of attachment such as: photo, page.

$photo = new Photo(
            'https://aubry.fr/',
            Photo::RATIO_RECTANGLE,
            "Rerum asperiores nulla suscipit ex. Eligendi vero optio architecto dignissimos. Omnis autem ab ad hic quaerat omnis.",
            "Eum assumenda ab accusamus quam blanditiis."
        );
$article->attachPhoto($photo);
  1. Publish the article to ONE App REST API by submitting through instanced publisher object.

$this->publisher->submitArticle($article);

Fetch

You can fetch all the articles by calling listArticle() on publisher object.

$this->publisher->listArticle();

Steps to contribute :

  1. Fork the original repository to your github repository.

  2. Clone from your repository

    git clone https://github.com/your_username/onesdk.git

  3. To keep up to date with original repository, run this command

    git remote add upstream https://github.com/KLYgarage/onesdk.git

    git pull upstream master

  4. Create branch. Remember, the name of branch should express what you're doing.

    git checkout -b my-topic-branch

  5. Don't forget to install composer dependencies

    composer install

  6. Modify the .env.example file, to reflect correct credentials.

    CLIENT_ID=$CLIENT_ID
    
    CLIENT_SECRET=$CLIENT_SECRET
    
    To get ACCESS_TOKEN, run the following commands using curl :
    
    curl -X POST "https://dev.one.co.id/oauth/token" \
     -H "Accept: application/json" \
     -d "grant_type"="client_credentials" \
     -d "client_id"="YOUR CLIENT ID" \
     -d "client_secret"="YOUR CLIENT SECRET";
     
    
  7. Save the .env.example as .env

  8. When you are ready to propose changes to the original repository, it's time to create pull request. To create pull request, run the following commands :

    git push -u origin my-topic-branch

  9. Go to your github account, on tab pull request, add your comment. Be detailed, use imperative, emoticon to make it clearer.

  10. Watch for feedbacks.

PHP CS Fixer

PHP CS Fixer is intended to fix coding standard. So, Remember! to always run PHP CS Fixer before you create pull request.

composer run cs-fix

Testing

How to Run Tests

Open a command prompt or terminal, navigate to project directory and run command composer run test

> php ./phpunit --bootstrap ./test/bootstrap.php ./test/
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

..................

Time: 14 seconds, Memory: 10.00MB

OK (18 tests, 98 assertions)

To see what test is running you can use command composer run test:verbose

> php ./phpunit --bootstrap ./test/bootstrap.php ./test/
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Starting test 'One\Test\Unit\PublisherTest::testSubmitArticleWithoutAttachment'.
.
Starting test 'One\Test\Unit\PublisherTest::testSubmitArticleWithPhotos'.
.
Starting test 'One\Test\Unit\PublisherTest::testSubmitArticleWithPage'.
.
Starting test 'One\Test\Unit\PublisherTest::testSubmitArticleWithGallery'.
.
Starting test 'One\Test\Unit\PublisherTest::testSubmitArticleWithVideo'.

Time: 12.34 seconds, Memory: 10.00MB

OK (18 tests, 98 assertions)

What to Remember When Writing a Test

  1. Make sure to create test case for every core function on the class.
  2. Always compare data you expected or created before you make a request with the actual data that you get from a response.
  3. Use the correct assertion. Avoid using assertEquals to compare arrays because sometimes you will get array (response from server) values sorted in different order from your expected array. In example:
$array = [
  '0'=>'500',
  '1'=>'A'
];

$arrayFromResponse = [
  '0'=>'A',
  '1'=>'500
];

Rather than sorting $arrayFromResponse to make the order equal, we can use assertTrue combine with array_diff

assertTrue(empty(array_diff($array, $arrayFromResponse)));

kly/onesdk 适用场景与选型建议

kly/onesdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.23k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 kly/onesdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 14.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-29