Remove API key requirement

This commit is contained in:
NeilClack
2026-08-17 20:36:59 -05:00
parent 359ae905d7
commit 74245ee07d
16 changed files with 74 additions and 194 deletions
+13 -26
View File
@@ -4,10 +4,6 @@
#include <curl/curl.h>
#include <string>
#ifndef API_KEY
#define API_KEY ""
#endif
namespace radiantwave::api {
namespace {
@@ -31,7 +27,7 @@ size_t writeCallback(char* ptr, size_t size, size_t nmemb, void* userdata) {
}
// Shared curl setup + perform. Returns a populated HttpResponse.
HttpResponse performRequest(const std::string& url, const std::string& apiKey,
HttpResponse performRequest(const std::string& url,
bool post, const std::string& jsonBody) {
HttpResponse response;
@@ -47,12 +43,6 @@ HttpResponse performRequest(const std::string& url, const std::string& apiKey,
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response.body);
struct curl_slist* headers = nullptr;
// An explicit apiKey wins; otherwise fall back to the key baked in at
// build time via -DAPI_KEY (empty string when unset).
const std::string effectiveKey = apiKey.empty() ? API_KEY : apiKey;
if (!effectiveKey.empty()) {
headers = curl_slist_append(headers, ("Authorization: Bearer " + effectiveKey).c_str());
}
if (post) {
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
@@ -79,13 +69,12 @@ HttpResponse performRequest(const std::string& url, const std::string& apiKey,
// ─── HTTP helpers ──────────────────────────────────────────────────────
HttpResponse httpGet(const std::string& path, const std::string& apiKey) {
return performRequest(urlFor(path), apiKey, false, "");
HttpResponse httpGet(const std::string& path) {
return performRequest(urlFor(path), false, "");
}
HttpResponse httpPost(const std::string& path, const std::string& jsonBody,
const std::string& apiKey) {
return performRequest(urlFor(path), apiKey, true, jsonBody);
HttpResponse httpPost(const std::string& path, const std::string& jsonBody) {
return performRequest(urlFor(path), true, jsonBody);
}
// ─── GET /frequencies ──────────────────────────────────────────────────
@@ -112,8 +101,8 @@ bool parseFrequenciesJson(const std::string& body, std::vector<Frequency>& out)
return true;
}
bool fetchFrequencies(std::vector<Frequency>& out, const std::string& apiKey) {
HttpResponse response = httpGet(PATH_FREQUENCIES, apiKey);
bool fetchFrequencies(std::vector<Frequency>& out) {
HttpResponse response = httpGet(PATH_FREQUENCIES);
if (!response.transportOk || response.status < 200 || response.status >= 300) {
return false;
}
@@ -169,8 +158,8 @@ bool parseColorPalettesJson(const std::string& body, std::vector<ColorPalette>&
return true;
}
bool fetchColorPalettes(std::vector<ColorPalette>& out, const std::string& apiKey) {
HttpResponse response = httpGet(PATH_COLOR_PALETTES, apiKey);
bool fetchColorPalettes(std::vector<ColorPalette>& out) {
HttpResponse response = httpGet(PATH_COLOR_PALETTES);
if (!response.transportOk || response.status < 200 || response.status >= 300) {
return false;
}
@@ -196,13 +185,12 @@ bool parseLicenseJson(const std::string& body, LicenseInfo& out) {
return !out.key.empty();
}
LicenseResult validateLicense(const std::string& key, const std::string& email,
const std::string& apiKey) {
LicenseResult validateLicense(const std::string& key, const std::string& email) {
LicenseResult result;
const std::string jsonBody =
"{\"license_key\":\"" + key + "\",\"email_address\":\"" + email + "\"}";
HttpResponse response = httpPost(PATH_LICENSE, jsonBody, apiKey);
HttpResponse response = httpPost(PATH_LICENSE, jsonBody);
result.status = response.status;
if (!response.transportOk) {
@@ -233,8 +221,7 @@ bool parseCreateAccountJson(const std::string& body, AccountBody& out) {
return true;
}
AccountResult createAccount(const std::string& email, const std::string& name,
const std::string& apiKey) {
AccountResult createAccount(const std::string& email, const std::string& name) {
AccountResult result;
std::string jsonBody =
@@ -244,7 +231,7 @@ AccountResult createAccount(const std::string& email, const std::string& name,
}
jsonBody += "}";
HttpResponse response = httpPost(PATH_CREATE_ACCOUNT, jsonBody, apiKey);
HttpResponse response = httpPost(PATH_CREATE_ACCOUNT, jsonBody);
result.status = response.status;
if (!response.transportOk) {