A laravel package for generating Bitly short URLs.

Overview

Laravel Bitly Package

A laravel package for generating Bitly short URLs.

For more information see Bitly

Build Status Latest Stable Version License Total Downloads Coverage Status

Requirements

Laravel 5.1 or later

Installation

Installation is a quick 3 step process:

  1. Download laravel-bitly using composer
  2. Enable the package in app.php
  3. Configure your Bitly credentials
  4. (Optional) Configure the package facade

Step 1: Download laravel-bitly using composer

Add shivella/laravel-bitly by running the command:

composer require shivella/laravel-bitly

Step 2: Enable the package in app.php

Register the Service in: config/app.php

Shivella\Bitly\BitlyServiceProvider::class,

Step 3: Configure Bitly credentials

php artisan vendor:publish --provider="Shivella\Bitly\BitlyServiceProvider"

Add this in you .env file

BITLY_ACCESS_TOKEN=your_secret_bitly_access_token

Step 4 (Optional): Configure the package facade

Register the Bitly Facade in: config/app.php



return [
    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        // ...
        'Bitly' => Shivella\Bitly\Facade\Bitly::class,
    ],
    // ...
];

Usage



$url = app('bitly')->getUrl('https://www.google.com/'); // http://bit.ly/nHcn3

Or if you want to use facade, add this in your class after namespace declaration:



use Bitly;

Then you can use it directly by calling Bitly:: like:



$url = Bitly::getUrl('https://www.google.com/'); // http://bit.ly/nHcn3

Testing

In your unit tests you may use BitlyClientFake class instead of regular client. It will create a fake short URLs using hashing without calling an external REST API, which will speed up your unit tests. Fake might be setup via DI at your \Tests\TestCase::createApplication() implementation:



namespace Tests;

use Illuminate\Contracts\Console\Kernel;
use Shivella\Bitly\Testing\BitlyClientFake;

trait CreatesApplication
{
    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        // swap Bitly client by a fake
        $app->singleton('bitly', function () {
            return new BitlyClientFake();
        });

        return $app;
    }
}

As an alternative you may use \Shivella\Bitly\Facade\Bitly::fake() method to swap regular client by a fake.

Comments
  • Switch API endpoint to /v3/shorten

    Switch API endpoint to /v3/shorten

    The correct endpoint is /v3/shorten, not /v3/link/lookup. Using the latter will result in errors for links that have never been shortened (by anyone on Bitly).

    opened by trevorgehman 5
  • Call to a member function getStatusCode() on null

    Call to a member function getStatusCode() on null

    Hi,

    I performed all the necessary steps with a laravel 8 environment. I get this message when I run $bitlyUrl = app('bitly')->getUrl($curr_url);

    Call to a member function getStatusCode() on null

    When I try with the second solution : use Bitly; $url = Bitly::getUrl('https://www.google.com/'); // http://bit.ly/nHcn3

    I have an error in the editor : Non static method 'getUrl' should not be called statically

    any idea? Thanks

    opened by foutesting 3
  • Analytics or Clicks

    Analytics or Clicks

    Hello Shivella,

    I want to commend you for such a great package. It works great! I wanted to find out if there is a way to track clicks or get the analytics from the bitly API?

    Also, one thing I noticed was that when a URL has already been processed (shortened) and for some reason, you fire the shortened event again on the same URL, it returns the below:

    message: "Client error: POST https://api-ssl.bitly.com/v4/shorten resulted in a 400 Bad Request response:↵{"message":"ALREADY_A_BITLY_LINK","resource":"bitlinks","description":"The value provided is invalid.","errors":[{"field (truncated...)↵"

    Thank you and hoping to hear from you soon.

    opened by VimKanzoGH 3
  • Added project facade and updated README.md with how to use it

    Added project facade and updated README.md with how to use it

    Hi! How are you?

    I found your package today and I really liked it. But at the same time that it was the first time that I saw a project using this way to call a lib app('bitly'), I thought that it's better to deliver the facade "option" for those who prefer to use it (personally, I prefer to use only facades if I can because it sounds me better using this to organize what I'm using in my classes). So I hope you enjoy my simple code!

    Thanks at all! See you! :smiley:

    opened by viniciusls 3
  • InvalidResponseException('The response does not contain a aggregate link');

    InvalidResponseException('The response does not contain a aggregate link');

    Good work on the package.

    But I only get valid for some links but I can't get the same for all my link atempts. I get the exception "The response does not contain a aggregate link"

    What might be causing this exception?

    Thanks for your response

    opened by fbownz 3
  • Can't install with Laravel 9

    Can't install with Laravel 9

    sail composer require shivella/laravel-bitly throws:

    Problem 1
        - shivella/laravel-bitly[1.1.0, ..., 1.1.1] require illuminate/support ^5.1 -> found illuminate/support[v5.1.1, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
        - shivella/laravel-bitly 1.1.2 requires illuminate/support ^5.1 || ^6.0 -> found illuminate/support[v5.1.1, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev] but these were not loaded, likely because it conflicts with another require.
        - shivella/laravel-bitly[1.1.3, ..., 1.1.5] require illuminate/support ^5.8 || ^6.0 -> found illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev] but these were not loaded, likely because it conflicts with another require.
        - shivella/laravel-bitly[1.1.6, ..., 1.1.7] require illuminate/support ^5.8 || ^6.0 || ^7.0 -> found illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but these were not loaded, likely because it conflicts with another require.
        - shivella/laravel-bitly[1.1.8, ..., 1.1.11] require illuminate/support ^5.8 || ^6.0 || ^7.0 || ^8.0 -> found illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
        - Root composer.json requires shivella/laravel-bitly ^1.1 -> satisfiable by shivella/laravel-bitly[1.1.0, ..., 1.1.11].
    

    Any idea how to fix this?

    opened by basvandertogt 2
  • Update to work with Laravel 8.x

    Update to work with Laravel 8.x

    Hi,

    The latest Laravel version wants guzzle ^7.0.1:

    https://github.com/laravel/laravel/blob/c6c41f11b8ea3065f035fbb6a6f570b7bfba0037/composer.json#L14

    But the current version of the library has:

    https://github.com/Shivella/laravel-bitly/blob/69b80608e7c489acf6812078f22fb7372a72b11f/composer.json#L31

    So when trying to run a composer update we get:

        - Installation request for laravel/framework ^8.0 -> satisfiable by laravel/framework[8.x-dev, v8.0.0, v8.0.1, v8.0.2, v8.0.3, v8.0.4, v8.1.0, v8.2.0].
        - Installation request for shivella/laravel-bitly ^1.0 -> satisfiable by shivella/laravel-bitly[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.0.8, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7].
        - Can only install one of: guzzlehttp/guzzle[7.0.1, 6.5.x-dev].
        - Can only install one of: guzzlehttp/guzzle[7.0.x-dev, 6.5.x-dev].
        - Can only install one of: guzzlehttp/guzzle[7.1.x-dev, 6.5.x-dev].
        - Conclusion: install guzzlehttp/guzzle 6.5.x-dev
        - Installation request for guzzlehttp/guzzle ^7.0.1 -> satisfiable by guzzlehttp/guzzle[7.0.1, 7.0.x-dev, 7.1.x-dev].
    

    An easy fix will probably change it to "^7.0.1".

    opened by falsovsky 2
  • throw exception on rate limit

    throw exception on rate limit

    I had to create around 1500 links at once, but it threw an exception that didn't show me why. So I added this rate limit check, so you know when you've reached it.

    opened by sweebee 2
  • cURL error 60: SSL certificate problem

    cURL error 60: SSL certificate problem

    Hello, I have this error: InvalidResponseException in BitlyClient.php line 79: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

    Does anyone know why this error occurs? Thanks.

    opened by gabohm 2
  • Simplify project directory structure

    Simplify project directory structure

    Project directory structure is overcomplicated without purpose.

    The 'src' directory contains redundant folders "Shivella" / "Bitly" before getting to the actual source files. The same happens in "Tests" directory.

    Instead of usage "psr-0" in composer and redundant folders it is better to switch to "psr-4" removing extra folders in the path:

    {
        "autoload": {
            "psr-4": {
                "Shivella\Bitly\\": "src"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "Shivella\Bitly\\Test\\": "Tests"
            }
        },
    }
    

    Note: such changeset should be applied after other PRs are processed.

    opened by klimov-paul 1
  • Upgraded Bitly API to V4

    Upgraded Bitly API to V4

    I have upgraded the API endpoint to the V4 version, because the V3 API will be deactivated on March 2020.

    The new API is using header token as its authentication method; therefore I have moved the token to the request header. The new API also returns a different json response, therefore I have updated the response.json for testing.

    opened by jonathan-lewerissa 1
Releases(1.1.13)
Owner
Wessel Strengholt
Webdeveloper using PHP, Symfony, React and Redux
Wessel Strengholt
A Laravel package to shorten urls

Laravel Short Url Laravel Short Url is a package allowing you to shorten urls. Installation With composer composer require gallib/laravel-short-url t

Alain Pellaux 153 Dec 16, 2022
Enables the possibility generating sanitized URL parts from persisted patterns.

#Persisted sanitized pattern mapping What does it do? Enables the possibility generating sanitized URL parts from persisted patterns. How does it work

Markus Hofmann 1 Apr 7, 2022
A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain.

A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain. Table of Contents Full documentation Dock

null 1.7k Dec 29, 2022
Create and validate signed URLs with a limited lifetime

THIS PACKAGE IS NOT MAINTAINED ANYMORE. SIGNING URLS IS NOW PART OF LARAVEL: https://laravel-news.com/signed-routes Create secured URLs with a limited

Spatie 652 Dec 31, 2022
A simple PHP library to parse and manipulate URLs

Url is a simple library to ease creating and managing Urls in PHP.

The League of Extraordinary Packages 351 Dec 30, 2022
A fast and powerful URL Shortener built with Laravel, VueJS, and Tailwind CSS.

A fast and powerful URL Shortener built with Laravel, VueJS, and Tailwind CSS.

Devpri 53 Dec 25, 2022
Simpler Url Shortener for Laravel

Laravel Url Shortener Install composer require magarrent/laravel-url-shortener Run migrations: php artisan migrate Configuration If you want to config

Marc Garcia Torrent 51 Dec 17, 2022
Laravel URL Localization Manager - [ccTLD, sub-domain, sub-directory].

Laravel URL Localization - (ccTLD, sub-domain, sub-directory). with Simple & Easy Helpers. Afrikaans Akan shqip አማርኛ العربية հայերեն অসমীয়া azərbayca

Pharaonic 2 Aug 7, 2022
URL shortener web application based on the Laravel PHP Framework.

UrlHub Warning: UrlHub is still in development, constantly being optimized and isn't still stable enough to be used in production environments. Whatev

Kei 349 Jan 4, 2023
URL shortener web application based on the Laravel PHP Framework.

UrlHub Warning: UrlHub is still in development, constantly being optimized and isn't still stable enough to be used in production environments. Whatev

Kei 348 Dec 23, 2022
Laravel based API to shorten URLs and share them easily. Redirects to the real URL by entering a short URL generated by the API

URL Shortener Requirements: PHP 7.4 or above composer node / npm Installation clone the project from the Github repository, enter the project folder,

Julio Vergara 5 Nov 20, 2021
Michael Pratt 307 Dec 23, 2022
A suit of basic files samples to build a light-weight , short-handed & a strong Laravel REST API Applications.

Concerning Laravel. I found myself repeating a very basic form of code each time i begin a new REST API. in which the whole Interface's pieces are dev

Adnane Kadri 1 Nov 22, 2021
TweetNow is a Twitter clone created with Vue.js and Laravel. It is a social media platform that allows users to post short messages, follow other users, and engage in conversations through comments and likes.

TweetNow TweetNow is a opensource social media created with Vue.js+Inertia SSR and Laravel. It is a social media platform that allows users to post sh

I.E.U. Juboraj Naofel 12 Jun 16, 2023
30 seconds of code Short PHP code snippets for all your development needs

30 seconds of code Short PHP code snippets for all your development needs Visit our website to view our snippet collection. Use the Search page to fin

30 seconds of code 2.5k Jan 1, 2023
🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.

Termwind Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS

Nuno Maduro 1.8k Dec 30, 2022
A PHP library for counting short DNA sequences for use in Bioinformatics

Helix A PHP library for counting short DNA sequences for use in Bioinformatics. Helix consists of tools for data extraction as well as an ultra-low me

Andrew DalPino 2 Jan 25, 2022
Shortener URL is simple web application to short your URL

Shortener URL is simple web application to short your URL. It will generate unique key, with the unique key it will redirect to the original URL.

Abid Ra 1 Jan 22, 2022
Yii Aliases - store path aliases, i.e. short name representing a long path

Yii Aliases The package aim is to store path aliases, i.e. short name representing a long path (a file path, a URL, etc.). Path alias value may have a

Yii Software 20 Nov 8, 2022
Medical Master or "Medic-M" was built to reduce the hassle of buying medicine, provide medicine to the sick in a short time. It is an HTML, CSS, JAVASCRIPT and PHP based system.

Medical Master (Medic-M) | WELCOME TO Medic-M(MEDICAL MASTER) | | Introduction | Medical Master or "Medic-M" was built to reduce the hassle of buying

NILOY KANTI PAUL 5 Oct 8, 2022