[READ ONLY] Subtree split of the Netflex API component (see netflex/api)
A library for working with the Netflex API.
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.
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,
// ...
],
// ...
];
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,
// ...
],
// ...
];
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.
Netflex API can be used standalone as well.
<?php
use Netflex\API\Client;
$client = new Client([
'auth' => ['publicKey', 'privateKey']
]);
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.
<?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'