jinxapi_github/v1_1_4/request/
migrations_set_lfs_preference.rs

1//! Update Git LFS preference
2//! 
3//! You can import repositories from Subversion, Mercurial, and TFS that include files larger than 100MB. This ability is powered by [Git LFS](https://git-lfs.github.com). You can learn more about our LFS feature and working with large files [on our help site](https://docs.github.com/articles/versioning-large-files/).
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/migrations#update-git-lfs-preference)
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_owner: &str,
36    p_repo: &str,
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() + 37);
44    url.push_str(trimmed);
45    url.push_str("/repos/");
46    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
47    url.push('/');
48    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
49    url.push_str("/import/lfs");
50    Ok(url)
51}
52
53#[cfg(feature = "hyper")]
54pub fn http_builder(
55    base_url: &str,
56    p_owner: &str,
57    p_repo: &str,
58    h_user_agent: &str,
59    h_accept: ::std::option::Option<&str>,
60) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
61    let url = url_string(
62        base_url,
63        p_owner,
64        p_repo,
65    )?;
66    let mut builder = ::http::request::Request::patch(url);
67    builder = builder.header(
68        "User-Agent",
69        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
70    );
71    if let Some(value) = &h_accept {
72        builder = builder.header(
73            "Accept",
74            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
75        );
76    }
77    Ok(builder)
78}
79
80#[cfg(feature = "hyper")]
81pub fn hyper_request(
82    mut builder: ::http::request::Builder,
83    content: Content<::hyper::Body>,
84) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
85{
86    if let Some(content_type) = content.content_type() {
87        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
88    }
89    Ok(builder.body(content.into_body())?)
90}
91
92#[cfg(feature = "hyper")]
93impl From<::hyper::Body> for Content<::hyper::Body> {
94    fn from(body: ::hyper::Body) -> Self {
95        Self::new(body)
96    }
97}
98
99#[cfg(feature = "reqwest")]
100pub fn reqwest_builder(
101    base_url: &str,
102    p_owner: &str,
103    p_repo: &str,
104    h_user_agent: &str,
105    h_accept: ::std::option::Option<&str>,
106) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
107    let url = url_string(
108        base_url,
109        p_owner,
110        p_repo,
111    )?;
112    let reqwest_url = ::reqwest::Url::parse(&url)?;
113    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
114    let headers = request.headers_mut();
115    headers.append(
116        "User-Agent",
117        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
118    );
119    if let Some(value) = &h_accept {
120        headers.append(
121            "Accept",
122            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
123        );
124    }
125    Ok(request)
126}
127
128#[cfg(feature = "reqwest")]
129pub fn reqwest_request(
130    mut builder: ::reqwest::Request,
131    content: Content<::reqwest::Body>,
132) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
133    if let Some(content_type) = content.content_type() {
134        builder.headers_mut().append(
135            ::reqwest::header::HeaderName::from_static("content-type"),
136            ::reqwest::header::HeaderValue::try_from(content_type)?,
137        );
138    }
139    *builder.body_mut() = Some(content.into_body());
140    Ok(builder)
141}
142
143#[cfg(feature = "reqwest")]
144impl From<::reqwest::Body> for Content<::reqwest::Body> {
145    fn from(body: ::reqwest::Body) -> Self {
146        Self::new(body)
147    }
148}
149
150#[cfg(feature = "reqwest-blocking")]
151pub fn reqwest_blocking_builder(
152    base_url: &str,
153    p_owner: &str,
154    p_repo: &str,
155    h_user_agent: &str,
156    h_accept: ::std::option::Option<&str>,
157) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
158    let url = url_string(
159        base_url,
160        p_owner,
161        p_repo,
162    )?;
163    let reqwest_url = ::reqwest::Url::parse(&url)?;
164    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
165    let headers = request.headers_mut();
166    headers.append(
167        "User-Agent",
168        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
169    );
170    if let Some(value) = &h_accept {
171        headers.append(
172            "Accept",
173            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
174        );
175    }
176    Ok(request)
177}
178
179#[cfg(feature = "reqwest-blocking")]
180pub fn reqwest_blocking_request(
181    mut builder: ::reqwest::blocking::Request,
182    content: Content<::reqwest::blocking::Body>,
183) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
184    if let Some(content_type) = content.content_type() {
185        builder.headers_mut().append(
186            ::reqwest::header::HeaderName::from_static("content-type"),
187            ::reqwest::header::HeaderValue::try_from(content_type)?,
188        );
189    }
190    *builder.body_mut() = Some(content.into_body());
191    Ok(builder)
192}
193
194#[cfg(feature = "reqwest-blocking")]
195impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
196    fn from(body: ::reqwest::blocking::Body) -> Self {
197        Self::new(body)
198    }
199}
200
201/// Types for body parameter in [`super::migrations_set_lfs_preference`]
202pub mod body {
203    #[allow(non_snake_case)]
204    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
205    pub struct Json<'a> {
206        /// Can be one of `opt_in` (large files will be stored using Git LFS) or `opt_out` (large files will be removed during the import).
207        pub use_lfs: ::std::borrow::Cow<'a, str>,
208
209        #[serde(flatten)]
210        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
211    }
212
213    #[cfg(feature = "hyper")]
214    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
215        type Error = crate::v1_1_4::ApiError;
216
217        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
218            Ok(
219                Self::new(::serde_json::to_vec(value)?.into())
220                .with_content_type(&b"application/json"[..])
221            )
222        }
223    }
224
225    #[cfg(feature = "reqwest")]
226    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
227        type Error = crate::v1_1_4::ApiError;
228
229        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
230            Ok(
231                Self::new(::serde_json::to_vec(value)?.into())
232                .with_content_type(&b"application/json"[..])
233            )
234        }
235    }
236
237    #[cfg(feature = "reqwest-blocking")]
238    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
239        type Error = crate::v1_1_4::ApiError;
240
241        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
242            Ok(
243                Self::new(::serde_json::to_vec(value)?.into())
244                .with_content_type(&b"application/json"[..])
245            )
246        }
247    }
248}