Skip to content
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

fix: use put instead of get for set_thread_subscription #661

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

ymgyt
Copy link
Contributor

@ymgyt ymgyt commented Jun 22, 2024

The set_thread_subscription() API of the Notification API was supposed to use the PUT method according to the documentation. The implementation was using GET, so I changed it to PUT.

curl -L \
  -X PUT \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/notifications/threads/THREAD_ID/subscription \
  -d '{"ignored":false}'

Additional Context

When I used PUT, the Not Found error no longer appeared.
However, the deserialization of the response type ThreadSubscription failed.
The cause was that the reason field was an empty string. (not null)

As a result, I was able to successfully change the thread subscription with the following code:

    pub(crate) async fn unsubscribe_thread(&self, id: ThreadId) -> octocrab::Result<()> {
        #[derive(serde::Serialize)]
        struct Inner {
            ignored: bool,
        }
        #[derive(serde::Deserialize)]
        struct Response {}

        let thread = id;
        let ignored = true;

        let route = format!("/notifications/threads/{thread}/subscription");
        let body = Inner { ignored };

        self.crab
            .put::<Response, _, _>(route, Some(&body))
            .await?;
        Ok(())
    }

@XAMPPRocky
Copy link
Owner

Thank you for your PR, and congrats on your first contribution! 🎉

@XAMPPRocky XAMPPRocky merged commit 5bdbbc1 into XAMPPRocky:main Jul 29, 2024
11 checks passed
@github-actions github-actions bot mentioned this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants