nekos-best.c 1.0.0
A simple, lightweight c wrapper for nekos.best API
Data Structures | Macros | Enumerations | Functions
nekosbest.h File Reference

This file contains structs and functions for interacting with the nekos.best API. More...

Go to the source code of this file.

Data Structures

struct  nekos_endpoint
 Struct for an endpoint/category. More...
 
struct  nekos_endpoint_list
 Struct for a list of endpoints/categories. More...
 
struct  nekos_source_gif
 Struct for a gif source. More...
 
struct  nekos_source_png
 Struct for a png source. More...
 
struct  nekos_result
 Struct for a result image. More...
 
struct  nekos_result_list
 Struct for a list of result images. More...
 
struct  nekos_http_response
 Struct for an http response. More...
 

Macros

#define NEKOS_BASE_URL   "https://nekos.best/api/v2/"
 Base URL for nekos.best API.
 
#define NEKOS_MAX_AMOUNT   20
 Maximum amount of results that can be requested.
 
#define NEKOS_MIN_QUERY_LEN   3
 Minimum length of query string.
 
#define NEKOS_MAX_QUERY_LEN   150
 Maximum length of query string.
 

Enumerations

enum  nekos_status {
  NEKOS_OK , NEKOS_MEM_ERR , NEKOS_LIBCURL_ERR , NEKOS_CJSON_ERR ,
  NEKOS_INVALID_PARAM_ERR
}
 Status codes for the nekos.best c wrapper. More...
 
enum  nekos_format { NEKOS_PNG , NEKOS_GIF }
 Enum for the format of the image. More...
 

Functions

nekos_status nekos_endpoints (nekos_endpoint_list *endpoints)
 Get a list of endpoints/categories.
 
nekos_endpointnekos_find_endpoint (const nekos_endpoint_list *endpoints, const char *name)
 Find a specific endpoint in a list of endpoints/categories.
 
nekos_status nekos_category (nekos_result_list *results, const nekos_endpoint *endpoint, int amount)
 Get a list of images from a category.
 
nekos_status nekos_search (nekos_result_list *results, const char *raw_query, int amount, const nekos_format format, const nekos_endpoint *endpoint)
 Search for images.
 
nekos_status nekos_download (nekos_http_response *http_response, const char *url)
 Download an image.
 
void nekos_free_endpoint (const nekos_endpoint *endpoint)
 Free an endpoint.
 
void nekos_free_endpoints (const nekos_endpoint_list *endpoints)
 Free a list of endpoints.
 
void nekos_free_result (const nekos_result *result)
 Free a result.
 
void nekos_free_results (const nekos_result_list *results)
 Free a list of results.
 
void nekos_free_http_response (const nekos_http_response *http_response)
 Free an http response.
 

Detailed Description

This file contains structs and functions for interacting with the nekos.best API.

Enumeration Type Documentation

◆ nekos_status

Status codes for the nekos.best c wrapper.

Enumerator
NEKOS_OK 

Indicates that the operation was successful.

NEKOS_MEM_ERR 

Indicates that there was a memory allocation error.

NEKOS_LIBCURL_ERR 

Indicates that there was an error with libcurl.

NEKOS_CJSON_ERR 

Indicates that there was an error with cJSON.

NEKOS_INVALID_PARAM_ERR 

Indicates that an invalid parameter was passed to a function.

◆ nekos_format

Enum for the format of the image.

Enumerator
NEKOS_PNG 

Indicates that the response image is a png and nekos_source_png should be used.

NEKOS_GIF 

Indicates that the response image is a gif and nekos_source_gif should be used.

Function Documentation

◆ nekos_endpoints()

nekos_status nekos_endpoints ( nekos_endpoint_list endpoints)

Get a list of endpoints/categories.

This function fetches the endpoints endpoint of the api and parses the response into a list of endpoints.

It will allocate memory for the list of endpoints and the endpoints themselves.

Parameters
[out]endpointsPointer to a nekos_endpoint_list to store the endpoints in.
Returns
NEKOS_OK
NEKOS_MEM_ERR
NEKOS_LIBCURL_ERR
NEKOS_CJSON_ERR

◆ nekos_find_endpoint()

nekos_endpoint * nekos_find_endpoint ( const nekos_endpoint_list endpoints,
const char *  name 
)

Find a specific endpoint in a list of endpoints/categories.

This function searches for a specific endpoint in a list of endpoints by name.

Parameters
[in]endpointsPointer to a nekos_endpoint_list to search in.
[in]nameName of the endpoint to search for.
Returns
Pointer to the endpoint if found, NULL otherwise.

◆ nekos_category()

nekos_status nekos_category ( nekos_result_list results,
const nekos_endpoint endpoint,
int  amount 
)

Get a list of images from a category.

This function fetches the specified category endpoint of the api and parses the response into a list of images.

It will allocate memory for the list of results, the results themselves, and the source information.

Parameters
[out]resultsPointer to a nekos_result_list to store the results in.
[in]endpointPointer to a nekos_endpoint to specify the category.
[in]amountAmount of images to fetch. Must be between 1 and NEKOS_MAX_AMOUNT.
Returns
NEKOS_OK
NEKOS_MEM_ERR
NEKOS_LIBCURL_ERR
NEKOS_CJSON_ERR
NEKOS_INVALID_PARAM_ERR

◆ nekos_search()

nekos_status nekos_search ( nekos_result_list results,
const char *  raw_query,
int  amount,
const nekos_format  format,
const nekos_endpoint endpoint 
)

Search for images.

This function fetches the search endpoint of the api and parses the response into a list of images.

The search can optionally specify a endpoint/category.

It will allocate memory for the list of results, the results themselves, and the source information.

Parameters
[out]resultsPointer to a nekos_result_list to store the results in.
[in]raw_queryQuery to search for. Must be between NEKOS_MIN_QUERY_LEN and NEKOS_MAX_QUERY_LEN.
[in]amountAmount of images to fetch. Must be between 1 and NEKOS_MAX_AMOUNT.
[in]formatFormat of the images to search for.
[in]endpointPointer to a nekos_endpoint to specify a category. Can be NULL.
Returns
NEKOS_OK
NEKOS_MEM_ERR
NEKOS_LIBCURL_ERR
NEKOS_CJSON_ERR
NEKOS_INVALID_PARAM_ERR

◆ nekos_download()

nekos_status nekos_download ( nekos_http_response http_response,
const char *  url 
)

Download an image.

This function fetches the specified image url and stores the response in a nekos_http_response .

It will allocate memory for the response text.

Parameters
[out]http_responsePointer to a nekos_http_response to store the response in.
[in]urlURL of the image to download.
Returns
NEKOS_OK
NEKOS_MEM_ERR
NEKOS_LIBCURL_ERR

◆ nekos_free_endpoint()

void nekos_free_endpoint ( const nekos_endpoint endpoint)

Free an endpoint.

This function frees the memory allocated for the endpoint.

Parameters
[in]endpointPointer to a nekos_endpoint to free.

◆ nekos_free_endpoints()

void nekos_free_endpoints ( const nekos_endpoint_list endpoints)

Free a list of endpoints.

This function frees the memory allocated for the list of endpoints and the endpoints themselves.

Parameters
[in]endpointsPointer to a nekos_endpoint_list to free.

◆ nekos_free_result()

void nekos_free_result ( const nekos_result result)

Free a result.

This function frees the memory allocated for the result and the source information.

Parameters
[in]resultPointer to a nekos_result to free.

◆ nekos_free_results()

void nekos_free_results ( const nekos_result_list results)

Free a list of results.

This function frees the memory allocated for the list of results, the results themselves, and the source information.

Parameters
[in]resultsPointer to a nekos_result_list to free.

◆ nekos_free_http_response()

void nekos_free_http_response ( const nekos_http_response http_response)

Free an http response.

This function frees the memory allocated for the response text.

Parameters
[in]http_responsePointer to a nekos_http_response to free.