2017 © Pedro Peláez
 

library redtube-api

PHP based API wrapper for Redtube HTTP API

image

realshadow/redtube-api

PHP based API wrapper for Redtube HTTP API

  • Monday, December 4, 2017
  • by realshadow
  • Repository
  • 2 Watchers
  • 3 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 17 % Grown

The README.md

Scrutinizer Code Quality Build Status, (*1)

Redtube API

PHP based API wrapper for Redtube HTTP API ., (*2)

All methods except getStarDetailedList are supported. This method at the time of writing always ends with an There are no stars! error., (*3)

Installation

composer require realshadow/redtube-api

Usage

Every method returns either a concrete object representing the response or collection of objects. Methods used for filtering videos return a Paginator object which contains all videos and basic informating about paging (current page, total count, last page, etc.)., (*4)

// Create new API client (default host points to https://api.***)
$redtube = new \Realshadow\Redtube\Redtube;

/**
 * Get all categories
 *
 * @return Collection<Category>
 */
$redtube->categories->getAll();

/**
 * Get all stars
 *
 * @return Collection<Star>
 */
$redtube->stars->getAll();

/**
 * Get all tags
 *
 * @return Collection<Tag>
 */
$redtube->tags->getAll();

/**
 * Find videos
 *
 * @return Paginator
 */
$redtube->videos->findBy($filter);

/**
 * Find video by its ID
 *
 * @return Video
 */
$redtube->videos->findById($id);

/**
 * Find out if a video is active
 *
 * @return bool
 */
$redtube->videos->isActive($id);

/**
 * Get embed code of a video
 *
 * @return string
 */
$redtube->videos->getEmbedCode($id);

/**
 * Find deleted videos
 *
 * @return Paginator
 */
$redtube->videos->findDeletedBy($filter);

Video filter

Videos can be filtered by using the VideoFilter class which provides fluent interface. You can use one of three enumerators to ease filtering - Period, OrderBy, Thumbsize., (*5)

Note: Redtube does not use traditional limit/offset queries but filtering by page. Each page contains 20 results., (*6)

For example, (*7)

$filter = VideoFilter::create()
    ->page(1)
    ->search('lesbian')
    ->tags(['blonde'])
    ->stars(['Jenna Jameson'])
    ->thumbsize(Thumbsize::BIG)
    ->period(Period::ALL_TIME)
    ->orderBy(OrderBy::RATING);

$videos = $redtube->videos->findBy($filter);

Get all active / deleted videos

If you want to retrieve more than one page (more than 20 videos) at once you can use these methods, (*8)

/**
 * Find all videos up to 10th page
 *
 * @return Generator
 */
$redtube->videos->findAllBy($filter, 10);

/**
 * Find deleted videos up to the 10th page
 *
 * @return Generator
 */
$redtube->videos->findAllDeletedBy($filter, 10);

Both methods return a generator after each page is requested to ease memory allocation. So the full usage example would be, (*9)

foreach ($redtube->videos->findAllBy($filter, 10) as $videos) {
    /** @var Illuminate\Support\Collection $videos */

    $videos->each(function (Video $video) {
        // rest of the code
    });
}

Exceptions

All of the error codes listed in documentation are transformed into PHP exceptions by using this mapping, (*10)

  • error code 1001 => NoSuchMethodException
  • error code 1002 => NoSuchDataProviderException
  • error code 1003 => NoInputParametersSpecifiedException
  • rest of the error codes will use NotFoundException with appropiate message

For example, (*11)

try {
    $videos = $redtube->videos->findBy($filter);
} catch (NotFoundException $e) {

}

The Versions

04/12 2017

dev-master

9999999-dev

PHP based API wrapper for Redtube HTTP API

  Sources   Download

MIT

The Requires

 

The Development Requires

04/12 2017

1.0.2

1.0.2.0

PHP based API wrapper for Redtube HTTP API

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2017

1.0.1

1.0.1.0

PHP based API wrapper for Redtube HTTP API

  Sources   Download

MIT

The Requires

 

The Development Requires

07/07 2017

1.0.0

1.0.0.0

PHP based API wrapper for Redtube HTTP API

  Sources   Download

MIT

The Requires

 

The Development Requires