Scrobbles
FossilOrigin-Name: d3363883c5c1aec969de698ef0cc63af8e5808d61e12dde5ab33acda1e51b4cf
This commit is contained in:
parent
9c72241040
commit
f11802fc98
2 changed files with 75 additions and 44 deletions
|
@ -20,7 +20,7 @@
|
|||
#include <mastodont_types.h>
|
||||
#include <mastodont_account.h>
|
||||
|
||||
struct mstdnt_scrobble
|
||||
typedef struct mstdnt_scrobble
|
||||
{
|
||||
struct mstdnt_account account;
|
||||
char* album;
|
||||
|
@ -29,7 +29,13 @@ struct mstdnt_scrobble
|
|||
char* id;
|
||||
int length;
|
||||
char* title;
|
||||
};
|
||||
} mstdnt_scrobble;
|
||||
|
||||
typedef struct mstdnt_scrobbles
|
||||
{
|
||||
mstdnt_scrobble* scrobbles;
|
||||
size_t len;
|
||||
} mstdnt_scrobbles;
|
||||
|
||||
struct mstdnt_get_scrobbles_args
|
||||
{
|
||||
|
@ -40,29 +46,38 @@ struct mstdnt_get_scrobbles_args
|
|||
int limit;
|
||||
};
|
||||
|
||||
// DEPRECATED
|
||||
struct _mstdnt_scrobbles_cb_args
|
||||
{
|
||||
struct mstdnt_scrobble** scrobbles;
|
||||
size_t* size;
|
||||
};
|
||||
|
||||
int mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args args);
|
||||
|
||||
int mstdnt_scrobbles_json(struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
int
|
||||
mstdnt_scrobbles_json(struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
|
||||
int mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* arg);
|
||||
int
|
||||
mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* arg,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js);
|
||||
int
|
||||
mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobble(mstdnt_scrobble* scrobble);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobbles(mstdnt_scrobbles* scrobbles);
|
||||
|
||||
#endif /* MASTODONT_SCROBBLES_H */
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include <mastodont_request.h>
|
||||
#include <mastodont_generate.h>
|
||||
|
||||
int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
||||
int
|
||||
mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -46,45 +47,60 @@ int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
|||
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_scrobbles_json, struct mstdnt_scrobble, mstdnt_scrobble_json)
|
||||
|
||||
int mstdnt_scrobbles_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* _args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_scrobbles_cb_args* args = _args;
|
||||
return mstdnt_scrobbles_json(args->scrobbles, args->size, json);
|
||||
mstdnt_scrobbles* scrobbles = mstdnt_malloc(sizeof(mstdnt_scrobbles));
|
||||
data->data = scrobbles;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_scrobbles;
|
||||
return mstdnt_scrobbles_json(&(scrobbles->scrobbles), &(scrobbles->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args args)
|
||||
{
|
||||
struct _mstdnt_scrobbles_cb_args req_cb_args = { scrobbles, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/accounts/%s/scrobbles", id);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&req_cb_args,
|
||||
mstdnt_scrobbles_json_callback
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_scrobbles_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobble(mstdnt_scrobble* scrobble)
|
||||
{
|
||||
mstdnt_cleanup_account(&(scrobble->account));
|
||||
}
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobbles(mstdnt_scrobbles* scrobbles)
|
||||
{
|
||||
if (!scrobbles) return;
|
||||
for (size_t i = 0; i < scrobbles->len; ++i)
|
||||
{
|
||||
mstdnt_cleanup_scrobble(scrobbles->scrobbles + i);
|
||||
}
|
||||
mstdnt_free(scrobbles->scrobbles);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue