Skip to content

Commit 173ed74

Browse files
committed
* Update Avatar Quotes example: Use libcurl instead of internetlib
1 parent 64df803 commit 173ed74

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

examples/20_avatar_quotes.ring

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
load "webview.ring"
55
load "jsonlib.ring"
6-
load "internetlib.ring"
6+
load "libcurl.ring"
77

88
# Global variable to hold the WebView instance.
99
oWebView = NULL
@@ -42,9 +42,8 @@ func loadQuoteHTML()
4242
<title>Avatar Quotes Generator</title>
4343
<meta charset="UTF-8">
4444
<meta name="viewport" content="width=device-width, initial-scale=1.0">
45-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
45+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css">
4646
<style>
47-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&family=Fira+Code:wght@400;500&display=swap');
4847
:root {
4948
--bg-color: #000000;
5049
--panel-bg: rgba(30, 30, 32, 0.6);
@@ -199,7 +198,7 @@ func handleFetchQuote(id, req)
199198
cErrorMessage = ""
200199

201200
try
202-
cResponse = download(cQuotesAPI) # Fetch data from the Avatar Quotes API.
201+
cResponse = request(cQuotesAPI) # Fetch data from the Avatar Quotes API.
203202
aJson = json2list(cResponse)["quotes"][1] # Parse the JSON response.
204203
# Structure the result as a list (array) for JSON conversion.
205204
aResult = [
@@ -217,4 +216,19 @@ func handleFetchQuote(id, req)
217216
if bError
218217
# If an error occurred, return an error message.
219218
oWebView.wreturn(id, WEBVIEW_ERROR_OK, list2json([:error = cErrorMessage]))
220-
ok
219+
ok
220+
221+
# Function to make a HTTP request using libcurl
222+
func request(url)
223+
curl = curl_easy_init()
224+
225+
curl_easy_setopt(curl, CURLOPT_USERAGENT, "RingLibCurl")
226+
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
227+
curl_easy_setopt(curl, CURLOPT_URL, url)
228+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false)
229+
230+
cOutput = curl_easy_perform_silent(curl)
231+
232+
curl_easy_cleanup(curl)
233+
234+
return cOutput

0 commit comments

Comments
 (0)