northern-lights/polr-client

Client for Polr API

1.0.1 2019-02-22 14:12 UTC

This package is auto-updated.

Last update: 2024-04-23 01:35:38 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version Maintainability Semantic Versioning License

Introduction

REST API client written in PHP for cydrobolt/polr

Provides simple interface for interaction with Polr instances

Usage

Very minimal example, using default configuration

<?php

namespace NorthernLights\Client\Polr\Example;

use NorthernLights\Client\Polr\ApiClient;
use NorthernLights\Client\Polr\Config\Config;
use NorthernLights\Client\Polr\Response\ShortenResponseInterface;


/**
 * Initialize API client and pass $config to it (DI)
 * @var ApiClient $api
 */
$api = new ApiClient();

/**
 * Shorten the long URL.
 * @var ShortenResponseInterface $response
 */
$response = $api->shorten('https://www.polrproject.org');

// Check if API request was successful. Remains true as long as HTTP status code equals 200 OK
if (!$response->wasSuccessful()) {
    echo 'There was an error querying the api' . PHP_EOL;
    exit(1);
}

echo 'Short URL is ' . $response->getShortUrl() . PHP_EOL;

For more detailed examples and configuration, please take a look in examples. All use scenarios are covered.

Installation

The recommended way to install is via Composer:

composer require northern-lights/polr-client

Alternatively, you can download latest stable version from releases.

Please note that this library doesn't ship with autoloader, but relies on Composer internal autoloader.

Industry standards and best practices

Library strives to comply with latest standards and best practices in the industry therefore we included

PSR-2 coding standard Compliance check & fix

We want the code to be as good as it is possible

$ composer check-style
$ composer fix-style

Note: Second command will actually modify files

Code syntax check (lint)

Very basic check which saves us the trouble

$ composer php-lint

Static Code Analysis

So we catch bugs early.

$ composer phpsam

Unit testing

So we make sure that all moving parts are running smoothly

$ composer test

TODO

Disclaimer

This project or it's authors are not affiliated with the Polr Project or any third party.

License

The MIT License (MIT). Please see License File for more information.