XAMPPRocky / octocrab

A modern, extensible GitHub API Client for Rust.
Other
1.07k stars 261 forks source link

fix: use put instead of get for set_thread_subscription #661

Closed ymgyt closed 2 months ago

ymgyt commented 3 months ago

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 commented 2 months ago

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