netflex/api

Netflex API library

Maintainers

Details

github.com/netflex-sdk/api

Source

Installs: 3 979

Dependents: 14

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

v5.2.4 2024-11-22 14:58 UTC

This package is auto-updated.

Last update: 2024-12-17 12:28:34 UTC


README

Stable version Build status License: MIT Contributors Downloads

[READ ONLY] Subtree split of the Netflex API component (see netflex/api)

A library for working with the Netflex API.

Documentation

Table of contents

Installation

1. Setup

composer require netflex/api

Note: If you are using Netflex SDK 2.0 or later, or Laravel 5.5, the steps 2 and 3, for providers and aliases, are unnecessaries. Netflex API supports Package Discovery.

2. Provider

You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your config/app.php file adding the following code at the end of your 'providers' section:

config/app.php

<?php

return [
    // ...
    'providers' => [
        Netflex\API\Providers\APIServiceProvider::class,
        // ...
    ],
    // ...
];

3. Facades

You may get access to the Netflex API using following facades:

  • Netflex\API\Facades\API

You can setup a short-version aliases for these facades in your config/app.php file. For example:

<?php

return [
    // ...
    'aliases' => [
        'API'   => Netflex\API\Facades\API::class,
        // ...
    ],
    // ...
];

4. Configuration

Publish config

In your terminal type

php artisan vendor:publish

or

php artisan vendor:publish --provider="Netflex\API\Providers\APIServiceProvider"

Alternatively, you can create the config file manually, under config/api.php, see example here.

Standalone usage

Netflex API can be used standalone as well.

<?php

use Netflex\API\Client;

$client = new Client([
  'auth' => ['publicKey', 'privateKey']
]);

Testing

For testing purposes, use the provided Netflex\API\Testing\MockClient implementation. This can be used with the Facade, so you don't have to modify your code while testing.

To bind the MockClient into the container, register the Netflex\API\Testing\Providers\MockAPIServiceProvider provider.

Example:

<?php

use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;

use Netflex\API\Facades\API;
use Netflex\API\Testing\Providers\MockAPIServiceProvider;

use GuzzleHttp\Psr7\Response;

$container = new Container;

Facade::setFacadeApplication($container);

// Register the service provider
(new MockAPIServiceProvider($container))->register();

// The container binding is now registered, and you can use the Facade.

API::mockResponse(
  new Response(
    200,
    ['Content-Type' => 'application/json'],
    json_encode(['hello' => 'world'])
  )
);

$response = API::get('/'); // Returns the mocked response

echo $response->hello; // Outputs 'world'