From 86b6f75eb7f37404629c3462d6578714edd2deee Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sat, 3 Sep 2022 22:34:26 +0300 Subject: [PATCH] sms.ru left SMS check --- .editorconfig | 24 ++++++++++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ public/.gitignore | 2 ++ public/css/styles.css | 0 public/index.html | 39 +++++++++++++++++++++++++++++++++++++++ public/js/app.js | 30 ++++++++++++++++++++++++++++++ shard.yml | 18 ++++++++++++++++++ src/Services.cr | 9 +++++++++ src/modules/sms_ru.cr | 6 ++++++ 9 files changed, 149 insertions(+) create mode 100644 .editorconfig create mode 100644 LICENSE create mode 100644 public/.gitignore create mode 100644 public/css/styles.css create mode 100644 public/index.html create mode 100644 public/js/app.js create mode 100644 shard.yml create mode 100644 src/Services.cr create mode 100644 src/modules/sms_ru.cr diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9e87bbe --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5791b44 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2022 Alexander Popov + +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. diff --git a/public/.gitignore b/public/.gitignore new file mode 100644 index 0000000..85f1001 --- /dev/null +++ b/public/.gitignore @@ -0,0 +1,2 @@ +/css/bootstrap* +/js/bootstrap* diff --git a/public/css/styles.css b/public/css/styles.css new file mode 100644 index 0000000..e69de29 diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e88d7b0 --- /dev/null +++ b/public/index.html @@ -0,0 +1,39 @@ + + + + + + Services + + + + + + +
+
+
+ +
+
+ Today: + +
+ +
+
SMS.ru
+
+
+
+
+
+
+ +
+
+
+
+ + diff --git a/public/js/app.js b/public/js/app.js new file mode 100644 index 0000000..6d4c9e4 --- /dev/null +++ b/public/js/app.js @@ -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); +} diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..0173eba --- /dev/null +++ b/shard.yml @@ -0,0 +1,18 @@ +name: Services +version: 0.1.0 + +# authors: +# - name + +# description: | +# Short description of ServicesCheck + +dependencies: + kemal: + github: kemalcr/kemal + +# development_dependencies: +# webmock: +# github: manastech/webmock.cr + +license: MIT diff --git a/src/Services.cr b/src/Services.cr new file mode 100644 index 0000000..7e3e614 --- /dev/null +++ b/src/Services.cr @@ -0,0 +1,9 @@ +require "kemal" +require "./modules/*" + +get "/" do + render "public/index.html" +end + +Kemal.config.env = "development" +Kemal.run diff --git a/src/modules/sms_ru.cr b/src/modules/sms_ru.cr new file mode 100644 index 0000000..abe52dd --- /dev/null +++ b/src/modules/sms_ru.cr @@ -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