'Latest articles widget' with Newscoop Rest API PHP-SDK
About Newscoop REST API PHP-SDK.
PHP-SDK is a library that simply allows access to the Newscoop REST API. You can easily install it in any php project with Composer - just add
"sourcefabric/newscoop-php-sdk": "dev-master"
to the required section. If you don’t use Composer yet, then you can clone this repository: https://github.com/sourcefabric/newscoop-api-php-sdk to your project vendors.
The SDK uses two required dependencies (if you are not using Composer, then you must download them to you project vendors too):
- “symfony/event-dispatcher”: “2.1.*”
- “kriswallsmith/buzz”: “v0.7”
The most important class in sdk is Newscoop\API\Client - You will use this class for almost everything.
Last articles widget
php composer.phar install
Now create web/ in your project directory and inside it the file index.php (newscoop-widget/web/index.php). At first you must initialize the silex application - this will be the first version of your widget: https://gist.github.com/3958564
Next step - SDK initialization:
Add the use statements before require_once function (on top):
use Newscoop\API\Client; use Symfony\Component\HttpFoundation\Request;
https://gist.github.com/3963466
Now we have the Client object - it’s time for our first api request.
You must first replace your routing function,
https://gist.github.com/3963528
To make the design better - add this asset to your web/Resources/public/css direcotry (create it)
bootstrap.css -
https://raw.github.com/ahilles107/newscoop-widget/master/web/Resources/public/css/bootstrap.css widget.css -
https://github.com/ahilles107/newscoop-widget/raw/master/web/Resources/public/css/widget.css
This is all in the tutorial. You can find more complex version of this widget here - https://github.com/ahilles107/newscoop-widget/.
- If you have questions - send us a message on our Newscoop Facebook page