What is this
, (*1)
Simple library for ValueFrame REST API., (*2)
Basically this is a wrapper for guzzlehttp/guzzle - this library
just adds necessary headers to each request., (*3)
Table of Contents
Requirements
Installation
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., (*4)
# Install Composer
curl -sS https://getcomposer.org/installer | php
You can add this library as a dependency to your project using following command:, (*5)
composer require protacon/vf-rest
After installing, you need to require Composer's autoloader:, (*6)
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., (*7)
Usage
First of all you should read official documentation
about ValueFrame REST API., (*8)
Simple usage example:, (*9)
<?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()));
}
Development
IDE
We highly recommend that you use "proper"
IDE
to development your application. Below is short list of some popular IDEs that
you could use., (*10)
PHP Code Sniffer
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., (*11)
./vendor/bin/phpcs -i
If you're using PhpStorm following links
will help you to get things rolling., (*12)
Testing
Library uses PHPUnit for testing. You can run all tests
by following command:, (*13)
./vendor/bin/phpunit
Or you could easily configure your IDE to run those for you., (*14)
Metrics
Library uses
PhpMetrics
to make static analyze of its code. You can run this by following command:, (*15)
./vendor/bin/phpmetrics --junit=build/logs/junit.xml --report-html=build/phpmetrics .
And after that open build/phpmetrics/index.html with your favorite browser., (*16)
Authors
Tarmo LeppÀnen, (*17)
License
The MIT License (MIT), (*18)
Copyright (c) 2018 Pinja, (*19)