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
use crate::types;
use super::*;
use serde::{Deserialize, Serialize};
impl Topic for StreamChangedTopic {
type Helix = crate::helix::streams::GetStreamsRequest;
const PATH: &'static str = "streams";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
pub struct StreamChangedTopic {
#[builder(setter(into))]
pub user_id: types::UserId,
}
#[test]
fn test_topic() {
use crate::helix::webhooks::hub::*;
use crate::helix::*;
let req = WebhookHubRequest::<StreamChangedTopic>::builder().build();
let body = WebhookHubBody::builder()
.callback("https://example.com/this-is-a-callback")
.lease_seconds(864000)
.mode(WebhookSubscriptionMode::Subscribe)
.secret("12233213890390".to_string())
.topic(
StreamChangedTopic::builder()
.user_id(5678.to_string())
.build(),
)
.build();
req.create_request(body, "token", "clientid").unwrap();
let data = br#"
{
"data": []
}
"#
.to_vec();
let http_response = http::Response::builder().body(data).unwrap();
dbg!(StreamChangedTopic::parse_payload(http_response).unwrap());
let data = br#"
{
"data": [
{
"id": "0123456789",
"user_id": "5678",
"user_name": "wjdtkdqhs",
"user_login": "wjdtkdqhs",
"game_id": "21779",
"type": "live",
"title": "Best Stream Ever",
"viewer_count": 417,
"started_at": "2017-12-01T10:09:45Z",
"language": "en",
"thumbnail_url": "https://link/to/thumbnail.jpg",
"tag_ids": []
}
]
}
"#
.to_vec();
let http_response = http::Response::builder().body(data).unwrap();
dbg!(StreamChangedTopic::parse_payload(http_response).unwrap());
}