fintech-systems/laravel-api-helpers

Various helpers to make interacting with APIs easier

v0.1.5 2022-08-19 13:18 UTC

This package is auto-updated.

Last update: 2024-04-20 16:01:53 UTC


README

Latest Stable Version GitHub Tests Action Status GitHub Code Style Action Status Total Downloads GitHub license

A helper library to facilitate working with APIs

API: Get, Post, Delete

public function get(string $url, array $header = [])

public function post(string $url, string|array $postFields, array $header = [])

public function delete(string $url, string|array $postFields = '', array $header = [])

Laravel API Helper Command - facilitates caching JSON API responses

Example:

class UserCommand extends LaravelApiHelpersCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'api:get-users {--cached}';

    ...

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        if ($file = $this->checkCachedFileExists()) {
            $this->info('A cached API result file was returned');

            return $file;
        }

        $result = file_put_contents($this->cachedFile, Api::getUsers());
        $this->info('The API command was successful');

        return $result;
    }

Installation

You can install the package via composer:

composer require fintech-systems/laravel-api-helpers

Usage

WhatsApp to WHMCS phone number conversion

$api = new Api();
$result = $api->convertWhatsAppNumberToWhmcsPhoneNumber('27823096710');
expect($result)->toEqual('+27.82 309 6710');

$api = new Api();
$result = $api->convertWhatsAppNumberToWhmcsPhoneNumber('14085551234');
expect($result)->toEqual('+1.408-555-1234');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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