14
14
//! .build();
15
15
//! ```
16
16
//!
17
- //! ## Response: [BroadcasterSubscription ]
17
+ //! ## Response: [BroadcasterSubscriptions ]
18
18
//!
19
19
//! Send the request to receive the response with [`HelixClient::req_get()`](helix::HelixClient::req_get).
20
20
//!
29
29
//! let request = get_broadcaster_subscriptions::GetBroadcasterSubscriptionsRequest::builder()
30
30
//! .broadcaster_id("1234")
31
31
//! .build();
32
- //! let response: Vec< get_broadcaster_subscriptions::BroadcasterSubscription> = client.req_get(request, &token).await?.data;
32
+ //! let response: get_broadcaster_subscriptions::BroadcasterSubscriptions = client.req_get(request, &token).await?.data;
33
33
//! # Ok(())
34
34
//! # }
35
35
//! ```
@@ -65,13 +65,42 @@ pub struct GetBroadcasterSubscriptionsRequest {
65
65
#[ derive( PartialEq , Deserialize , Serialize , Debug , Clone ) ]
66
66
#[ cfg_attr( feature = "deny_unknown_fields" , serde( deny_unknown_fields) ) ]
67
67
#[ non_exhaustive]
68
+ pub struct BroadcasterSubscriptions {
69
+ /// List of users subscribed to the broadcaster and the details of the subscription.
70
+ pub subscriptions : Vec < BroadcasterSubscription > ,
71
+ /// The number of Twitch users subscribed to the broadcaster.
72
+ pub total : i64 ,
73
+ }
74
+
75
+ /// A subscription in a channel
76
+ #[ derive( PartialEq , Deserialize , Serialize , Debug , Clone ) ]
77
+ #[ cfg_attr( feature = "deny_unknown_fields" , serde( deny_unknown_fields) ) ]
78
+ #[ non_exhaustive]
68
79
pub struct BroadcasterSubscription {
69
80
/// User ID of the broadcaster.
70
81
pub broadcaster_id : types:: UserId ,
71
82
/// Login of the broadcaster.
72
83
pub broadcaster_login : types:: UserName ,
73
84
/// Display name of the broadcaster.
74
85
pub broadcaster_name : types:: DisplayName ,
86
+ /// User ID of the broadcaster.
87
+ #[ serde(
88
+ default ,
89
+ deserialize_with = "helix::deserialize_none_from_empty_string"
90
+ ) ]
91
+ pub gifter_id : Option < types:: UserId > ,
92
+ /// Login of the gifter.
93
+ #[ serde(
94
+ default ,
95
+ deserialize_with = "helix::deserialize_none_from_empty_string"
96
+ ) ]
97
+ pub gifter_login : Option < types:: UserName > ,
98
+ /// Display name of the gifter.
99
+ #[ serde(
100
+ default ,
101
+ deserialize_with = "helix::deserialize_none_from_empty_string"
102
+ ) ]
103
+ pub gifter_name : Option < types:: DisplayName > ,
75
104
/// Determines if the subscription is a gift subscription.
76
105
pub is_gift : bool ,
77
106
/// Type of subscription (Tier 1, Tier 2, Tier 3). 1000 = Tier 1, 2000 = Tier 2, 3000 = Tier 3 subscriptions.
@@ -87,15 +116,49 @@ pub struct BroadcasterSubscription {
87
116
}
88
117
89
118
impl Request for GetBroadcasterSubscriptionsRequest {
90
- type Response = Vec < BroadcasterSubscription > ;
119
+ type Response = BroadcasterSubscriptions ;
91
120
92
121
const PATH : & ' static str = "subscriptions" ;
93
122
#[ cfg( feature = "twitch_oauth2" ) ]
94
123
const SCOPE : & ' static [ twitch_oauth2:: Scope ] =
95
124
& [ twitch_oauth2:: Scope :: ChannelReadSubscriptions ] ;
96
125
}
97
126
98
- impl RequestGet for GetBroadcasterSubscriptionsRequest { }
127
+ impl RequestGet for GetBroadcasterSubscriptionsRequest {
128
+ fn parse_inner_response (
129
+ request : Option < Self > ,
130
+ uri : & http:: Uri ,
131
+ response : & str ,
132
+ status : http:: StatusCode ,
133
+ ) -> Result < helix:: Response < Self , Self :: Response > , helix:: HelixRequestGetError >
134
+ where
135
+ Self : Sized ,
136
+ {
137
+ #[ derive( PartialEq , Deserialize , Debug ) ]
138
+ struct InnerResponse {
139
+ data : Vec < BroadcasterSubscription > ,
140
+ #[ serde( default ) ]
141
+ pagination : helix:: Pagination ,
142
+ total : i64 ,
143
+ }
144
+ let response: InnerResponse = helix:: parse_json ( response, true ) . map_err ( |e| {
145
+ helix:: HelixRequestGetError :: DeserializeError (
146
+ response. to_string ( ) ,
147
+ e,
148
+ uri. clone ( ) ,
149
+ status,
150
+ )
151
+ } ) ?;
152
+ Ok ( helix:: Response {
153
+ data : BroadcasterSubscriptions {
154
+ subscriptions : response. data ,
155
+ total : response. total ,
156
+ } ,
157
+ pagination : response. pagination . cursor ,
158
+ request,
159
+ } )
160
+ }
161
+ }
99
162
100
163
impl helix:: Paginated for GetBroadcasterSubscriptionsRequest {
101
164
fn set_pagination ( & mut self , cursor : Option < helix:: Cursor > ) { self . after = cursor }
@@ -109,26 +172,30 @@ fn test_request() {
109
172
. broadcaster_id ( "123" . to_string ( ) )
110
173
. build ( ) ;
111
174
112
- // From twitch docs. Malformed example on https://dev.twitch.tv/docs/api/reference#get-broadcaster-subscriptions
175
+ // From twitch docs. Example has ...
113
176
let data = br#"
114
- {
115
- "data": [
116
- {
117
- "broadcaster_id": "123",
118
- "broadcaster_login": "test_user",
119
- "broadcaster_name": "test_user",
120
- "is_gift": true,
121
- "tier": "1000",
122
- "plan_name": "The Ninjas",
123
- "user_id": "123",
124
- "user_login": "snoirf",
125
- "user_name": "snoirf"
126
- }
127
- ],
128
- "pagination": {
129
- "cursor": "xxxx"
130
- }
131
- }
177
+ {
178
+ "data": [
179
+ {
180
+ "broadcaster_id": "141981764",
181
+ "broadcaster_login": "twitchdev",
182
+ "broadcaster_name": "TwitchDev",
183
+ "gifter_id": "12826",
184
+ "gifter_login": "twitch",
185
+ "gifter_name": "Twitch",
186
+ "is_gift": true,
187
+ "tier": "1000",
188
+ "plan_name": "Channel Subscription (twitchdev)",
189
+ "user_id": "527115020",
190
+ "user_name": "twitchgaming",
191
+ "user_login": "twitchgaming"
192
+ }
193
+ ],
194
+ "pagination": {
195
+ "cursor": "xxxx"
196
+ },
197
+ "total": 13
198
+ }
132
199
"#
133
200
. to_vec ( ) ;
134
201
0 commit comments