-
Notifications
You must be signed in to change notification settings - Fork 42
Fix/parsing issue#504 #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix/parsing issue#504 #507
Conversation
I am encountering these test failures, the changes that i have done are running fine on local machine but i am not able to understand why is this failing. I would appreciate a lot if anyone could suggest what changes can be done? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, just three small things. The rest is just things I noticed that already existed before your PR.
I'll keep in mind to check for the get-ad-schedule response.
struct IsWrong { | ||
snooze_count: i32, | ||
snooze_refresh_at: i32, | ||
next_ad_at: i32, | ||
duration: i32, | ||
last_ad_at: i32, | ||
preroll_free_time: i32, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is still returned. We should check that this isn't returned anymore by Twitch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Twitch can still return numbers here (https://redirect.github.com/twitchdev/issues/issues/857):
> twitch api get channels/ads -q broadcaster_id=129546453
{
"data": [
{
"duration": 0,
"last_ad_at": 0,
"next_ad_at": 0,
"preroll_free_time": 0,
"snooze_count": 3,
"snooze_refresh_at": 0
}
]
}
Undo this change for now.
let resp: helix::InnerResponse<[ChatSettings; 1]> = parse_json(response, true) | ||
.map_err(|e| { | ||
HelixRequestPatchError::DeserializeError( | ||
response.to_string(), | ||
e, | ||
uri.clone(), | ||
status, | ||
) | ||
})?; | ||
resp.data.into_iter().next().ok_or( | ||
helix::HelixRequestPatchError::InvalidResponse { | ||
reason: "expected at least one element in data", | ||
response: response.to_string(), | ||
status, | ||
uri: uri.clone(), | ||
}, | ||
)? | ||
let [data] = resp.data; | ||
data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use parse_single_return
too, no? It checks for the status as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I will change it.
please remove the merge commit :) |
…ypted/twitch_api into fix/parsing-issue#504
I have added a commit with the updated changes, Please review them and give your suggestions, if any!! |
need to fix the tests, they are failing due to a merge you did. also please remove the merge commits, you should be able to find some guides online or you can ask for more precise help. Specifically what I think you should need to do is
and then fix whatever issues arise from that, could also remove I'd also like it if you squashed the commits afterwards :) |
struct IsWrong { | ||
snooze_count: i32, | ||
snooze_refresh_at: i32, | ||
next_ad_at: i32, | ||
duration: i32, | ||
last_ad_at: i32, | ||
preroll_free_time: i32, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Twitch can still return numbers here (https://redirect.github.com/twitchdev/issues/issues/857):
> twitch api get channels/ads -q broadcaster_id=129546453
{
"data": [
{
"duration": 0,
"last_ad_at": 0,
"next_ad_at": 0,
"preroll_free_time": 0,
"snooze_count": 3,
"snooze_refresh_at": 0
}
]
}
Undo this change for now.
🤔 we could also use GitHub's squash merge. There, merges get squashed away |
This PR fixes the parsing of Twitch Helix API endpoints that return only a single item in the data array. Instead of parsing responses into an intermediate
Vec<T>
and then extracting the first element with .into_iter().next(), we now parse directly into [T; 1] (a fixed-size array) or use theparse_single_return
helper function where appropriate.Fixes #504
Updated Files:
src/helix/endpoints/channels/get_ad_schedule.rs
src/helix/endpoints/channels/start_commercial.rs
src/helix/endpoints/charity/get_charity_campaign.rs
src/helix/endpoints/chat/update_chat_settings.rs
src/helix/endpoints/eventsub/create_eventsub_subscription.rs
src/helix/endpoints/moderation/ban_user.rs
src/helix/endpoints/moderation/get_shield_mode_status.rs
src/helix/endpoints/moderation/update_shield_mode_status.rs
src/helix/endpoints/moderation/warn_chat_user.rs
src/helix/endpoints/points/create_custom_rewards.rs
src/helix/endpoints/points/update_custom_reward.rs
src/helix/endpoints/points/update_redemption_status.rs
src/helix/endpoints/polls/create_poll.rs
src/helix/endpoints/polls/end_poll.rs
src/helix/endpoints/predictions/create_prediction.rs
src/helix/endpoints/predictions/end_prediction.rs
src/helix/endpoints/raids/start_a_raid.rs
src/helix/endpoints/subscriptions/check_user_subscription.rs