Simple library for ValueFrame REST API.
Basically this is a wrapper for guzzlehttp/guzzle - this library just adds necessary headers to each request.
- PHP 7.3 or higher
- Composer
The recommended way to install this library is with Composer. Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.
# Install Composer
curl -sS https://getcomposer.org/installer | php
You can add this library as a dependency to your project using following command:
composer require protacon/vf-rest
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Note that this is only needed if you're using this library as a stand-alone component - usually your framework (eg. Symfony) is already handling this part for you.
First of all you should read official documentation about ValueFrame REST API.
Simple usage example:
<?php
declare(strict_types=1);
namespace App;
use GuzzleHttp\Exception\BadResponseException;
use ValueFrame\Rest\Factory as Client;
use function json_decode;
use function var_dump;
require __DIR__ . '/vendor/autoload.php';
$customer = 'asiakas'; // X-VF-REST-USER , see docs
$token = 'siirtoavain'; // {SIIRTOAVAIN} , see docs
$resource = 'tehtavan_kommentti'; // {REST_resurssi} , see docs
$client = Client::build($customer, $token, $resource);
try {
$response = $client->get('');
var_dump($response->getStatusCode());
var_dump(json_decode($response->getBody()->getContents()));
} catch (BadResponseException $exception) {
var_dump($exception->getResponse()->getStatusCode());
var_dump(json_decode($exception->getResponse()->getBody()->getContents()));
}
We highly recommend that you use "proper" IDE to development your application. Below is short list of some popular IDEs that you could use.
It's highly recommended that you use this tool while doing actual development
to application. PHP Code Sniffer is added to project dev
dependencies, so
all you need to do is just configure it to your favorite IDE. So the phpcs
command is available via following example command.
./vendor/bin/phpcs -i
If you're using PhpStorm following links will help you to get things rolling.
Library uses PHPUnit for testing. You can run all tests by following command:
./vendor/bin/phpunit
Or you could easily configure your IDE to run those for you.
Library uses PhpMetrics to make static analyze of its code. You can run this by following command:
./vendor/bin/phpmetrics --junit=build/logs/junit.xml --report-html=build/phpmetrics .
And after that open build/phpmetrics/index.html
with your favorite browser.
Copyright (c) 2018 Pinja