Skip to content

Commit

Permalink
test bool
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Nov 4, 2024
1 parent d6b3619 commit 65a5420
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/dotenv_.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

using namespace std;

std::string get_api_key()
std::string get_api_key( )
{

dotenv env(".env");
std::string apikey = env.get("EVDS_APIKEY", "");

Expand Down
36 changes: 28 additions & 8 deletions src/get.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct GetParams
std::string url;
std::string api_key;
std::string proxy_url;
bool cache = false ;
bool cache = false;
};

// ...................................................... WriteCallback
Expand Down Expand Up @@ -91,7 +91,7 @@ std::enable_if_t<is_cstring<T>::value, const char *> get_proxy_for_url(T url, T
return "";
}

std::string get_request_real(const GetParams &params);
std::string get_request_real(const GetParams &params , bool test );

std::string get_request(const GetParams &params, const Config &config)
{
Expand All @@ -115,15 +115,16 @@ std::string get_request(const GetParams &params, const Config &config)
return cached_result;
}

auto res = get_request_real(params);
auto res = get_request_real(params, config.test);
if (cache_option)
cache.save_cache(fnc_name, res, params_str);
return res;
}
std::string get_request_real(const GetParams &params)
std::string get_request_real(const GetParams &params, bool test)
{
// if (config.test)

if (!evds::confirm("Request?"))
if (!test & !evds::confirm("Request?"))
{
std::cout << "Not requesting ...";
throw std::runtime_error("Request was cancelled ");
Expand All @@ -141,7 +142,7 @@ std::string get_request_real(const GetParams &params)
std::unique_ptr<CURL, CurlDeleter> curl(curl_easy_init());
if (curl)
{
std::cout << "url: " << params.url << "\n";
std::cout << "url: " << params.url << "\n";
curl_easy_setopt(curl.get(), CURLOPT_URL, params.url.c_str());

// Prepare the header with the API key
Expand Down Expand Up @@ -212,7 +213,6 @@ std::string read_content_from_file(const std::string &filename)

return buffer.str();
}


std::string getEvds(const std::string &url, const Config &config)
{
Expand All @@ -221,7 +221,27 @@ std::string getEvds(const std::string &url, const Config &config)
{
GetParams params;
params.url = url;
params.api_key = get_api_key() ;

const char *env_apikey = std::getenv("EVDS_APIKEY");

if (config.test)
{

if (env_apikey)
{
params.api_key = std::string(env_apikey);
}
else
{
std::cerr << "Environment variable EVDS_APIKEY is not set." << std::endl;
return "";
}
}
else
{
params.api_key = get_api_key();
}

params.proxy_url = "";

std::string response = get_request(params, config);
Expand Down
2 changes: 1 addition & 1 deletion src/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace evds
}

bool confirm(const std::string &message)
{
{
std::string input;
std::cout << message << " (y/n): ";
std::cin >> input;
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ int main(int argc, char *argv[])
config.cache = false;
config.start_date = "01-01-2020";
config.end_date = "31-12-2025";
config.test = false ;

// Parse command-line arguments
std::vector<std::string> indexes;
Expand All @@ -68,6 +69,10 @@ int main(int argc, char *argv[])
if (args.count("cache")) {
config.cache = args["cache"] == "true";
}
if (args.count("test")) {
config.test = args["test"] == "true";
}

if (args.count("start_date")) {
config.start_date = args["start_date"];
}
Expand Down
3 changes: 2 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace evds
std::string start_date = "01-01-2000";
std::string end_date = "31-12-2100";
std::string frequency = "daily";
std::string aggregation = "none";
std::string aggregation = "none";
bool test = false ;

bool cache = true;
};
Expand Down

0 comments on commit 65a5420

Please sign in to comment.