Skip to content

Commit

Permalink
add game hash query param to patch api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland committed Nov 13, 2024
1 parent 8d8ef92 commit 612b3b6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 30 deletions.
2 changes: 2 additions & 0 deletions include/rc_api_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ typedef struct rc_api_fetch_game_data_request_t {
const char* api_token;
/* The unique identifier of the game */
uint32_t game_id;
/* The hash associated to the game being played */
const char* game_hash;
}
rc_api_fetch_game_data_request_t;

Expand Down
4 changes: 4 additions & 0 deletions src/rapi/rc_api_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ int rc_api_init_fetch_game_data_request(rc_api_request_t* request, const rc_api_
rc_url_builder_init(&builder, &request->buffer, 48);
if (rc_api_url_build_dorequest(&builder, "patch", api_params->username, api_params->api_token)) {
rc_url_builder_append_unum_param(&builder, "g", api_params->game_id);

if (api_params->game_hash && *api_params->game_hash)
rc_url_builder_append_str_param(&builder, "m", api_params->game_hash);

request->post_data = rc_url_builder_finalize(&builder);
request->content_type = RC_CONTENT_TYPE_URLENCODED;
}
Expand Down
1 change: 1 addition & 0 deletions src/rc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,7 @@ static void rc_client_begin_fetch_game_data(rc_client_load_state_t* load_state)
fetch_game_data_request.username = client->user.username;
fetch_game_data_request.api_token = client->user.token;
fetch_game_data_request.game_id = load_state->hash->game_id;
fetch_game_data_request.game_hash = load_state->hash->hash;

result = rc_api_init_fetch_game_data_request(&request, &fetch_game_data_request);
if (result != RC_OK) {
Expand Down
38 changes: 38 additions & 0 deletions test/rapi/test_rc_api_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,42 @@ static void test_init_fetch_game_data_request() {
rc_api_destroy_request(&request);
}

static void test_init_fetch_game_data_request_game_hash() {
rc_api_fetch_game_data_request_t fetch_game_data_request;
rc_api_request_t request;

memset(&fetch_game_data_request, 0, sizeof(fetch_game_data_request));
fetch_game_data_request.username = "Username";
fetch_game_data_request.api_token = "API_TOKEN";
fetch_game_data_request.game_id = 1234;
fetch_game_data_request.game_hash = "ABCDEF0123456789";

ASSERT_NUM_EQUALS(rc_api_init_fetch_game_data_request(&request, &fetch_game_data_request), RC_OK);
ASSERT_STR_EQUALS(request.url, DOREQUEST_URL);
ASSERT_STR_EQUALS(request.post_data, "r=patch&u=Username&t=API_TOKEN&g=1234&m=ABCDEF0123456789");
ASSERT_STR_EQUALS(request.content_type, RC_CONTENT_TYPE_URLENCODED);

rc_api_destroy_request(&request);
}

static void test_init_fetch_game_data_request_game_hash_empty(void) {
rc_api_fetch_game_data_request_t fetch_game_data_request;
rc_api_request_t request;

memset(&fetch_game_data_request, 0, sizeof(fetch_game_data_request));
fetch_game_data_request.username = "Username";
fetch_game_data_request.api_token = "API_TOKEN";
fetch_game_data_request.game_id = 1234;
fetch_game_data_request.game_hash = "";

ASSERT_NUM_EQUALS(rc_api_init_fetch_game_data_request(&request, &fetch_game_data_request), RC_OK);
ASSERT_STR_EQUALS(request.url, DOREQUEST_URL);
ASSERT_STR_EQUALS(request.post_data, "r=patch&u=Username&t=API_TOKEN&g=1234");
ASSERT_STR_EQUALS(request.content_type, RC_CONTENT_TYPE_URLENCODED);

rc_api_destroy_request(&request);
}

static void test_init_fetch_game_data_request_no_id() {
rc_api_fetch_game_data_request_t fetch_game_data_request;
rc_api_request_t request;
Expand Down Expand Up @@ -1270,6 +1306,8 @@ void test_rapi_runtime(void) {

/* patch */
TEST(test_init_fetch_game_data_request);
TEST(test_init_fetch_game_data_request_game_hash);
TEST(test_init_fetch_game_data_request_game_hash_empty);
TEST(test_init_fetch_game_data_request_no_id);

TEST(test_process_fetch_game_data_response_empty);
Expand Down
Loading

0 comments on commit 612b3b6

Please sign in to comment.