This SDK is created for easier intergration and API usage of ONE APP.
For publisher only
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.
To use this SDK, there are several basic steps that should be done :
\One\Model\Article
object\One\Publisher
ObjectsubmitArticle
method on Publisher
These are some examples code to perform those steps :
Refer to loadTestEnv() method.
$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 :
$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
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);
$this->publisher->submitArticle($article);
You can fetch all the articles by calling listArticle()
on publisher object.
$this->publisher->listArticle();
Fork the original repository to your github repository.
Clone from your repository
git clone https://github.com/your_username/onesdk.git
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
Create branch. Remember, the name of branch should express what you're doing.
git checkout -b my-topic-branch
Don't forget to install composer dependencies
composer install
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";
Save the .env.example as .env
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
Go to your github account, on tab pull request, add your comment. Be detailed, use imperative, emoticon to make it clearer.
Watch for feedbacks.
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
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)
$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)));