Coder Social home page Coder Social logo

laravel-giphy's Introduction

Laravel Giphy

LARAVEL GIPHY

Laravel Giphy is a Giphy API wrapper for Laravel (and Lumen but ssh, don't tell anyone), providing an easy to access Giphy facade.

Installation

To use this package without running in to trouble you will need PHP 5.5+ or HHVM 3.6+, and Composer.

  1. Get the latest version of Laravel Giphy, add the following line to your composer.json file

    "hiddeco/laravel-giphy": "0.1.*@alpha"

  2. Run composer update or composer install

  3. Register the Laravel Giphy service provider in config/app.php by adding 'HiddeCo\Giphy\GiphyServiceProvider to the providers key

  4. Add the Giphy facade to the aliases key: 'Giphy' => 'HiddeCo\Giphy\Facades\Giphy'

Configuration

The only configuration Laravel Giphy needs is a GIPHY_API_KEY in your .env file. A public beta key is available in the Giphy API Documentation.

Note: On Laravel it is also possible to configure Laravel Giphy by running php artisan config:publish and adding your apiKey to config/giphy.php.

Injecting Giphy

Injecting Giphy in to a controller could not have been any easier.

<?php

class GifController extends BaseController {

	public function __construct(HiddeCo\Giphy\Giphy $giphy)
    {

		$this->giphy = $giphy;

	}

  	public function get($id)
   	{
		try
		{

			return $this->giphy->gif()->random([ 'fmt' => 'html' ]);
		}
		catch (\Exception $e)
		{

			return $e->getMessage();
		}
    }
}

The API

Using this package to communicate with the Giphy API is fairly simple by using the Giphy facade.

Giphy: GIFs

Do you want to find a sweet GIF based on a keyword, translate a keyword to just one GIF or just get a random GIF? It is all possible.

Giphy::gif->search($query, $params = [])

Searches all GIFs for the provided word or phrase and accepts 4 optional parameters as array.

  • limit: default 25 (max: 100)
  • offset
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::gif()->search('code', [limit' => 10, 'offset' => 10, 'rating' => 'g', 'fmt' => 'html']);

Gipgy::gif()->get($id)

Returns JSON meta data about a GIF by id.

Giphy::gif()->get('4hnQDVKVARZ6w');

Giphy::gif()->getMultiple($ids = [])

Returns JSON meta data about mulitple GIFs by id.

Giphy::gif()->getMultiple(['4hnQDVKVARZ6w', 'Ro2MgOxH9iaVG']);

Giphy::gif()->translate($query, $params = [])

Returns a GIF from the Giphy 'translation engine', enter a keyword and get a GIF translation back. Accepts 2 optional parameters.

  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::gif()->translate($query, ['rating' => 'g', 'fmt' => 'html']);

Giphy::gif()->random($params = [])

Returns a random GIF, limitation is possible by using the following optional parameters.

  • tag: get a random GIF based on the keyword
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::gif()->random(['tag' => 'cats', 'rating' => 'g', 'fmt' => 'html']);

Giphy::gif()->trending($params = [])

Returns currently trending GIFs on the internet. Accepts 3 optional parameters.

  • limit: default 25 (max: 100)
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::gif()->trending(['limit' => 100, 'rating' => 'pg', 'fmt' => 'html');

Giphy: Stickers

Giphy stickers are animated stickers (animated GIFs with transparent backgrounds).

Giphy::sticker()->search($query, $params = [])

Searches all sticker GIFs for the provided word or phrase and accepts 4 optional parameters as array.

  • limit: default 25 (max: 100)
  • offset
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::sticker()->search('code', [limit' => 10, 'offset' => 10, 'rating' => 'g', 'fmt' => 'html']);

Giphy::sticker()->translate($query, $params = [])

Returns a sticker GIF from the Giphy 'translation engine', enter a keyword and get a sticker GIF translation back. Accepts 2 optional parameters.

  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::sticker()->translate($query, ['rating' => 'g', 'fmt' => 'html']);

Giphy::sticker()->random($params = [])

Returns a random sticker GIF, limitation is possible by using the following optional parameters.

  • tag: get a random GIF based on the keyword
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::sticker()->random(['tag' => 'cats', 'rating' => 'g', 'fmt' => 'html]);

Giphy::sticker()->trending($params = [])

Returns currently trending sticker GIFs on the internet. Accepts 3 optional parameters.

  • limit: default 25 (max: 100)
  • rating: limit results by rating (y,g, pg, pg-13 or r)
  • fmt: returned format, json or html (default: json)
Giphy::sticker()->trending(['limit' => 100, 'rating' => 'pg', 'fmt' => 'html']);

License

Laravel Giphy is licensed under the MIT License (MIT).

laravel-giphy's People

Contributors

hiddeco avatar arall avatar

Watchers

James Cloos avatar Anthony  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.