//! Create an organization invitation
//!
//! 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.
//!
//! 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.
//!
//! [API method documentation](https://docs.github.com/rest/reference/orgs#create-an-organization-invitation)
pub struct Content<Body>
{
body: Body,
content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
}
impl<Body> Content<Body> {
pub fn new(body: Body) -> Self {
Self { body, content_type_value: None }
}
#[must_use]
pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
self.content_type_value = Some(content_type.into());
self
}
fn content_type(&self) -> Option<&[u8]> {
self.content_type_value.as_deref()
}
fn into_body(self) -> Body {
self.body
}
}
fn url_string(
base_url: &str,
p_org: &str,
) -> Result<String, crate::v1_1_4::ApiError> {
let trimmed = if base_url.is_empty() {
"https://api.github.com"
} else {
base_url.trim_end_matches('/')
};
let mut url = String::with_capacity(trimmed.len() + 35);
url.push_str(trimmed);
url.push_str("/orgs/");
::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
url.push_str("/invitations");
Ok(url)
}
#[cfg(feature = "hyper")]
pub fn http_builder(
base_url: &str,
p_org: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_org,
)?;
let mut builder = ::http::request::Request::post(url);
builder = builder.header(
"User-Agent",
&::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
);
if let Some(value) = &h_accept {
builder = builder.header(
"Accept",
&::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
);
}
Ok(builder)
}
#[cfg(feature = "hyper")]
pub fn hyper_request(
mut builder: ::http::request::Builder,
content: Content<::hyper::Body>,
) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
{
if let Some(content_type) = content.content_type() {
builder = builder.header(::http::header::CONTENT_TYPE, content_type);
}
Ok(builder.body(content.into_body())?)
}
#[cfg(feature = "hyper")]
impl From<::hyper::Body> for Content<::hyper::Body> {
fn from(body: ::hyper::Body) -> Self {
Self::new(body)
}
}
#[cfg(feature = "reqwest")]
pub fn reqwest_builder(
base_url: &str,
p_org: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_org,
)?;
let reqwest_url = ::reqwest::Url::parse(&url)?;
let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
let headers = request.headers_mut();
headers.append(
"User-Agent",
::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
);
if let Some(value) = &h_accept {
headers.append(
"Accept",
::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
);
}
Ok(request)
}
#[cfg(feature = "reqwest")]
pub fn reqwest_request(
mut builder: ::reqwest::Request,
content: Content<::reqwest::Body>,
) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
if let Some(content_type) = content.content_type() {
builder.headers_mut().append(
::reqwest::header::HeaderName::from_static("content-type"),
::reqwest::header::HeaderValue::try_from(content_type)?,
);
}
*builder.body_mut() = Some(content.into_body());
Ok(builder)
}
#[cfg(feature = "reqwest")]
impl From<::reqwest::Body> for Content<::reqwest::Body> {
fn from(body: ::reqwest::Body) -> Self {
Self::new(body)
}
}
#[cfg(feature = "reqwest-blocking")]
pub fn reqwest_blocking_builder(
base_url: &str,
p_org: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_org,
)?;
let reqwest_url = ::reqwest::Url::parse(&url)?;
let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
let headers = request.headers_mut();
headers.append(
"User-Agent",
::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
);
if let Some(value) = &h_accept {
headers.append(
"Accept",
::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
);
}
Ok(request)
}
#[cfg(feature = "reqwest-blocking")]
pub fn reqwest_blocking_request(
mut builder: ::reqwest::blocking::Request,
content: Content<::reqwest::blocking::Body>,
) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
if let Some(content_type) = content.content_type() {
builder.headers_mut().append(
::reqwest::header::HeaderName::from_static("content-type"),
::reqwest::header::HeaderValue::try_from(content_type)?,
);
}
*builder.body_mut() = Some(content.into_body());
Ok(builder)
}
#[cfg(feature = "reqwest-blocking")]
impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
fn from(body: ::reqwest::blocking::Body) -> Self {
Self::new(body)
}
}
/// Types for body parameter in [`super::orgs_create_invitation`]
pub mod body {
#[allow(non_snake_case)]
#[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
pub struct Json<'a> {
/// **Required unless you provide `email`**. GitHub user ID for the person you are inviting.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub invitee_id: ::std::option::Option<i64>,
/// **Required unless you provide `invitee_id`**. Email address of the person you are inviting, which can be an existing GitHub user.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// Specify role for new member. Can be one of:
/// \* `admin` - Organization owners with full administrative rights to the organization and complete access to all repositories and teams.
/// \* `direct_member` - Non-owner organization members with ability to see other members and join teams by invitation.
/// \* `billing_manager` - Non-owner organization members with ability to manage the billing settings of your organization.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub role: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// Specify IDs for the teams you want to invite new members to.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub team_ids: ::std::option::Option<::std::borrow::Cow<'a, [i64]>>,
#[serde(flatten)]
pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
}
#[cfg(feature = "hyper")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
#[cfg(feature = "reqwest")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
#[cfg(feature = "reqwest-blocking")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
}