From c58e507032b345a42179c8b04838faab27b72fea Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 14 Mar 2015 17:22:52 +0100 Subject: [PATCH] format_http_params function --- bot/utils.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bot/utils.lua b/bot/utils.lua index 9b149a3..8fb397e 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -365,3 +365,22 @@ function send_document_from_url(receiver, url, cb_function, cb_extra) print("File path: "..file_path) _send_document(receiver, file_path, cb_function, cb_extra) end + +-- Parameters in ?a=1&b=2 style +function format_http_params(params, is_get) + local str = '' + -- If is get add ? to the beginning + if is_get then str = '?' end + local first = true -- Frist param + for k,v in pairs (params) do + if v then -- nil value + if first then + first = false + str = str..k.. "="..v + else + str = str.."&"..k.. "="..v + end + end + end + return str +end \ No newline at end of file