Limo
A simple mod manager
Loading...
Searching...
No Matches
api.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "file.h"
9#include "mod.h"
10#include <cpr/cpr.h>
11#include <string>
12
13
17namespace nexus
18{
22struct Page
23{
25 std::string url;
29 std::vector<std::pair<std::string, std::vector<std::string>>> changelog;
31 std::vector<File> files;
32};
33
37class Api
38{
39public:
41 Api() = delete;
42
47 static void setApiKey(const std::string& api_key);
53 static bool isInitialized();
59 static Mod getMod(const std::string& mod_url);
66 static Mod getMod(const std::string& domain_name, long mod_id);
71 static void trackMod(const std::string& mod_url);
76 static void untrackMod(const std::string& mod_url);
81 static std::vector<Mod> getTrackedMods();
87 static std::vector<File> getModFiles(const std::string& mod_url);
94 static std::string getDownloadUrl(const std::string& mod_url, long file_id);
100 static std::string getDownloadUrl(const std::string& nxm_url);
106 static std::vector<std::pair<std::string, std::vector<std::string>>> getChangelogs(
107 const std::string& mod_url);
114 static bool modUrlIsValid(const std::string& url);
120 static Page getNexusPage(const std::string& mod_url);
127 static std::optional<std::pair<std::string, bool>> validateKey(const std::string& api_key);
133 static std::string getNexusPageUrl(const std::string& nxm_url);
138 static std::string getApiKey();
139
140private:
142 inline static std::string api_key_ = "";
143
149 static std::optional<std::pair<std::string, int>> extractDomainAndModId(
150 const std::string& mod_url);
151};
152}
static std::string getNexusPageUrl(const std::string &nxm_url)
Generates a NexusMods mod page URL from the given nxm URL.
Definition api.cpp:313
static void trackMod(const std::string &mod_url)
Tracks the mod for the NexusMods account belonging to the API key.
Definition api.cpp:43
static bool modUrlIsValid(const std::string &url)
Checks if the given URL is a valid NexusMods mod page URL. Only verifies if the URL is semantically c...
Definition api.cpp:284
static std::optional< std::pair< std::string, bool > > validateKey(const std::string &api_key)
Checks if the NexusMods API can be accessed with the given API key.
Definition api.cpp:297
static std::string getDownloadUrl(const std::string &mod_url, long file_id)
Generates a download URL for the given mod file. This only works for premium accounts.
Definition api.cpp:117
static Mod getMod(const std::string &mod_url)
Fetches data for the mod accessible by the given NexusMods URL.
Definition api.cpp:21
static std::string getApiKey()
Getter for the API key.
Definition api.cpp:322
static std::optional< std::pair< std::string, int > > extractDomainAndModId(const std::string &mod_url)
Extracts the NexusMods domain and mod id from the given mod page URL.
Definition api.cpp:327
static std::string api_key_
The API key used for all operations.
Definition api.h:142
static void setApiKey(const std::string &api_key)
Sets the API key to use for all operations.
Definition api.cpp:11
static std::vector< std::pair< std::string, std::vector< std::string > > > getChangelogs(const std::string &mod_url)
Fetches changelogs for the given mod.
Definition api.cpp:203
static bool isInitialized()
Checks if this class has been initialized with an API key. Does NOT check if the key works.
Definition api.cpp:16
static std::vector< File > getModFiles(const std::string &mod_url)
Fetches data for all available files for the given mod.
Definition api.cpp:88
static void untrackMod(const std::string &mod_url)
Tracks the mod for the NexusMods account belonging to the API key.
Definition api.cpp:55
Api()=delete
This is an abstract class, so the constructor is deleted.
static std::vector< Mod > getTrackedMods()
Fetches data for all mods tracked by the account belonging to the API key.
Definition api.cpp:67
static Page getNexusPage(const std::string &mod_url)
Fetches data to fill a Page object for the given mod.
Definition api.cpp:292
Contains data for a mod on NexusMods.
Definition mod.h:22
The nexus namespace contains structs and functions needed for accessing the NexusMods API.
Definition api.h:18
Header for the nexus::File class.
Header for the nexus::Mod class.
Contains all data for a mod available through the NexusMods api.
Definition api.h:23
Mod mod
Contains an overview of of the mod page, like a description and summary.
Definition api.h:27
std::vector< std::pair< std::string, std::vector< std::string > > > changelog
For every Version of the mod: A vector of changes in that version.
Definition api.h:29
std::string url
URL of the mod page on NexusMods.
Definition api.h:25
std::vector< File > files
Contains data on all available files for the mod.
Definition api.h:31