koel/app/Http/Controllers/API/LastfmController.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2015-12-20 12:17:35 +00:00
<?php
namespace App\Http\Controllers\API;
use App\Http\Requests\API\LastfmSetSessionKeyRequest;
2020-09-06 18:21:39 +00:00
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;
2017-06-04 01:30:45 +00:00
use Illuminate\Http\JsonResponse;
2015-12-20 12:17:35 +00:00
/**
* @group Last.fm integration
*/
2015-12-20 12:17:35 +00:00
class LastfmController extends Controller
{
2020-09-06 18:21:39 +00:00
/** @var User */
private $currentUser;
public function __construct(?Authenticatable $currentUser)
2018-09-04 06:25:24 +00:00
{
2020-09-06 18:21:39 +00:00
$this->currentUser = $currentUser;
2015-12-20 12:17:35 +00:00
}
2016-01-26 06:32:29 +00:00
/**
* Set Last.fm session key
*
* Set the Last.fm session key for the current user. This call should be made after the user is
* [connected to Last.fm](https://www.last.fm/api/authentication).
*
* @bodyParam key string required The Last.fm [session key](https://www.last.fm/api/show/auth.getSession).
* @response []
2016-01-26 15:23:55 +00:00
*
2017-06-04 01:30:45 +00:00
* @return JsonResponse
2016-01-26 06:32:29 +00:00
*/
public function setSessionKey(LastfmSetSessionKeyRequest $request)
2016-01-26 06:32:29 +00:00
{
2020-09-06 18:21:39 +00:00
$this->currentUser->savePreference('lastfm_session_key', trim($request->key));
2016-01-26 06:32:29 +00:00
return response()->json();
}
2015-12-20 12:17:35 +00:00
/**
* Disconnect the current user from Last.fm
2016-03-06 04:11:28 +00:00
*
2017-06-04 01:30:45 +00:00
* @return JsonResponse
2015-12-20 12:17:35 +00:00
*/
public function disconnect()
{
2020-09-06 18:21:39 +00:00
$this->currentUser->deletePreference('lastfm_session_key');
2018-09-04 02:25:34 +00:00
return response()->json();
2015-12-20 12:17:35 +00:00
}
}