Marsy is a library that allow you to deserialize and manage data returned by SpaceX API. Marsy currently support V4 of API.
To use it just add source files to your project.
You can use functions provided by services or write your own services on top of provided parsers. Remember to look here before start.
Library uses C++17 features. You need to remember it, when you compile your program.
SpaceX API uses queries to filter data. They're based on mongoose-paginate.
You can build simple query
with QueryBuilder
or make one on your own based on nlohmann::json
documentation.
You can build simple options -> select
with SortBuilder
or make one on your own based on nlohmann::json
documentation.
Currently Marsy doesn't provide query builder for these: options -> select
, options -> populate
You need to write them based on nlohmann::json
documentation.
Field | Type | Docs |
---|---|---|
query |
nlohmann::json |
link |
options -> select |
nlohmann::json |
link |
options -> sort |
nlohmann::json |
link |
options -> populate |
nlohmann::json |
link |
Since Marsy includes JSON in several classes, output program can be huge when compiled in debug mode (I achieved 60MB binaries). Remember to roll it out as release, when you done with testing.
Currently functions are synchronous. Don't call them from UI thread. Use second thread or features like std::future
.
Marsy doesn't handle internet connection, so you need to provide implementation of IConnection
interface. Enum ResponseStatus
is to help you handle different statuses returned by API. Service will parse returned JSON only when status is ResponseStatus::ok
.
There are 2 reasons why I made is as it is:
- C++ doesn't have internet connection in STL yet. I did not want to include big library or use different system APIs to provide support for more than one platform e.g. (WinAPI, POSIX etc.),
- maybe you already have library with internet connection in your project or you want to use one that you like the most.
However
I made IConnector
implementation based on curl and curlcpp. You can find it here.
Marsy doesn't parse dates returned by API. They're stored as strings.
#include <iostream>
#include <memory>
#include "Connection/Implementation/CurlConnector.h"
#include "Services/Capsules/CapsuleService.h"
using namespace Marsy;
int main()
{
std::shared_ptr<IConnector> conn = std::make_shared<CurlConnector>();
CapsuleService capsuleService(conn);
ServiceResponse<CapsuleModel> capsuleResponse = capsuleService.getCapsule("5e9e2c5bf35918ed873b2664");
CapsuleModel capsule = capsuleResponse.object;
std::cout << "serial " << capsule.serial.value() << std::endl;
std::cout << "reuseCount " << capsule.reuseCount.value() << std::endl;
std::cout << "waterLandings " << capsule.waterLandings.value() << std::endl;
std::cout << "landLandings " << capsule.landLandings.value() << std::endl;
std::cout << "lastUpdate " << capsule.lastUpdate.value() << std::endl;
for(auto i : capsule.launches.value())
{
std::cout << "launches " << i << std::endl;
}
std::cout << "id " << capsule.id.value() << std::endl;
}