From e0699931c375dc6c700faf99f9e6683ee28958c0 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Fri, 7 Oct 2022 21:11:20 +0300 Subject: [PATCH] add /_info --- .gitignore | 2 ++ README.md | 4 ++++ shard.yml | 4 ++++ src/Services.cr | 6 ++++++ src/modules/_info.cr | 16 ++++++++++++++++ src/modules/sms_ru.cr | 4 ---- 6 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 README.md create mode 100644 src/modules/_info.cr diff --git a/.gitignore b/.gitignore index 0abbe52..01e3ba3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +bin/ lib/ config.yml +shard.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b890e5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +This is my API service + +## methods +/api/v1.0/smsru_status diff --git a/shard.yml b/shard.yml index 0173eba..a4f1726 100644 --- a/shard.yml +++ b/shard.yml @@ -7,6 +7,10 @@ version: 0.1.0 # description: | # Short description of ServicesCheck +targets: + api: + main: src/Services.cr + dependencies: kemal: github: kemalcr/kemal diff --git a/src/Services.cr b/src/Services.cr index 7e3e614..d0bf292 100644 --- a/src/Services.cr +++ b/src/Services.cr @@ -1,6 +1,12 @@ +require "yaml" require "kemal" require "./modules/*" +CONFIG = File.open("./config.yml") { |file| YAML.parse(file) } +CONFIG.class + +APP = {version: "1.0.0"} + get "/" do render "public/index.html" end diff --git a/src/modules/_info.cr b/src/modules/_info.cr new file mode 100644 index 0000000..22f3a0a --- /dev/null +++ b/src/modules/_info.cr @@ -0,0 +1,16 @@ +require "json" + +get "/info" do |env| + version = APP["version"] + + if env.params.query["json"]? + env.response.content_type = "application/json" + + data = {version: version}.to_json + data + else + env.response.content_type = "text/plain" + + "Vesrion: #{version}" + end +end diff --git a/src/modules/sms_ru.cr b/src/modules/sms_ru.cr index a5709ab..88a2cd2 100644 --- a/src/modules/sms_ru.cr +++ b/src/modules/sms_ru.cr @@ -1,9 +1,5 @@ -require "yaml" require "http/client" -CONFIG = File.open("./config.yml") { |file| YAML.parse(file) } -CONFIG.class - get "/api/v1.0/smsru_status" do response = HTTP::Client.get "https://sms.ru/my/free?api_id=#{CONFIG["sms.ru"]["api_id"]}&json=1" response.body