One SDK Publisher php package
This SDK is created for easier intergration and API usage of ONE APP., (*2)
For publisher only, (*3)
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., (*4)
To use this SDK, there are several basic steps that should be done :, (*5)
\One\Model\Article
object\One\Publisher
ObjectsubmitArticle
method on Publisher
These are some examples code to perform those steps :, (*6)
Refer to loadTestEnv() method., (*7)
$env = \loadTestEnv(); $this->publisher = new Publisher( $env['YOUR_CLIENT_ID'], $env['YOUR_CLIENT_SECRET'] );
If you want to publish an article, there are several steps should be done :, (*8)
$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" );
Attach if article contains some attachments, (*9)
Article supports multiple kind of attachment such as: photo, page., (*10)
$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);
$this->publisher->submitArticle($article);
, (*11)
You can fetch all the articles by calling listArticle()
on publisher object., (*12)
$this->publisher->listArticle();
, (*13)
Fork the original repository to your github repository., (*14)
Clone from your repository, (*15)
git clone https://github.com/your_username/onesdk.git
, (*16)
To keep up to date with original repository, run this command, (*17)
git remote add upstream https://github.com/KLYgarage/onesdk.git
, (*18)
git pull upstream master
, (*19)
Create branch. Remember, the name of branch should express what you're doing., (*20)
git checkout -b my-topic-branch
, (*21)
Don't forget to install composer dependencies, (*22)
composer install
, (*23)
Modify the .env.example file, to reflect correct credentials., (*24)
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";
Save the .env.example as .env, (*25)
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 :, (*26)
git push -u origin my-topic-branch
, (*27)
Go to your github account, on tab pull request, add your comment. Be detailed, use imperative, emoticon to make it clearer., (*28)
Watch for feedbacks., (*29)
PHP CS Fixer is intended to fix coding standard. So, Remember! to always run PHP CS Fixer before you create pull request., (*30)
composer run cs-fix
, (*31)
Open a command prompt or terminal, navigate to project directory and run command composer run test
, (*32)
> 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
, (*33)
> 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)
$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
, (*34)
assertTrue(empty(array_diff($array, $arrayFromResponse)));