Skip to content

C++ wrapper for unofficial SpaceX API. Providing information about SpaceX company, launches, landings, rockets and more.

License

Notifications You must be signed in to change notification settings

AzuxDario/Marsy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marsy

License Stars Issues

Marsy is a library that allow you to deserialize and manage data returned by SpaceX API. Marsy currently support V4 of API.

Usage

Start

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.

Queries

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

Size of binary in debug mode

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.

Things you should be aware of

Asynchronous

Currently functions are synchronous. Don't call them from UI thread. Use second thread or features like std::future.

Internet connection

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.

Dates parsing

Marsy doesn't parse dates returned by API. They're stored as strings.

Sample code

#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;
}

External libraries