otakugifs.c 1.0.0
A simple, lightweight c wrapper the otakugifs.xyz API
Data Structures | Macros | Enumerations | Functions
otakugifs.h File Reference

This file contains structs and functions for interacting with the otakugifs.xyz API. More...

Go to the source code of this file.

Data Structures

struct  otaku_reaction_list
 Struct for a list of reactions. More...
 
struct  otaku_result
 Struct for a result. More...
 
struct  otaku_http_response
 Struct for an http response. More...
 

Macros

#define OTAKU_BASE_URL   "https://api.otakugifs.xyz/gif"
 Base URL for the otakugifs.xyz API.
 

Enumerations

enum  otaku_status { OTAKU_OK , OTAKU_MEM_ERR , OTAKU_LIBCURL_ERR , OTAKU_CJSON_ERR }
 Status codes for the otakugifs.xyz c wrapper. More...
 
enum  otaku_format { OTAKU_GIF , OTAKU_WEBP , OTAKU_AVIF }
 Enum for the format of the image. More...
 

Functions

otaku_status otaku_reactions (otaku_reaction_list *reactions)
 Get a list of reactions.
 
bool otaku_is_reaction (const otaku_reaction_list *reactions, const char *name)
 Check if a reaction exists.
 
otaku_status otaku_reaction (otaku_result *result, const char *reaction, otaku_format format)
 Fetch a reaction.
 
otaku_status otaku_download (otaku_http_response *http_response, const char *url)
 Download an image.
 
void otaku_free_reactions (const otaku_reaction_list *reactions)
 Free a list of reactions.
 
void otaku_free_result (const otaku_result *result)
 Free a result.
 
void otaku_free_http_response (const otaku_http_response *http_response)
 Free an http response.
 

Detailed Description

This file contains structs and functions for interacting with the otakugifs.xyz API.

Enumeration Type Documentation

◆ otaku_status

Status codes for the otakugifs.xyz c wrapper.

Enumerator
OTAKU_OK 

Indicates that the operation was successful.

OTAKU_MEM_ERR 

Indicates that there was a memory allocation error.

OTAKU_LIBCURL_ERR 

Indicates that there was an error with libcurl.

OTAKU_CJSON_ERR 

Indicates that there was an error with cJSON.

◆ otaku_format

Enum for the format of the image.

Enumerator
OTAKU_GIF 

Indicates that the response image is a gif.

OTAKU_WEBP 

Indicates that the response image is a webp.

OTAKU_AVIF 

Indicates that the response image is a avif.

Function Documentation

◆ otaku_reactions()

otaku_status otaku_reactions ( otaku_reaction_list reactions)

Get a list of reactions.

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

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

Parameters
[out]reactionsPointer to a otaku_reaction_list to store the reactions in.
Returns
OTAKU_OK
OTAKU_MEM_ERR
OTAKU_LIBCURL_ERR
OTAKU_CJSON_ERR

◆ otaku_is_reaction()

bool otaku_is_reaction ( const otaku_reaction_list reactions,
const char *  name 
)

Check if a reaction exists.

This function searches for a specific reaction in a list of reactions by name.

Parameters
[in]reactionsPointer to a otaku_reaction_list to search in.
[in]nameName of the reaction to search for.
Returns
True if the reaction exists, false otherwise.

◆ otaku_reaction()

otaku_status otaku_reaction ( otaku_result result,
const char *  reaction,
otaku_format  format 
)

Fetch a reaction.

This function fetches the specified reaction endpoint of the api and parses the response into a result reaction.

It will allocate memory for the result.

Parameters
[out]resultPointer to a otaku_result to store the result in.
[in]reactionReaction to fetch. Must be a valid reaction.
[in]formatFormat of the result.
Returns
OTAKU_OK
OTAKU_MEM_ERR
OTAKU_LIBCURL_ERR
OTAKU_CJSON_ERR

◆ otaku_download()

otaku_status otaku_download ( otaku_http_response http_response,
const char *  url 
)

Download an image.

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

It will allocate memory for the response text.

Parameters
[out]http_responsePointer to a otaku_http_response to store the response in.
[in]urlURL of the image to download.
Returns
OTAKU_OK
OTAKU_MEM_ERR
OTAKU_LIBCURL_ERR

◆ otaku_free_reactions()

void otaku_free_reactions ( const otaku_reaction_list reactions)

Free a list of reactions.

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

Parameters
[in]reactionsPointer to a otaku_reaction_list to free.

◆ otaku_free_result()

void otaku_free_result ( const otaku_result result)

Free a result.

This function frees the memory allocated for the result.

Parameters
[in]resultPointer to a otaku_result to free.

◆ otaku_free_http_response()

void otaku_free_http_response ( const otaku_http_response http_response)

Free an http response.

This function frees the memory allocated for the response text.

Parameters
[in]http_responsePointer to a otaku_http_response to free.