jinxapi_github/v1_1_4/request/
activity_mark_notifications_as_read.rs

1//! Mark notifications as read
2//! 
3//! Marks all notifications as "read" removes it from the [default view on GitHub](https://github.com/notifications). If the number of notifications is too large to complete in one request, you will receive a `202 Accepted` status and GitHub will run an asynchronous process to mark notifications as "read." To check whether any "unread" notifications remain, you can use the [List notifications for the authenticated user](https://docs.github.com/rest/reference/activity#list-notifications-for-the-authenticated-user) endpoint and pass the query parameter `all=false`.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/activity#mark-notifications-as-read)
6
7pub struct Content<Body>
8{
9    body: Body,
10    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
11}
12
13impl<Body> Content<Body> {
14    pub fn new(body: Body) -> Self {
15        Self { body, content_type_value: None }
16    }
17
18    #[must_use]
19    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
20        self.content_type_value = Some(content_type.into());
21        self
22    }
23
24    fn content_type(&self) -> Option<&[u8]> {
25        self.content_type_value.as_deref()
26    }
27
28    fn into_body(self) -> Body {
29        self.body
30    }
31}
32
33#[cfg(feature = "hyper")]
34pub fn http_builder(
35    base_url: &str,
36    h_user_agent: &str,
37    h_accept: ::std::option::Option<&str>,
38) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
39    let default_url = concat!("https://api.github.com", "/notifications");
40    let url = if base_url.is_empty() {
41        ::http::uri::Uri::from_static(default_url)
42    } else {
43        let trimmed = base_url.trim_end_matches('/');
44        let mut url = String::with_capacity(trimmed.len() + 14);
45        url.push_str(trimmed);
46        url.push_str(&default_url[22..]);
47        url.try_into().map_err(::http::Error::from)?
48    };
49    let mut builder = ::http::request::Request::put(url);
50    builder = builder.header(
51        "User-Agent",
52        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
53    );
54    if let Some(value) = &h_accept {
55        builder = builder.header(
56            "Accept",
57            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
58        );
59    }
60    Ok(builder)
61}
62
63#[cfg(feature = "hyper")]
64pub fn hyper_request(
65    mut builder: ::http::request::Builder,
66    content: Content<::hyper::Body>,
67) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
68{
69    if let Some(content_type) = content.content_type() {
70        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
71    }
72    Ok(builder.body(content.into_body())?)
73}
74
75#[cfg(feature = "hyper")]
76impl From<::hyper::Body> for Content<::hyper::Body> {
77    fn from(body: ::hyper::Body) -> Self {
78        Self::new(body)
79    }
80}
81
82#[cfg(feature = "reqwest")]
83pub fn reqwest_builder(
84    base_url: &str,
85    h_user_agent: &str,
86    h_accept: ::std::option::Option<&str>,
87) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
88    let default_url = concat!("https://api.github.com", "/notifications");
89    let reqwest_url = if base_url.is_empty() {
90        ::reqwest::Url::parse(default_url)?
91    } else {
92        let trimmed = base_url.trim_end_matches('/');
93        let mut url = String::with_capacity(trimmed.len() + 14);
94        url.push_str(trimmed);
95        url.push_str(&default_url[22..]);
96        ::reqwest::Url::parse(&url)?
97    };
98    let mut request = ::reqwest::Request::new(::reqwest::Method::PUT, reqwest_url);
99    let headers = request.headers_mut();
100    headers.append(
101        "User-Agent",
102        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
103    );
104    if let Some(value) = &h_accept {
105        headers.append(
106            "Accept",
107            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
108        );
109    }
110    Ok(request)
111}
112
113#[cfg(feature = "reqwest")]
114pub fn reqwest_request(
115    mut builder: ::reqwest::Request,
116    content: Content<::reqwest::Body>,
117) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
118    if let Some(content_type) = content.content_type() {
119        builder.headers_mut().append(
120            ::reqwest::header::HeaderName::from_static("content-type"),
121            ::reqwest::header::HeaderValue::try_from(content_type)?,
122        );
123    }
124    *builder.body_mut() = Some(content.into_body());
125    Ok(builder)
126}
127
128#[cfg(feature = "reqwest")]
129impl From<::reqwest::Body> for Content<::reqwest::Body> {
130    fn from(body: ::reqwest::Body) -> Self {
131        Self::new(body)
132    }
133}
134
135#[cfg(feature = "reqwest-blocking")]
136pub fn reqwest_blocking_builder(
137    base_url: &str,
138    h_user_agent: &str,
139    h_accept: ::std::option::Option<&str>,
140) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
141    let default_url = concat!("https://api.github.com", "/notifications");
142    let reqwest_url = if base_url.is_empty() {
143        ::reqwest::Url::parse(default_url)?
144    } else {
145        let trimmed = base_url.trim_end_matches('/');
146        let mut url = String::with_capacity(trimmed.len() + 14);
147        url.push_str(trimmed);
148        url.push_str(&default_url[22..]);
149        ::reqwest::Url::parse(&url)?
150    };
151    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PUT, reqwest_url);
152    let headers = request.headers_mut();
153    headers.append(
154        "User-Agent",
155        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
156    );
157    if let Some(value) = &h_accept {
158        headers.append(
159            "Accept",
160            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
161        );
162    }
163    Ok(request)
164}
165
166#[cfg(feature = "reqwest-blocking")]
167pub fn reqwest_blocking_request(
168    mut builder: ::reqwest::blocking::Request,
169    content: Content<::reqwest::blocking::Body>,
170) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
171    if let Some(content_type) = content.content_type() {
172        builder.headers_mut().append(
173            ::reqwest::header::HeaderName::from_static("content-type"),
174            ::reqwest::header::HeaderValue::try_from(content_type)?,
175        );
176    }
177    *builder.body_mut() = Some(content.into_body());
178    Ok(builder)
179}
180
181#[cfg(feature = "reqwest-blocking")]
182impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
183    fn from(body: ::reqwest::blocking::Body) -> Self {
184        Self::new(body)
185    }
186}
187
188/// Types for body parameter in [`super::activity_mark_notifications_as_read`]
189pub mod body {
190    #[allow(non_snake_case)]
191    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
192    pub struct Json<'a> {
193        /// Describes the last point that notifications were checked.
194        #[serde(skip_serializing_if = "Option::is_none", default)]
195        pub last_read_at: ::std::option::Option<::std::borrow::Cow<'a, str>>,
196
197        /// Whether the notification has been read.
198        #[serde(skip_serializing_if = "Option::is_none", default)]
199        pub read: ::std::option::Option<bool>,
200
201        #[serde(flatten)]
202        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
203    }
204
205    #[cfg(feature = "hyper")]
206    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
207        type Error = crate::v1_1_4::ApiError;
208
209        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
210            Ok(
211                Self::new(::serde_json::to_vec(value)?.into())
212                .with_content_type(&b"application/json"[..])
213            )
214        }
215    }
216
217    #[cfg(feature = "reqwest")]
218    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
219        type Error = crate::v1_1_4::ApiError;
220
221        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
222            Ok(
223                Self::new(::serde_json::to_vec(value)?.into())
224                .with_content_type(&b"application/json"[..])
225            )
226        }
227    }
228
229    #[cfg(feature = "reqwest-blocking")]
230    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
231        type Error = crate::v1_1_4::ApiError;
232
233        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
234            Ok(
235                Self::new(::serde_json::to_vec(value)?.into())
236                .with_content_type(&b"application/json"[..])
237            )
238        }
239    }
240}