11#ifndef __FDP_API_HXX__
12#define __FDP_API_HXX__
16#include <ghc/filesystem.hpp>
19#include <json/reader.h>
25#include "fdp/exceptions.hxx"
26#include "fdp/objects/api_object.hxx"
27#include "fdp/utilities/json.hxx"
28#include "fdp/utilities/logging.hxx"
30namespace FairDataPipeline {
53size_t write_func_(
void *ptr,
size_t size,
size_t nmemb, std::string *data);
67 typedef std::shared_ptr< API > sptr;
75 static sptr
construct(
const std::string& url_root );
87 Json::Value
get_request(
const std::string &addr_path,
88 long expected_response = 200, std::string token =
"");
90 Json::Value patch(
const std::string addr_path, Json::Value &post_data,
91 const std::string &token,
long expected_response = 200);
102 Json::Value
post(
const std::string addr_path, Json::Value &post_data,
103 const std::string &token,
long expected_response = 201);
105 Json::Value post_storage_root(Json::Value &post_data,
const std::string &token);
107 Json::Value post_file_type(Json::Value &post_data,
const std::string &token);
109 Json::Value get_by_json_query(
const std::string &addr_path,
110 Json::Value &query_data,
111 long expected_response = 200,
112 std::string token =
"");
122 Json::Value
get_by_id(
const std::string &table,
int const &
id,
123 long expected_response = 200, std::string token =
"");
171 API(
const std::string& url_root)
174 std::string url_root_;
175 CURL *setup_json_session_(std::string &addr_path, std::string *response,
176 long &http_code, std::string token =
"");
177 CURL *setup_download_session_(
const ghc::filesystem::path &addr_path,
180 Json::Value post_patch_request(
const std::string addr_path, Json::Value &post_data,
181 const std::string &token,
long expected_response,
bool PATCH =
false);
184 Json::Value
get_request(
const ghc::filesystem::path &addr_path,
185 long expected_response = 200, std::string token =
"");
187 void download_file(
const ghc::filesystem::path &url,
188 ghc::filesystem::path out_path);
191std::string url_encode(
const std::string& url);
a class which handles the fetching and posting of information to the FDP data pipeline RestAPI
Definition: api.hxx:65
std::string json_to_query_string(Json::Value &json_value)
Formats a json object into a string representation which can be used as a url endpoint query.
Definition: api.cxx:165
static std::string remove_leading_forward_slash(std::string str)
Remove the leading forward slash from a given string.
Definition: api.cxx:347
static sptr construct(const std::string &url_root)
construct an API object using the given URL as the root
Definition: api.cxx:16
static std::string append_with_forward_slash(std::string string)
Static function to append a given string with a "/" unless the string is empty or already ends with a...
Definition: api.cxx:334
Json::Value get_request(const std::string &addr_path, long expected_response=200, std::string token="")
sends the given 'packet' of information to the RestAPI
Definition: api.cxx:102
std::string escape_space(std::string &str)
escapes space " " characters within a string with it's html character code (%20)
Definition: api.cxx:201
std::string get_url_root() const
returns the root URL for the RestAPI used by the API instance
Definition: api.hxx:131
Json::Value post(const std::string addr_path, Json::Value &post_data, const std::string &token, long expected_response=201)
post information from a JSON value object to the RestAPI
Definition: api.cxx:206
Json::Value get_by_id(const std::string &table, int const &id, long expected_response=200, std::string token="")
get an object from the api by it's id
Definition: api.cxx:158