1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use serde::Deserialize;
#[doc(no_inline)]
#[cfg(feature = "twitch_oauth2")]
pub use twitch_oauth2::Scope;
#[cfg(feature = "twitch_oauth2")]
use twitch_oauth2::TwitchToken;
#[cfg(feature = "client")]
pub mod client;
mod endpoints;
pub mod request;
pub mod response;
#[cfg(feature = "client")]
#[doc(inline)]
pub use client::{client_ext::make_stream, *};
pub use endpoints::*;
#[cfg(feature = "client")]
#[doc(inline)]
pub use request::errors::ClientRequestError;
#[doc(inline)]
pub use request::errors::{
CreateRequestError, HelixRequestDeleteError, HelixRequestGetError, HelixRequestPatchError,
HelixRequestPostError, HelixRequestPutError, InvalidUri, SerializeError,
};
#[doc(inline)]
pub use request::{Request, RequestDelete, RequestGet, RequestPatch, RequestPost, RequestPut};
#[doc(inline)]
pub use response::Response;
pub(crate) mod ser;
pub(crate) use crate::deserialize_default_from_null;
use crate::{parse_json, parse_json_value};
#[derive(PartialEq, Deserialize, Debug)]
struct InnerResponse<D> {
data: D,
#[serde(default)]
pagination: Pagination,
#[serde(default)]
total: Option<i64>,
#[serde(default, flatten)]
other: Option<serde_json::Map<String, serde_json::Value>>,
}
#[derive(Deserialize, Debug)]
#[cfg(feature = "unsupported")]
#[cfg_attr(nightly, doc(cfg(feature = "unsupported")))]
struct CustomInnerResponse<'a> {
#[serde(borrow)]
data: &'a serde_json::value::RawValue,
#[serde(default)]
pagination: Pagination,
#[serde(default)]
total: Option<i64>,
#[serde(flatten, default)]
other: serde_json::Map<String, serde_json::Value>,
}
#[derive(Deserialize, Clone, Debug)]
struct HelixRequestError {
error: String,
status: u16,
message: String,
}
fn deserialize_none_from_empty_string<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
where
D: serde::de::Deserializer<'de>,
T: serde::de::DeserializeOwned, {
let val = serde_json::Value::deserialize(deserializer)?;
match val {
serde_json::Value::String(string) if string.is_empty() => Ok(None),
other => Ok(parse_json_value(other, true).map_err(serde::de::Error::custom)?),
}
}
pub trait Paginated: Request {
fn set_pagination(&mut self, cursor: Option<Cursor>);
}
#[derive(PartialEq, Deserialize, Debug, Clone, Default)]
struct Pagination {
#[serde(default)]
cursor: Option<Cursor>,
}
#[aliri_braid::braid(serde)]
pub struct Cursor;
#[derive(thiserror::Error, Debug, displaydoc::Display)]
pub enum BodyError {
JsonError(#[from] serde_json::Error),
QuerySerializeError(#[from] ser::Error),
InvalidUri(#[from] InvalidUri),
}
pub trait HelixRequestBody {
fn try_to_body(&self) -> Result<hyper::body::Bytes, BodyError>;
}
#[derive(Default, Clone, Copy)]
pub struct EmptyBody;
impl HelixRequestBody for EmptyBody {
fn try_to_body(&self) -> Result<hyper::body::Bytes, BodyError> { Ok(<_>::default()) }
}
impl<T> HelixRequestBody for T
where T: serde::Serialize + private::SealedSerialize
{
fn try_to_body(&self) -> Result<hyper::body::Bytes, BodyError> {
serde_json::to_vec(&self)
.map_err(Into::into)
.map(Into::into)
}
}
pub(crate) mod private {
pub trait SealedSerialize {}
}