sms.ru left SMS check

This commit is contained in:
Alexander Popov 2022-09-03 22:34:26 +03:00
commit 86b6f75eb7
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
9 changed files with 149 additions and 0 deletions

24
.editorconfig Normal file
View File

@ -0,0 +1,24 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.cr]
indent_style = space
indent_size = 2
[{*.html,*.css,*.json}]
indent_style = tab
indent_size = 4
[*.md]
trim_trailing_whitespace = false
[*.js]
indent_style = space
indent_size = 2

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2022 Alexander Popov <iiiypuk@fastmail.fm>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

2
public/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/css/bootstrap*
/js/bootstrap*

0
public/css/styles.css Normal file
View File

39
public/index.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Services</title>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<script type="text/javascript" src="/js/app.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
</head>
<body>
<main class="d-flex flex-nowrap">
<div class="d-flex flex-column flex-shrink-0 p-3 text-bg-dark border-end" style="width: 280px;">
</div>
<section class="bg-dark text-bg-dark w-100 p-3">
<div class="fw-bold">
Today:
<label id="data-today"></label>
</div>
<div class="row">
<div class="col">SMS.ru</div>
<div class="col-6">
<div class="progress">
<div id="data-smsru-progress" class="progress-bar progress-bar-striped bg-danger" role="progressbar"
aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"
style="width: 100%"></div>
</div>
</div>
<div class="col text-end">
<button id="button-smsru-update" class="btn btn-sm btn-outline-primary">Update</button>
</div>
</div>
</section>
</main>
</body>
</html>

30
public/js/app.js Normal file
View File

@ -0,0 +1,30 @@
window.onload = function () {
let dataToday = document.getElementById('data-today');
// Set current date
let today = new Date().toLocaleDateString('en-US', {
// 'weekday': 'long',
'year': 'numeric',
'month': 'long',
'day': 'numeric'
});
dataToday.innerText = today.replace('/', ' ');
let smsruUpdateButton = document.getElementById('button-smsru-update');
smsruUpdateButton.onclick = smsruUpdateMessages;
}
function smsruUpdateMessages() {
let smsProgress = document.getElementById('data-smsru-progress');
fetch('/api/v1.0/smsru_status')
.then(response => response.json())
.then(data => {
smsProgress.setAttribute('aria-valuenow', data.used_today);
smsProgress.setAttribute('aria-valuemax', data.total_free);
smsProgress.setAttribute('style', `width: ${data.used_today / data.total_free * 100}%`);
smsProgress.innerText = `Лимит: ${data.used_today} из ${data.total_free}`;
});
// console.log(smsProgress);
}

18
shard.yml Normal file
View File

@ -0,0 +1,18 @@
name: Services
version: 0.1.0
# authors:
# - name <email@example.com>
# description: |
# Short description of ServicesCheck
dependencies:
kemal:
github: kemalcr/kemal
# development_dependencies:
# webmock:
# github: manastech/webmock.cr
license: MIT

9
src/Services.cr Normal file
View File

@ -0,0 +1,9 @@
require "kemal"
require "./modules/*"
get "/" do
render "public/index.html"
end
Kemal.config.env = "development"
Kemal.run

6
src/modules/sms_ru.cr Normal file
View File

@ -0,0 +1,6 @@
require "http/client"
get "/api/v1.0/smsru_status" do
response = HTTP::Client.get "https://sms.ru/my/free?api_id=F1FC9A76-1408-E4CF-1F89-E7CC756762B6&json=1"
response.body
end