jinxapi_github/v1_1_4/request/
orgs_update_webhook.rs

1//! Update an organization webhook
2//! 
3//! Updates a webhook configured in an organization. When you update a webhook, the `secret` will be overwritten. If you previously had a `secret` set, you must provide the same `secret` or set a new `secret` or the secret will be removed. If you are only updating individual webhook `config` properties, use "[Update a webhook configuration for an organization](/rest/reference/orgs#update-a-webhook-configuration-for-an-organization)."
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/orgs#update-an-organization-webhook)
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
33fn url_string(
34    base_url: &str,
35    p_org: &str,
36    p_hook_id: i64,
37) -> Result<String, crate::v1_1_4::ApiError> {
38    let trimmed = if base_url.is_empty() {
39        "https://api.github.com"
40    } else {
41        base_url.trim_end_matches('/')
42    };
43    let mut url = String::with_capacity(trimmed.len() + 31);
44    url.push_str(trimmed);
45    url.push_str("/orgs/");
46    ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
47    url.push_str("/hooks/");
48    ::querylizer::Simple::extend(&mut url, &p_hook_id, false, &::querylizer::encode_path)?;
49    Ok(url)
50}
51
52#[cfg(feature = "hyper")]
53pub fn http_builder(
54    base_url: &str,
55    p_org: &str,
56    p_hook_id: i64,
57    h_user_agent: &str,
58    h_accept: ::std::option::Option<&str>,
59) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
60    let url = url_string(
61        base_url,
62        p_org,
63        p_hook_id,
64    )?;
65    let mut builder = ::http::request::Request::patch(url);
66    builder = builder.header(
67        "User-Agent",
68        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
69    );
70    if let Some(value) = &h_accept {
71        builder = builder.header(
72            "Accept",
73            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
74        );
75    }
76    Ok(builder)
77}
78
79#[cfg(feature = "hyper")]
80pub fn hyper_request(
81    mut builder: ::http::request::Builder,
82    content: Content<::hyper::Body>,
83) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
84{
85    if let Some(content_type) = content.content_type() {
86        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
87    }
88    Ok(builder.body(content.into_body())?)
89}
90
91#[cfg(feature = "hyper")]
92impl From<::hyper::Body> for Content<::hyper::Body> {
93    fn from(body: ::hyper::Body) -> Self {
94        Self::new(body)
95    }
96}
97
98#[cfg(feature = "reqwest")]
99pub fn reqwest_builder(
100    base_url: &str,
101    p_org: &str,
102    p_hook_id: i64,
103    h_user_agent: &str,
104    h_accept: ::std::option::Option<&str>,
105) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
106    let url = url_string(
107        base_url,
108        p_org,
109        p_hook_id,
110    )?;
111    let reqwest_url = ::reqwest::Url::parse(&url)?;
112    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
113    let headers = request.headers_mut();
114    headers.append(
115        "User-Agent",
116        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
117    );
118    if let Some(value) = &h_accept {
119        headers.append(
120            "Accept",
121            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
122        );
123    }
124    Ok(request)
125}
126
127#[cfg(feature = "reqwest")]
128pub fn reqwest_request(
129    mut builder: ::reqwest::Request,
130    content: Content<::reqwest::Body>,
131) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
132    if let Some(content_type) = content.content_type() {
133        builder.headers_mut().append(
134            ::reqwest::header::HeaderName::from_static("content-type"),
135            ::reqwest::header::HeaderValue::try_from(content_type)?,
136        );
137    }
138    *builder.body_mut() = Some(content.into_body());
139    Ok(builder)
140}
141
142#[cfg(feature = "reqwest")]
143impl From<::reqwest::Body> for Content<::reqwest::Body> {
144    fn from(body: ::reqwest::Body) -> Self {
145        Self::new(body)
146    }
147}
148
149#[cfg(feature = "reqwest-blocking")]
150pub fn reqwest_blocking_builder(
151    base_url: &str,
152    p_org: &str,
153    p_hook_id: i64,
154    h_user_agent: &str,
155    h_accept: ::std::option::Option<&str>,
156) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
157    let url = url_string(
158        base_url,
159        p_org,
160        p_hook_id,
161    )?;
162    let reqwest_url = ::reqwest::Url::parse(&url)?;
163    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
164    let headers = request.headers_mut();
165    headers.append(
166        "User-Agent",
167        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
168    );
169    if let Some(value) = &h_accept {
170        headers.append(
171            "Accept",
172            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
173        );
174    }
175    Ok(request)
176}
177
178#[cfg(feature = "reqwest-blocking")]
179pub fn reqwest_blocking_request(
180    mut builder: ::reqwest::blocking::Request,
181    content: Content<::reqwest::blocking::Body>,
182) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
183    if let Some(content_type) = content.content_type() {
184        builder.headers_mut().append(
185            ::reqwest::header::HeaderName::from_static("content-type"),
186            ::reqwest::header::HeaderValue::try_from(content_type)?,
187        );
188    }
189    *builder.body_mut() = Some(content.into_body());
190    Ok(builder)
191}
192
193#[cfg(feature = "reqwest-blocking")]
194impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
195    fn from(body: ::reqwest::blocking::Body) -> Self {
196        Self::new(body)
197    }
198}
199
200/// Types for body parameter in [`super::orgs_update_webhook`]
201pub mod body {
202    #[allow(non_snake_case)]
203    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
204    pub struct Json<'a> {
205        #[serde(skip_serializing_if = "Option::is_none", default)]
206        pub config: ::std::option::Option<crate::v1_1_4::request::orgs_update_webhook::body::json::Config<'a>>,
207
208        /// Determines what [events](https://docs.github.com/webhooks/event-payloads) the hook is triggered for.
209        #[serde(skip_serializing_if = "Option::is_none", default)]
210        pub events: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
211
212        /// Determines if notifications are sent when the webhook is triggered. Set to `true` to send notifications.
213        #[serde(skip_serializing_if = "Option::is_none", default)]
214        pub active: ::std::option::Option<bool>,
215
216        /// # Example
217        /// 
218        /// ```json
219        /// "\"web\""
220        /// ```
221        #[serde(skip_serializing_if = "Option::is_none", default)]
222        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
223
224        #[serde(flatten)]
225        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
226    }
227
228    /// Types for fields in [`Json`]
229    pub mod json {
230        /// Key/value pairs to provide settings for this webhook. [These are defined below](https://docs.github.com/rest/reference/orgs#update-hook-config-params).
231        #[allow(non_snake_case)]
232        #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
233        pub struct Config<'a> {
234            /// The URL to which the payloads will be delivered.
235            /// 
236            /// # Example
237            /// 
238            /// ```json
239            /// "https://example.com/webhook"
240            /// ```
241            pub url: ::std::borrow::Cow<'a, str>,
242
243            /// The media type used to serialize the payloads. Supported values include `json` and `form`. The default is `form`.
244            /// 
245            /// # Example
246            /// 
247            /// ```json
248            /// "\"json\""
249            /// ```
250            #[serde(skip_serializing_if = "Option::is_none", default)]
251            pub content_type: ::std::option::Option<::std::borrow::Cow<'a, str>>,
252
253            /// If provided, the `secret` will be used as the `key` to generate the HMAC hex digest value for [delivery signature headers](https://docs.github.com/webhooks/event-payloads/#delivery-headers).
254            /// 
255            /// # Example
256            /// 
257            /// ```json
258            /// "\"********\""
259            /// ```
260            #[serde(skip_serializing_if = "Option::is_none", default)]
261            pub secret: ::std::option::Option<::std::borrow::Cow<'a, str>>,
262
263            #[serde(skip_serializing_if = "Option::is_none", default)]
264            pub insecure_ssl: ::std::option::Option<::serde_json::value::Value>,
265
266            #[serde(flatten)]
267            pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
268        }
269    }
270
271    #[cfg(feature = "hyper")]
272    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
273        type Error = crate::v1_1_4::ApiError;
274
275        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
276            Ok(
277                Self::new(::serde_json::to_vec(value)?.into())
278                .with_content_type(&b"application/json"[..])
279            )
280        }
281    }
282
283    #[cfg(feature = "reqwest")]
284    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
285        type Error = crate::v1_1_4::ApiError;
286
287        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
288            Ok(
289                Self::new(::serde_json::to_vec(value)?.into())
290                .with_content_type(&b"application/json"[..])
291            )
292        }
293    }
294
295    #[cfg(feature = "reqwest-blocking")]
296    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
297        type Error = crate::v1_1_4::ApiError;
298
299        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
300            Ok(
301                Self::new(::serde_json::to_vec(value)?.into())
302                .with_content_type(&b"application/json"[..])
303            )
304        }
305    }
306}