bramalho/laravel-bitly-client

Laravel Bitly Client Package

v1.0.0 2018-06-23 17:54 UTC

This package is auto-updated.

Last update: 2024-11-13 02:27:47 UTC


README

Latest Stable Version Total Downloads License

Laravel Bitly Client is a Laravel package that provide a simple client for the Bitly URL shorten.

Installation

Install the package

composer require bramalho/laravel-bitly-client

Add the service provider in config/app.php

BRamalho\LaravelBitlyClient\LaravelBitlyClientServiceProvider::class,

Publish the configs

php artisan vendor:publish --provider 'BRamalho\LaravelBitlyClient\LaravelBitlyClientServiceProvider'

Add your Bitly credentials in your .env file

BITLY_LOGIN=your_api_login
BITLY_API_KEY=your_api_key

Usage

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use BRamalho\LaravelBitlyClient\BitlyClient;
use BRamalho\LaravelBitlyClient\InvalidCredentialsException;
use BRamalho\LaravelBitlyClient\UnableToGenerateURLException;

class HomeController extends Controller
{
    /**
     * @return array
     * @throws InvalidCredentialsException
     * @throws UnableToGenerateURLException
     */
    public function index()
    {
        $bitlyClient = new BitlyClient();

        return $bitlyClient->generate('https://brunoramalho.com');
    }
}

This will return something like:

[
    'url' => 'http://bit.ly/2KiTbFW',
    'hash' => '2KiTbFW',
    'global_hash' => '2KiTbWs',
    'long_url' => 'https://brunoramalho.com/'
    'new_hash' => 0
]

License

The Laravel Bitly Client is open-sourced software licensed under the MIT license.