Skip to content

Commit

Permalink
fix url bug
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Downs <brian.downs@gmail.com>
  • Loading branch information
briandowns committed Dec 21, 2024
1 parent 5d29a61 commit b197789
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
61 changes: 57 additions & 4 deletions bluesky.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define GET_FOLLOWS_URL API_BASE "/app.bsky.graph.getFollows"
#define GET_FOLLOWERS_URL API_BASE "/app.bsky.graph.getFollowers"
#define GET_AUTHOR_FEED API_BASE "/app.bsky.feed.getAuthorFeed"
#define GET_ACTOR_LIKES_URL "/app.bsky.feed.getActorLikes"

#define SET_BASIC_CURL_CONFIG \
curl_easy_setopt(curl, CURLOPT_URL, url); \
Expand Down Expand Up @@ -411,7 +412,7 @@ bs_client_followers_get(const char *handle,
chunk = curl_slist_append(chunk, token_header);

char *url = calloc(DEFAULT_URL_SIZE, sizeof(char));
strcpy(url, GET_FOLLOWS_URL);
strcpy(url, GET_FOLLOWERS_URL);
strcat(url, "?actor=");
strcat(url, handle);

Expand Down Expand Up @@ -452,7 +453,7 @@ bs_client_followers_get(const char *handle,
}

bs_client_response_t*
bs_profile_preferences()
bs_client_profile_preferences()
{
bs_client_response_t *response = bs_client_response_new();
struct curl_slist *chunk = NULL;
Expand All @@ -476,7 +477,7 @@ bs_profile_preferences()
}

bs_client_response_t*
bs_timeline_get(const bs_client_pagination_opts *opts)
bs_client_timeline_get(const bs_client_pagination_opts *opts)
{
bs_client_response_t *response = bs_client_response_new();
struct curl_slist *chunk = NULL;
Expand Down Expand Up @@ -524,7 +525,8 @@ bs_timeline_get(const bs_client_pagination_opts *opts)
}

bs_client_response_t*
bs_author_feed_get(const char *did, const bs_client_pagination_opts *opts)
bs_client_author_feed_get(const char *did,
const bs_client_pagination_opts *opts)
{
bs_client_response_t *response = bs_client_response_new();
struct curl_slist *chunk = NULL;
Expand Down Expand Up @@ -573,6 +575,57 @@ bs_author_feed_get(const char *did, const bs_client_pagination_opts *opts)
return response;
}

bs_client_response_t*
bs_client_actor_likes_get(const char *handle,
const bs_client_pagination_opts *opts)
{
bs_client_response_t *response = bs_client_response_new();
struct curl_slist *chunk = NULL;

chunk = curl_slist_append(chunk, BS_REQ_JSON_HEADER);
chunk = curl_slist_append(chunk, token_header);

char *url = calloc(DEFAULT_URL_SIZE, sizeof(char));
strcpy(url, GET_ACTOR_LIKES_URL);
strcat(url, "?actor=");
strcat(url, handle);

if (opts != NULL) {
if (opts->limit != 0 && opts->limit >= 50) {
if (opts->limit > 100) {
char *err_msg = "limit max value is 100";
response->err_msg = calloc(strlen(err_msg)+1, sizeof(char));
strcpy(response->err_msg, err_msg);
CALL_CLEANUP;
return response;
}

strcat(url, "&limit=");
char lim_val[11] = {0};
sprintf(lim_val, "%d", opts->limit);
strcat(url, lim_val);
} else {
strcat(url, "&limit=100");
}

if (opts->cursor != NULL) {
strcat(url, "&cursor=");
strcat(url, opts->cursor);
}
}

SET_BASIC_CURL_CONFIG;
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);

CURLcode res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response->resp_code);
CURL_CALL_ERROR_CHECK;

CALL_CLEANUP;

return response;
}

void
bs_client_free()
{
Expand Down
14 changes: 11 additions & 3 deletions bluesky.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,29 @@ bs_client_followers_get(const char *handle,
* Retrieve the profile preferences for the authenticated user.
*/
bs_client_response_t*
bs_profile_preferences();
bs_client_profile_preferences();

/**
* Get the authenticated user's timeline. The JSON response has a field called
* "cursor". If this field is populated, there are more results to retrieve.
* The response memory needs to be freed by the caller.
*/
bs_client_response_t*
bs_timeline_get(const bs_client_pagination_opts *opts);
bs_client_timeline_get(const bs_client_pagination_opts *opts);

/**
* Retrieve posts from the given user DID.
*/
bs_client_response_t*
bs_author_feed_get(const char *did, const bs_client_pagination_opts *opts);
bs_client_author_feed_get(const char *did,
const bs_client_pagination_opts *opts);

/**
* Retrieve likes from the given user handle.
*/
bs_client_response_t*
bs_client_actor_likes_get(const char *handle,
const bs_client_pagination_opts *opts);

/**
* Free the memory used by the client.
Expand Down

0 comments on commit b197789

Please sign in to comment.