ajout heimdall
This commit is contained in:
83
heimdall/config/www/SupportedApps/WaniKani/WaniKani.php
Executable file
83
heimdall/config/www/SupportedApps/WaniKani/WaniKani.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php namespace App\SupportedApps\WaniKani;
|
||||
|
||||
class WaniKani extends \App\SupportedApps implements \App\EnhancedApps {
|
||||
|
||||
public $config;
|
||||
|
||||
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
||||
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
|
||||
|
||||
function __construct() {
|
||||
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to obtain user information to test login
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$api_token = $this->config->username;
|
||||
$attrs = [
|
||||
'headers' => ['Authorization' => 'Bearer '.$api_token]
|
||||
];
|
||||
return parent::execute($this->url('user'), $attrs, false, 'GET');
|
||||
}
|
||||
|
||||
/**
|
||||
* "Login" the user and return the username
|
||||
*/
|
||||
public function test()
|
||||
{
|
||||
$test = $this->login();
|
||||
if($test->getStatusCode() === 200 && $test->getBody()) {
|
||||
$wk_resp = json_decode($test->getBody());
|
||||
echo "Hello ".$wk_resp->data->username;
|
||||
} else {
|
||||
echo "Failed";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the user summary and return the total of Reviews and Lessons
|
||||
*/
|
||||
public function livestats()
|
||||
{
|
||||
$status = 'inactive';
|
||||
$now = \Carbon\Carbon::now();
|
||||
$api_token = $this->config->username;
|
||||
$attrs = [
|
||||
'headers' => ['Authorization' => 'Bearer '.$api_token]
|
||||
];
|
||||
$res = parent::execute($this->url('summary'), $attrs, false, 'GET');
|
||||
$details = json_decode($res->getBody());
|
||||
$data = [ "lessons" => 0, "reviews" => 0 ];
|
||||
foreach($details->data->lessons as $lesson)
|
||||
{
|
||||
$available_at = \Carbon\Carbon::createFromTimeString($lesson->available_at);
|
||||
if($now >= $available_at)
|
||||
{
|
||||
$data["lessons"] += count($lesson->subject_ids);
|
||||
}
|
||||
}
|
||||
foreach($details->data->reviews as $review)
|
||||
{
|
||||
$available_at = \Carbon\Carbon::createFromTimeString($review->available_at);
|
||||
if($now >= $available_at)
|
||||
{
|
||||
$data["reviews"] += count($review->subject_ids);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getLiveStats($status, $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build api url
|
||||
*/
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl('https://api.wanikani.com/v2/').$endpoint;
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
10
heimdall/config/www/SupportedApps/WaniKani/app.json
Executable file
10
heimdall/config/www/SupportedApps/WaniKani/app.json
Executable file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "dc115cfaac280c4b97289484356c21428af565be",
|
||||
"name": "WaniKani",
|
||||
"website": "https://www.wanikani.com/",
|
||||
"license": "Proprietary",
|
||||
"description": "WaniKani is a Japanese radicals, kanji, and vocabulary learning web app that uses mnemonics and SRS to make kanji learning simple.",
|
||||
"enhanced": true,
|
||||
"tile_background": "light",
|
||||
"icon": "wanikani.png"
|
||||
}
|
||||
13
heimdall/config/www/SupportedApps/WaniKani/config.blade.php
Executable file
13
heimdall/config/www/SupportedApps/WaniKani/config.blade.php
Executable file
@@ -0,0 +1,13 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
{!! Form::hidden('config[override_url]') !!}
|
||||
{!! Form::hidden('config[password]') !!}
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.api_token') }}</label>
|
||||
{!! Form::text('config[username]', (isset($item) ? $item->getconfig()->username : null), array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
10
heimdall/config/www/SupportedApps/WaniKani/livestats.blade.php
Executable file
10
heimdall/config/www/SupportedApps/WaniKani/livestats.blade.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<ul class="livestats">
|
||||
<li>
|
||||
<span class="title">Lessons</span>
|
||||
<strong>{!! $lessons !!}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">Reviews</span>
|
||||
<strong>{!! $reviews !!}</strong>
|
||||
</li>
|
||||
</ul>
|
||||
BIN
heimdall/config/www/SupportedApps/WaniKani/wanikani.png
Executable file
BIN
heimdall/config/www/SupportedApps/WaniKani/wanikani.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user