protacon/vf-rest

ValueFrame REST API component

0.5.0 2023-04-19 10:34 UTC

This package is auto-updated.

Last update: 2024-03-19 12:43:28 UTC


README

MIT licensed Total Downloads Latest Stable Version Latest Unstable Version

Simple library for ValueFrame REST API.

Basically this is a wrapper for guzzlehttp/guzzle - this library just adds necessary headers to each request.

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.

# 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.

Usage

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()));
}

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.

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.

./vendor/bin/phpcs -i

If you're using PhpStorm following links will help you to get things rolling.

Testing

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.

Metrics

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.

Authors

Tarmo Leppänen

License

The MIT License (MIT)

Copyright (c) 2018 Pinja