jinxapi_github/v1_1_4/request/
orgs_create_invitation.rs

1//! Create an organization invitation
2//! 
3//! Invite people to an organization by using their GitHub user ID or their email address. In order to create invitations in an organization, the authenticated user must be an organization owner.
4//! 
5//! This endpoint triggers [notifications](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/about-notifications). Creating content too quickly using this endpoint may result in secondary rate limiting. See "[Secondary rate limits](https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits)" and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.
6//! 
7//! [API method documentation](https://docs.github.com/rest/reference/orgs#create-an-organization-invitation)
8
9pub struct Content<Body>
10{
11    body: Body,
12    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
13}
14
15impl<Body> Content<Body> {
16    pub fn new(body: Body) -> Self {
17        Self { body, content_type_value: None }
18    }
19
20    #[must_use]
21    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
22        self.content_type_value = Some(content_type.into());
23        self
24    }
25
26    fn content_type(&self) -> Option<&[u8]> {
27        self.content_type_value.as_deref()
28    }
29
30    fn into_body(self) -> Body {
31        self.body
32    }
33}
34
35fn url_string(
36    base_url: &str,
37    p_org: &str,
38) -> Result<String, crate::v1_1_4::ApiError> {
39    let trimmed = if base_url.is_empty() {
40        "https://api.github.com"
41    } else {
42        base_url.trim_end_matches('/')
43    };
44    let mut url = String::with_capacity(trimmed.len() + 35);
45    url.push_str(trimmed);
46    url.push_str("/orgs/");
47    ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
48    url.push_str("/invitations");
49    Ok(url)
50}
51
52#[cfg(feature = "hyper")]
53pub fn http_builder(
54    base_url: &str,
55    p_org: &str,
56    h_user_agent: &str,
57    h_accept: ::std::option::Option<&str>,
58) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
59    let url = url_string(
60        base_url,
61        p_org,
62    )?;
63    let mut builder = ::http::request::Request::post(url);
64    builder = builder.header(
65        "User-Agent",
66        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
67    );
68    if let Some(value) = &h_accept {
69        builder = builder.header(
70            "Accept",
71            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
72        );
73    }
74    Ok(builder)
75}
76
77#[cfg(feature = "hyper")]
78pub fn hyper_request(
79    mut builder: ::http::request::Builder,
80    content: Content<::hyper::Body>,
81) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
82{
83    if let Some(content_type) = content.content_type() {
84        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
85    }
86    Ok(builder.body(content.into_body())?)
87}
88
89#[cfg(feature = "hyper")]
90impl From<::hyper::Body> for Content<::hyper::Body> {
91    fn from(body: ::hyper::Body) -> Self {
92        Self::new(body)
93    }
94}
95
96#[cfg(feature = "reqwest")]
97pub fn reqwest_builder(
98    base_url: &str,
99    p_org: &str,
100    h_user_agent: &str,
101    h_accept: ::std::option::Option<&str>,
102) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
103    let url = url_string(
104        base_url,
105        p_org,
106    )?;
107    let reqwest_url = ::reqwest::Url::parse(&url)?;
108    let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
109    let headers = request.headers_mut();
110    headers.append(
111        "User-Agent",
112        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
113    );
114    if let Some(value) = &h_accept {
115        headers.append(
116            "Accept",
117            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
118        );
119    }
120    Ok(request)
121}
122
123#[cfg(feature = "reqwest")]
124pub fn reqwest_request(
125    mut builder: ::reqwest::Request,
126    content: Content<::reqwest::Body>,
127) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
128    if let Some(content_type) = content.content_type() {
129        builder.headers_mut().append(
130            ::reqwest::header::HeaderName::from_static("content-type"),
131            ::reqwest::header::HeaderValue::try_from(content_type)?,
132        );
133    }
134    *builder.body_mut() = Some(content.into_body());
135    Ok(builder)
136}
137
138#[cfg(feature = "reqwest")]
139impl From<::reqwest::Body> for Content<::reqwest::Body> {
140    fn from(body: ::reqwest::Body) -> Self {
141        Self::new(body)
142    }
143}
144
145#[cfg(feature = "reqwest-blocking")]
146pub fn reqwest_blocking_builder(
147    base_url: &str,
148    p_org: &str,
149    h_user_agent: &str,
150    h_accept: ::std::option::Option<&str>,
151) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
152    let url = url_string(
153        base_url,
154        p_org,
155    )?;
156    let reqwest_url = ::reqwest::Url::parse(&url)?;
157    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
158    let headers = request.headers_mut();
159    headers.append(
160        "User-Agent",
161        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
162    );
163    if let Some(value) = &h_accept {
164        headers.append(
165            "Accept",
166            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
167        );
168    }
169    Ok(request)
170}
171
172#[cfg(feature = "reqwest-blocking")]
173pub fn reqwest_blocking_request(
174    mut builder: ::reqwest::blocking::Request,
175    content: Content<::reqwest::blocking::Body>,
176) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
177    if let Some(content_type) = content.content_type() {
178        builder.headers_mut().append(
179            ::reqwest::header::HeaderName::from_static("content-type"),
180            ::reqwest::header::HeaderValue::try_from(content_type)?,
181        );
182    }
183    *builder.body_mut() = Some(content.into_body());
184    Ok(builder)
185}
186
187#[cfg(feature = "reqwest-blocking")]
188impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
189    fn from(body: ::reqwest::blocking::Body) -> Self {
190        Self::new(body)
191    }
192}
193
194/// Types for body parameter in [`super::orgs_create_invitation`]
195pub mod body {
196    #[allow(non_snake_case)]
197    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
198    pub struct Json<'a> {
199        /// **Required unless you provide `email`**. GitHub user ID for the person you are inviting.
200        #[serde(skip_serializing_if = "Option::is_none", default)]
201        pub invitee_id: ::std::option::Option<i64>,
202
203        /// **Required unless you provide `invitee_id`**. Email address of the person you are inviting, which can be an existing GitHub user.
204        #[serde(skip_serializing_if = "Option::is_none", default)]
205        pub email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
206
207        /// Specify role for new member. Can be one of:  
208        /// \* `admin` - Organization owners with full administrative rights to the organization and complete access to all repositories and teams.  
209        /// \* `direct_member` - Non-owner organization members with ability to see other members and join teams by invitation.  
210        /// \* `billing_manager` - Non-owner organization members with ability to manage the billing settings of your organization.
211        #[serde(skip_serializing_if = "Option::is_none", default)]
212        pub role: ::std::option::Option<::std::borrow::Cow<'a, str>>,
213
214        /// Specify IDs for the teams you want to invite new members to.
215        #[serde(skip_serializing_if = "Option::is_none", default)]
216        pub team_ids: ::std::option::Option<::std::borrow::Cow<'a, [i64]>>,
217
218        #[serde(flatten)]
219        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
220    }
221
222    #[cfg(feature = "hyper")]
223    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
224        type Error = crate::v1_1_4::ApiError;
225
226        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
227            Ok(
228                Self::new(::serde_json::to_vec(value)?.into())
229                .with_content_type(&b"application/json"[..])
230            )
231        }
232    }
233
234    #[cfg(feature = "reqwest")]
235    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
236        type Error = crate::v1_1_4::ApiError;
237
238        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
239            Ok(
240                Self::new(::serde_json::to_vec(value)?.into())
241                .with_content_type(&b"application/json"[..])
242            )
243        }
244    }
245
246    #[cfg(feature = "reqwest-blocking")]
247    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
248        type Error = crate::v1_1_4::ApiError;
249
250        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
251            Ok(
252                Self::new(::serde_json::to_vec(value)?.into())
253                .with_content_type(&b"application/json"[..])
254            )
255        }
256    }
257}