add http rest functions
This commit is contained in:
@@ -56,9 +56,12 @@ First line<br/>Second line
|
||||
|
||||
# Сетевые функции
|
||||
|
||||
* `net:get_text(url)` - функция для получения текстовых данных по по протоколу HTTP (JSON, XML, plain text).
|
||||
* `http:get(url, [id])` - выполняет запрос HTTP GET, id - строка-идентификатор запрос (см. ниже);
|
||||
* `http:post(url, string, [id])` - выполняет запрос HTTP POST, второй аргумент - JSON-строка;
|
||||
* `http:put(url, [id])` - выполняет запрос HTTP PUT;
|
||||
* `http:delete(url, [id])` - выполняет запрос HTTP DELETE.
|
||||
|
||||
Функция не возвращает никакого значения, а вместо этого вызывает колбек `on_network_result(string, number)`. Первый аргмент: тело ответа, второй - код (200, 404 и т.д.).
|
||||
Эти функции не возвращают никакого значения, а вместо этого вызывают колбек `on_network_result(string, [code], [id])`. Первый аргумент: тело ответа, второй (опциональный) - код (200, 404 и т.д.), третий (опциональный) - строка, идентифицирующая запрос, если она была указана в запросе.
|
||||
|
||||
# Функции обработки данных
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
equals = "<font color=\""..ui:get_secondary_text_color().."\"> = </font>"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://api.blockchain.info/ticker")
|
||||
http:get("https://api.blockchain.info/ticker")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
equals = "<font color=\""..ui:get_secondary_text_color().."\"> = </font>"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://api.covid19api.com/summary")
|
||||
http:get("https://api.covid19api.com/summary")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -20,7 +20,7 @@ function on_alarm()
|
||||
end
|
||||
|
||||
function get_rates(loc_date)
|
||||
net:get_text("https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"..loc_date.."/currencies/usd.json")
|
||||
http:get("https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"..loc_date.."/currencies/usd.json")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://api.trending-github.com/github/repositories")
|
||||
http:get("https://api.trending-github.com/github/repositories")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("http://api.icndb.com/jokes/random")
|
||||
http:get("http://api.icndb.com/jokes/random")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://inspiration.goprogram.ai/")
|
||||
http:get("https://inspiration.goprogram.ai/")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
function on_alarm()
|
||||
local dateStr = os.date('%Y%m%d')
|
||||
net:get_text("https://isdayoff.ru/"..dateStr)
|
||||
http:get("https://isdayoff.ru/"..dateStr)
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function on_alarm()
|
||||
local location = system:get_location()
|
||||
net:get_text("https://nominatim.openstreetmap.org/reverse?format=json&lat=".. location[1].."&lon=".. location[2].."&addressdetails=1")
|
||||
http:get("https://nominatim.openstreetmap.org/reverse?format=json&lat=".. location[1].."&lon=".. location[2].."&addressdetails=1")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://api.ipify.org")
|
||||
http:get("https://api.ipify.org")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=ru")
|
||||
http:get("http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=ru")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://api.quotable.io/random")
|
||||
http:get("https://api.quotable.io/random")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- version = "1.0"
|
||||
|
||||
function on_alarm()
|
||||
net:get_text("https://official-joke-api.appspot.com/random_joke")
|
||||
http:get("https://official-joke-api.appspot.com/random_joke")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function on_resume()
|
||||
net:get_text("https://google.com")
|
||||
http:get("https://google.com")
|
||||
end
|
||||
|
||||
function on_network_result(body, code)
|
||||
|
||||
Reference in New Issue
Block a user