diff --git a/.gitattributes b/.gitattributes index dfe0770..e94406b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,6 @@ -# Auto detect text files and perform LF normalization -* text=auto +*.lbe binary +.gitattributes export-ignore +*LICENSE.txt export-ignore +*license.txt export-ignore +*LICENSE.html export-ignore +*LICENSE export-ignore \ No newline at end of file diff --git a/README.md b/README.md index c896c48..14e4546 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # LB Web Request - Simple Web Request extension for LioranBoard. +A simple LioranBoard extension for web requests. +You can choose type, whether to save the response in a variable and whether to enable proxy (for any cors errors). +As of now it cannot pass custom headers or parameters except for query string. +Might be useful for triggering actions without actually having to open the url in your browser or retrieving data from some public APIs. +The premade button shows how to retrieve the most recent tweet from NYTimes. + +**How to install an extension:** +1. Download the .lbe extension file +2. Click on Install Extension in your LioranBoard Receiver +3. Select the extension file you downloaded +4. Select your default Transmitter you are using. Make 100% sure it is the correct one. +5. Refresh your Transmitter or close and reopen Lioranboard Receiver. +6. Most extensions include a premade deck with buttons. If you do not see one, create a new button, add "Send to Extensions" command and select the extension you just installed. If you can only see the extension name with no input fields, it means it was not installed correctly. Repeat steps above. + +[![](https://github.com/christinna9031/LioranBoard-Files/blob/main/img/paypal.png?raw=true)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3YWXYQE3HKWHQ) diff --git a/web request.lbe b/web request.lbe index fbce620..11c6c1b 100644 --- a/web request.lbe +++ b/web request.lbe @@ -1,140 +1,143 @@ -[extension_name] -Web Request -[insert_external] -

Web request is installed.

- -[insert_command] -lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"Web Request","boxcount":5,"boxname1":"variable","boxtype1":"string","boxname2":"save_in_variable|yes|no|","boxtype2":"string","boxname3":"method|GET|POST|PUT|DELETE|","boxtype3":"string","boxname4":"proxy|yes|no|","boxtype4":"string","boxname5":"url","boxtype5":"string"}'); -[insert_hook] -case "WebRequest":{ - LBWebRequest(LioranBoardJSON.variable,LioranBoardJSON.url,LioranBoardJSON.save_in_variable,LioranBoardJSON.method,LioranBoardJSON.proxy) -}break -[insert_script] -async function LBWebRequest(variable,url,save,method,proxy){ - - async function fetchURL (){ - if (proxy=="yes"){ - url="https://cors-anywhere.herokuapp.com/"+url - } - const response = await fetch (url, { - "method": method, - 'Accept': 'application/json' -} - ) - - let content = await response.text() - if (!response.ok){ - try { - content = JSON.parse(content)} - catch (e){} - let error = content.message || content.error || "Something went wrong." - throw new Error(error) - } else { - try { - content = JSON.parse(content)} - catch (e){} - } - return content; -} - -await fetchURL () - .then (data => { - lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request successful!"}') - if (save=="yes"){ - lioranboardclient.send('{"type":"MESSAGE","topic":"SetValue","valuename":"' + variable + '","value":"' + ReplaceSymbols(data) + '","real":false}')}}) - .catch (e =>{ - lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request failed! '+ReplaceSymbols(e)+'"}')}) - - function ReplaceSymbols(tw) { - tw = JSON.stringify(tw) - tw = tw.replace(/(?:\r\n|\r|\n)/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); - tw = tw.replace(/"/g, "'").replace(/\//g, '/').replace(/\\/g, "\\\\") - return tw - }} -[insert_over] -[buttons_0x0] -activepress="0.000000" -border_size="0.000000" -combine="0.000000" -type="websocketaction+" -picture="" -text="web request" -color="12632256.000000" -button_id="4445.000000" -websocketdelay6="0.000000" -websocketvalue8_6="" -websocketvalue7_6="" -websocketvalue6_6="" -websocketvalue5_6="" -websocketvalue4_6="" -websocketvalue3_6="" -websocketvalue2_6="" -websocketvalue1_6="/$latest_news$/" -websocketaction6="36.000000" -websocketdelay5="0.000000" -websocketvalue8_5="" -websocketvalue7_5="" -websocketvalue6_5="https://decapi.me/twitter/latest/nytimes" -websocketvalue5_5="no" -websocketvalue4_5="GET" -websocketvalue3_5="yes" -websocketvalue2_5="latest_news" -websocketvalue1_5="Web Request" -websocketaction5="71.000000" -websocketdelay4="0.000000" -websocketvalue8_4="" -websocketvalue7_4="" -websocketvalue6_4="" -websocketvalue5_4="" -websocketvalue4_4="" -websocketvalue3_4="" -websocketvalue2_4="" -websocketvalue1_4="The extension doesn't support cutom headers or passing parameters (except for query string)" -websocketaction4="92.000000" -websocketdelay3="0.000000" -websocketvalue8_3="" -websocketvalue7_3="" -websocketvalue6_3="" -websocketvalue5_3="" -websocketvalue4_3="" -websocketvalue3_3="" -websocketvalue2_3="" -websocketvalue1_3="you can check for CORS errors by opening Transmitter in your browser and pressing F12 to see the log" -websocketaction3="92.000000" -websocketdelay2="0.000000" -websocketvalue8_2="" -websocketvalue7_2="" -websocketvalue6_2="" -websocketvalue5_2="" -websocketvalue4_2="" -websocketvalue3_2="" -websocketvalue2_2="" -websocketvalue1_2="Use proxy if your requests are failing due to CORS errors" -websocketaction2="92.000000" -websocketdelay1="0.000000" -websocketvalue8_1="" -websocketvalue7_1="" -websocketvalue6_1="" -websocketvalue5_1="" -websocketvalue4_1="" -websocketvalue3_1="" -websocketvalue2_1="" -websocketvalue1_1="Decide whether you want to save the response in a variable or not " -websocketaction1="92.000000" -websocketdelay0="0.000000" -websocketvalue8_0="" -websocketvalue7_0="" -websocketvalue6_0="" -websocketvalue5_0="" -websocketvalue4_0="" -websocketvalue3_0="" -websocketvalue2_0="" -websocketvalue1_0="Make a simple web request. Choose a method (GET is most likely what you want) " -websocketaction0="92.000000" -[configs] -name="Web Request Example" -background_color="8947848.000000" -grid_height="2.000000" +[extension_name] +Web Request +[insert_external] +

Web request is installed.

+ +[insert_command] +lioranboardclient.send('{"type":"MESSAGE","topic":"ExtensionCommand","name":"Web Request","boxcount":5,"boxname1":"variable","boxtype1":"string","boxname2":"save_in_variable|yes|no|","boxtype2":"string","boxname3":"method|GET|POST|PUT|DELETE|","boxtype3":"string","boxname4":"proxy|yes|no|","boxtype4":"string","boxname5":"url","boxtype5":"string"}'); +[insert_hook] +case "WebRequest":{ + LBWebRequest(LioranBoardJSON.variable,LioranBoardJSON.url,LioranBoardJSON.save_in_variable,LioranBoardJSON.method,LioranBoardJSON.proxy) +}break +[insert_script] +async function LBWebRequest(variable, url, save, method, proxy) { + + async function fetchURL() { + if (proxy == "yes") { + url = "https://cors-anywhere.herokuapp.com/" + url + } + const response = await fetch(url, { + "method": method, + 'Accept': 'application/json' + }) + + let content = await response.text() + if (!response.ok) { + try { + content = JSON.parse(content) + } catch (e) {} + let error = content.message || content.error || "Something went wrong." + throw new Error(error) + } else { + try { + content = JSON.parse(content) + } catch (e) {} + } + return content; + } + + await fetchURL() + .then(data => { + lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request successful!"}') + if (save == "yes") { + lioranboardclient.send('{"type":"MESSAGE","topic":"SetValue","valuename":"' + variable + '","value":"' + ReplaceSymbols(data) + '","real":false}') + } + }) + .catch(e => { + lioranboardclient.send('{"type":"MESSAGE","topic":"AlertMessage","message":"Web request failed! ' + ReplaceSymbols(e) + '"}') + }) + + function ReplaceSymbols(tw) { + tw = JSON.stringify(tw) + tw = tw.replace(/(?:\r\n|\r|\n)/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); + tw = tw.replace(/"/g, "'").replace(/\//g, '/').replace(/\\/g, "\\\\") + return tw + } +} +[insert_over] +[buttons_0x0] +activepress="0.000000" +border_size="0.000000" +combine="0.000000" +type="websocketaction+" +picture="" +text="web request" +color="12632256.000000" +button_id="4445.000000" +websocketdelay6="0.000000" +websocketvalue8_6="" +websocketvalue7_6="" +websocketvalue6_6="" +websocketvalue5_6="" +websocketvalue4_6="" +websocketvalue3_6="" +websocketvalue2_6="" +websocketvalue1_6="/$latest_news$/" +websocketaction6="36.000000" +websocketdelay5="0.000000" +websocketvalue8_5="" +websocketvalue7_5="" +websocketvalue6_5="https://decapi.me/twitter/latest/nytimes" +websocketvalue5_5="no" +websocketvalue4_5="GET" +websocketvalue3_5="yes" +websocketvalue2_5="latest_news" +websocketvalue1_5="Web Request" +websocketaction5="71.000000" +websocketdelay4="0.000000" +websocketvalue8_4="" +websocketvalue7_4="" +websocketvalue6_4="" +websocketvalue5_4="" +websocketvalue4_4="" +websocketvalue3_4="" +websocketvalue2_4="" +websocketvalue1_4="The extension doesn't support cutom headers or passing parameters (except for query string)" +websocketaction4="92.000000" +websocketdelay3="0.000000" +websocketvalue8_3="" +websocketvalue7_3="" +websocketvalue6_3="" +websocketvalue5_3="" +websocketvalue4_3="" +websocketvalue3_3="" +websocketvalue2_3="" +websocketvalue1_3="you can check for CORS errors by opening Transmitter in your browser and pressing F12 to see the log" +websocketaction3="92.000000" +websocketdelay2="0.000000" +websocketvalue8_2="" +websocketvalue7_2="" +websocketvalue6_2="" +websocketvalue5_2="" +websocketvalue4_2="" +websocketvalue3_2="" +websocketvalue2_2="" +websocketvalue1_2="Use proxy if your requests are failing due to CORS errors" +websocketaction2="92.000000" +websocketdelay1="0.000000" +websocketvalue8_1="" +websocketvalue7_1="" +websocketvalue6_1="" +websocketvalue5_1="" +websocketvalue4_1="" +websocketvalue3_1="" +websocketvalue2_1="" +websocketvalue1_1="Decide whether you want to save the response in a variable or not " +websocketaction1="92.000000" +websocketdelay0="0.000000" +websocketvalue8_0="" +websocketvalue7_0="" +websocketvalue6_0="" +websocketvalue5_0="" +websocketvalue4_0="" +websocketvalue3_0="" +websocketvalue2_0="" +websocketvalue1_0="Make a simple web request. Choose a method (GET is most likely what you want) " +websocketaction0="92.000000" +[configs] +name="Web Request Example" +background_color="8947848.000000" +grid_height="2.000000" grid_width="2.000000" \ No newline at end of file