Skip to content

Abstraction of generic API calls that are used across multiple possibly dissimilar applications.

License

Notifications You must be signed in to change notification settings

fintech-systems/api-helpers

Repository files navigation

Laravel API Helpers

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.

About

Abstraction of generic API calls that are used across multiple possibly dissimilar applications.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published