Limo
A simple mod manager
Loading...
Searching...
No Matches
nexus::Api Class Reference

Provides functions for accessing the NexusMods API. More...

#include <api.h>

Public Member Functions

 Api ()=delete
 This is an abstract class, so the constructor is deleted.
 

Static Public Member Functions

static void setApiKey (const std::string &api_key)
 Sets the API key to use for all operations.
 
static bool isInitialized ()
 Checks if this class has been initialized with an API key. Does NOT check if the key works.
 
static Mod getMod (const std::string &mod_url)
 Fetches data for the mod accessible by the given NexusMods URL.
 
static Mod getMod (const std::string &domain_name, long mod_id)
 Fetches data for the mod specified by the NexusMods domain and mod id.
 
static void trackMod (const std::string &mod_url)
 Tracks the mod for the NexusMods account belonging to the API key.
 
static void untrackMod (const std::string &mod_url)
 Tracks the mod for the NexusMods account belonging to the API key.
 
static std::vector< ModgetTrackedMods ()
 Fetches data for all mods tracked by the account belonging to the API key.
 
static std::vector< FilegetModFiles (const std::string &mod_url)
 Fetches data for all available files for the given mod.
 
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.
 
static std::string getDownloadUrl (const std::string &nxm_url)
 Generates a download URL from the given nxm Url.
 
static std::vector< std::pair< std::string, std::vector< std::string > > > getChangelogs (const std::string &mod_url)
 Fetches changelogs for the given mod.
 
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 correct, not if the target exists.
 
static Page getNexusPage (const std::string &mod_url)
 Fetches data to fill a Page object for the given mod.
 
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.
 
static std::string getNexusPageUrl (const std::string &nxm_url)
 Generates a NexusMods mod page URL from the given nxm URL.
 
static std::string getApiKey ()
 Getter for the API key.
 

Static Private Member Functions

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.
 

Static Private Attributes

static std::string api_key_ = ""
 The API key used for all operations.
 

Detailed Description

Provides functions for accessing the NexusMods API.

Member Function Documentation

◆ extractDomainAndModId()

std::optional< std::pair< std::string, int > > Api::extractDomainAndModId ( const std::string & mod_url)
staticprivate

Extracts the NexusMods domain and mod id from the given mod page URL.

Parameters
urlURL to the mod on NexusMods.
Returns
If the given URL is valid: The domain and mod id. Else an empty std::optional.

◆ getApiKey()

std::string Api::getApiKey ( )
static

Getter for the API key.

Returns
The API key.

◆ getChangelogs()

std::vector< std::pair< std::string, std::vector< std::string > > > Api::getChangelogs ( const std::string & mod_url)
static

Fetches changelogs for the given mod.

Parameters
mod_urlURL to the mod on NexusMods.
Returns
For every Version of the mod: A vector of changes in that version.

◆ getDownloadUrl() [1/2]

std::string Api::getDownloadUrl ( const std::string & mod_url,
long file_id )
static

Generates a download URL for the given mod file. This only works for premium accounts.

Parameters
mod_urlURL to the mod on NexusMods.
file_idId of the file for which a link is to be generated.
Returns
The download URL.

◆ getDownloadUrl() [2/2]

std::string Api::getDownloadUrl ( const std::string & nxm_url)
static

Generates a download URL from the given nxm Url.

Parameters
nxm_urlThe nxm Url used. This is usually generated through the NexusMods website.
Returns
The download URL.

◆ getMod() [1/2]

Mod Api::getMod ( const std::string & domain_name,
long mod_id )
static

Fetches data for the mod specified by the NexusMods domain and mod id.

Parameters
domain_nameThe NexusMods domain containing the mod.
mod_idTarget mod id.
Returns
A Mod object containing all received data.

◆ getMod() [2/2]

Mod Api::getMod ( const std::string & mod_url)
static

Fetches data for the mod accessible by the given NexusMods URL.

Parameters
mod_urlURL to the mod on NexusMods.
Returns
A Mod object containing all received data.

◆ getModFiles()

std::vector< File > Api::getModFiles ( const std::string & mod_url)
static

Fetches data for all available files for the given mod.

Parameters
mod_urlURL to the mod on NexusMods.
Returns
A vector of File objects containing the received data.

◆ getNexusPage()

Page Api::getNexusPage ( const std::string & mod_url)
static

Fetches data to fill a Page object for the given mod.

Parameters
mod_urlURL to the mod on NexusMods.
Returns
The generated Page object.

◆ getNexusPageUrl()

std::string Api::getNexusPageUrl ( const std::string & nxm_url)
static

Generates a NexusMods mod page URL from the given nxm URL.

Parameters
nxm_urlThe nxm Url used. This is usually generated through the NexusMods website.
Returns
The NexusMods mod page URL.

◆ getTrackedMods()

std::vector< Mod > Api::getTrackedMods ( )
static

Fetches data for all mods tracked by the account belonging to the API key.

Returns
A vector of Mod objects with the received data.

◆ isInitialized()

bool Api::isInitialized ( )
static

Checks if this class has been initialized with an API key. Does NOT check if the key works.

Returns
True if an API key exists.

◆ modUrlIsValid()

bool Api::modUrlIsValid ( const std::string & url)
static

Checks if the given URL is a valid NexusMods mod page URL. Only verifies if the URL is semantically correct, not if the target exists.

Parameters
urlURL to check.
Returns
True if the URL points to a NexusMods page.

◆ setApiKey()

void Api::setApiKey ( const std::string & api_key)
static

Sets the API key to use for all operations.

Parameters
api_keyThe new API key.

◆ trackMod()

void Api::trackMod ( const std::string & mod_url)
static

Tracks the mod for the NexusMods account belonging to the API key.

Parameters
mod_urlURL to the mod on NexusMods.

◆ untrackMod()

void Api::untrackMod ( const std::string & mod_url)
static

Tracks the mod for the NexusMods account belonging to the API key.

Parameters
mod_urlURL to the mod on NexusMods.

◆ validateKey()

std::optional< std::pair< std::string, bool > > Api::validateKey ( const std::string & api_key)
static

Checks if the NexusMods API can be accessed with the given API key.

Parameters
api_keyAPI key to validate.
Returns
If the key works: The account name and a bool indicating if the account is premium. Else: An empty std::optional.

The documentation for this class was generated from the following files: