kly / onesdk
One SDK Publisher php package
Installs: 13 211
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 9
Open Issues: 7
Requires
- guzzlehttp/guzzle: ~6.2
- php-ds/php-ds: ^1.2
- psr/http-message: ^1.0
- psr/log: ^1.0
- symfony/polyfill-intl-normalizer: ^1.8
Requires (Dev)
- phpunit/phpunit: ^7.2
- symplify/easy-coding-standard: ^6.0
- dev-master
- 2.3.41
- 2.3.40
- 2.3.39
- 2.3.38
- 2.3.37
- 2.3.36
- 2.3.35
- 2.3.34
- 2.3.33
- 2.3.32
- 2.3.31
- 2.3.30
- 2.3.29
- 2.3.28
- 2.3.27
- 2.3.26
- 2.3.25
- 2.3.24
- 2.3.23
- 2.3.22
- 2.3.21
- 2.3.20
- 2.3.19
- 2.3.18
- 2.3.17
- 2.3.16
- 2.3.15
- 2.3.14
- 2.3.13
- 2.3.12
- 2.3.11
- 2.3.10
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- v2.1.2
- v2.1.1
- v2.1
- v2.0
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- v1.2.2
- v1.2.1
- v1.2
- 1.1.5
- 1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1
- v1.0
- dev-php-5x
This package is auto-updated.
Last update: 2024-12-15 06:52:23 UTC
README
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 :
- Create and load credentials (client_id and client_secret or separated one use access_token)
- Instance your content into
\One\Model\Article
object - Attach any necessary details (Photos, Videos, Galleries, Or extra Pages)
- Instance
\One\Publisher
Object - Send your Article object through
submitArticle
method onPublisher
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 :
- 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"
);
- 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);
- 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 :
-
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
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
- Make sure to create test case for every core function on the class.
- Always compare data you expected or created before you make a request with the actual data that you get from a response.
- 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)));