PHPackages                             vdhicts/hihaho-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. vdhicts/hihaho-api-client

ActiveLibrary[API Development](/categories/api)

vdhicts/hihaho-api-client
=========================

A client for the API of HiHaHo

v8.0.0(2mo ago)018.1k↓50%MITPHPPHP &gt;=8.2CI passing

Since Nov 29Pushed 2mo agoCompare

[ Source](https://github.com/vdhicts/hihaho-api-client)[ Packagist](https://packagist.org/packages/vdhicts/hihaho-api-client)[ Docs](https://github.com/vdhicts/hihaho-api-client)[ RSS](/packages/vdhicts-hihaho-api-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (12)Versions (11)Used By (0)

HiHaHo API Client
=================

[](#hihaho-api-client)

Easy HiHaHo REST API client.

Not all endpoints are currently implemented, feel free to add them or create an issue when you need help implementing the endpoint. It's also possible to extend the client.

Requirements
------------

[](#requirements)

This package requires at least PHP 8.2.

Installation
------------

[](#installation)

This package can be used in any PHP project or with any framework.

You can install the package via composer:

`composer require vdhicts/hihaho-api-client`

Usage
-----

[](#usage)

This package is just an easy client for using the HiHaHo API. Please refer to the [API documentation](https://api-docs.hihaho.com/) for more information about the requests.

### Getting started

[](#getting-started)

```
// Initialize the configuration
$configuration = new \Vdhicts\HiHaHo\Configuration(
    ..
);

// Initialize the API
$api = new \Vdhicts\HiHaHo\HiHaHo($configuration);

// Get all videos
$response = $api->allVideos();

if ($response->ok()) {
    $response->json('data');
}
```

### Authentication

[](#authentication)

This package will automatically retrieve the access token, so you won't have to store the access token. If you want to store the access/refresh token anyway, you can access it in the `Configuration` class with: `$configuration->getAccessToken()` or `$configuration->getRefreshToken()`.

### Extending the client

[](#extending-the-client)

You can extend the client and implement your own endpoints:

```
class Video extends HiHaHo
{
    public function updateVideo(int $videoId): Response
    {
        return $this
            ->withToken($this->getAccessToken())
            ->put(sprintf('v2/video/%d', $videoId), [
                'status' => 0,
            ]);
    }
}
```

### Handling errors

[](#handling-errors)

A `Response` object will always be returned. See [Error handling](https://laravel.com/docs/8.x/http-client#error-handling) of the Http Client.

```
if ($response->failed()) {
    var_dump($response->serverError());
}
```

### Laravel

[](#laravel)

This package can be easily used in any Laravel application. I would suggest adding your credentials to the `.env` file of the project:

```
HIHAHO_CLIENT_ID=clientid
HIHAHO_CLIENT_SECRET=secret
HIHAHO_USERNAME=username
HIHAHO_PASSWORD=password

```

Next create a config file `hihaho.php` in `/config`:

```
