This commit is contained in:
Mars 2024-06-13 17:11:47 -04:00
parent ee61c994ac
commit 60d4160033
Signed by: pupbrained
GPG key ID: EF82E8CA83FF158C
2 changed files with 17 additions and 17 deletions

View file

@ -29,12 +29,16 @@
else pkgs # TODO: Remove when fixed on darwin
);
[
curl
fmt
glib
tomlplusplus
yyjson
]
++ (
if !stdenv.isDarwin && system == "x86_64-linux"
then [pkgsStatic.curl]
else [pkgs.curl]
)
++ linuxPkgs
++ darwinPkgs;

View file

@ -1,4 +1,5 @@
#include <curl/curl.h>
#include <fmt/core.h>
#include <rfl/json.hpp>
#include <rfl/json/load.hpp>
#include <util/result.h>
@ -48,21 +49,17 @@ fn WriteCacheToFile(const WeatherOutput& data) -> Result<> {
return Ok();
}
fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* buffer)
-> size_t {
size_t realsize = size * nmemb;
buffer->append(static_cast<char*>(contents), realsize);
return realsize;
fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str) -> size_t {
size_t totalSize = size * nmemb;
str->append(static_cast<char*>(contents), totalSize);
return totalSize;
}
// Function to make API request
fn MakeApiRequest(const std::string& url) -> Result<WeatherOutput> {
fmt::println("Making API request...");
fmt::println("Making API request to URL: {}", url);
CURL* curl = curl_easy_init();
std::string responseBuffer;
if (curl) {
@ -72,17 +69,16 @@ fn MakeApiRequest(const std::string& url) -> Result<WeatherOutput> {
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK)
return Error(fmt::format(
"Failed to perform cURL request: {}", curl_easy_strerror(res)
));
if (res != CURLE_OK) {
return Error(fmt::format("Failed to perform cURL request: {}", curl_easy_strerror(res)));
}
fmt::println("Received response from API. Response size: {}", responseBuffer.size());
fmt::println("Received response from API.");
// Parse the JSON response
WeatherOutput output =
rfl::json::read<WeatherOutput>(responseBuffer).value();
return Ok(output);
return Ok(output); // Return an empty result for now
}
return Error("Failed to initialize cURL.");