jinxapi_github/v1_1_4/request/
teams_add_member_legacy.rs

1//! Add team member (Legacy)
2//! 
3//! The "Add team member" endpoint (described below) is deprecated.
4//! 
5//! We recommend using the [Add or update team membership for a user](https://docs.github.com/rest/reference/teams#add-or-update-team-membership-for-a-user) endpoint instead. It allows you to invite new organization members to your teams.
6//! 
7//! Team synchronization is available for organizations using GitHub Enterprise Cloud. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation.
8//! 
9//! To add someone to a team, the authenticated user must be an organization owner or a team maintainer in the team they're changing. The person being added to the team must be a member of the team's organization.
10//! 
11//! **Note:** When you have team synchronization set up for a team with your organization's identity provider (IdP), you will see an error if you attempt to use the API for making changes to the team's membership. If you have access to manage group membership in your IdP, you can manage GitHub team membership through your identity provider, which automatically adds and removes team members in an organization. For more information, see "[Synchronizing teams between your identity provider and GitHub](https://docs.github.com/articles/synchronizing-teams-between-your-identity-provider-and-github/)."
12//! 
13//! Note that you'll need to set `Content-Length` to zero when calling out to this endpoint. For more information, see "[HTTP verbs](https://docs.github.com/rest/overview/resources-in-the-rest-api#http-verbs)."
14//! 
15//! [API method documentation](https://docs.github.com/rest/reference/teams#add-team-member-legacy)
16
17
18fn url_string(
19    base_url: &str,
20    p_team_id: i64,
21    p_username: &str,
22) -> Result<String, crate::v1_1_4::ApiError> {
23    let trimmed = if base_url.is_empty() {
24        "https://api.github.com"
25    } else {
26        base_url.trim_end_matches('/')
27    };
28    let mut url = String::with_capacity(trimmed.len() + 34);
29    url.push_str(trimmed);
30    url.push_str("/teams/");
31    ::querylizer::Simple::extend(&mut url, &p_team_id, false, &::querylizer::encode_path)?;
32    url.push_str("/members/");
33    ::querylizer::Simple::extend(&mut url, &p_username, false, &::querylizer::encode_path)?;
34    Ok(url)
35}
36
37#[cfg(feature = "hyper")]
38pub fn http_builder(
39    base_url: &str,
40    p_team_id: i64,
41    p_username: &str,
42    h_user_agent: &str,
43    h_accept: ::std::option::Option<&str>,
44) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
45    let url = url_string(
46        base_url,
47        p_team_id,
48        p_username,
49    )?;
50    let mut builder = ::http::request::Request::put(url);
51    builder = builder.header(
52        "User-Agent",
53        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
54    );
55    if let Some(value) = &h_accept {
56        builder = builder.header(
57            "Accept",
58            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
59        );
60    }
61    Ok(builder)
62}
63
64#[cfg(feature = "hyper")]
65#[inline]
66pub fn hyper_request(
67    builder: ::http::request::Builder,
68) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError> {
69    Ok(builder.body(::hyper::Body::empty())?)
70}
71
72#[cfg(feature = "reqwest")]
73pub fn reqwest_builder(
74    base_url: &str,
75    p_team_id: i64,
76    p_username: &str,
77    h_user_agent: &str,
78    h_accept: ::std::option::Option<&str>,
79) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
80    let url = url_string(
81        base_url,
82        p_team_id,
83        p_username,
84    )?;
85    let reqwest_url = ::reqwest::Url::parse(&url)?;
86    let mut request = ::reqwest::Request::new(::reqwest::Method::PUT, reqwest_url);
87    let headers = request.headers_mut();
88    headers.append(
89        "User-Agent",
90        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
91    );
92    if let Some(value) = &h_accept {
93        headers.append(
94            "Accept",
95            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
96        );
97    }
98    Ok(request)
99}
100
101#[cfg(feature = "reqwest")]
102#[inline(always)]
103pub fn reqwest_request(
104    builder: ::reqwest::Request,
105) -> Result<::reqwest::Request, crate::v1_1_4::ApiError>
106{
107    Ok(builder)
108}
109
110#[cfg(feature = "reqwest-blocking")]
111pub fn reqwest_blocking_builder(
112    base_url: &str,
113    p_team_id: i64,
114    p_username: &str,
115    h_user_agent: &str,
116    h_accept: ::std::option::Option<&str>,
117) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
118    let url = url_string(
119        base_url,
120        p_team_id,
121        p_username,
122    )?;
123    let reqwest_url = ::reqwest::Url::parse(&url)?;
124    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PUT, reqwest_url);
125    let headers = request.headers_mut();
126    headers.append(
127        "User-Agent",
128        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
129    );
130    if let Some(value) = &h_accept {
131        headers.append(
132            "Accept",
133            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
134        );
135    }
136    Ok(request)
137}
138
139#[cfg(feature = "reqwest-blocking")]
140#[inline(always)]
141pub fn reqwest_blocking_request(
142    builder: ::reqwest::blocking::Request,
143) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError>
144{
145    Ok(builder)
146}