moodle_api 0.1.0

Moodle Webservice Client in Rust.
Documentation
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
use serde::{self, Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Params {
    /// Post to fetch.
    #[serde(rename = "postid")]
    pub r#postid: Option<i64>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAuthorGroupsItemUrls {
    /// image
    #[serde(rename = "image")]
    pub r#image: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAuthorGroupsItem {
    /// id
    #[serde(rename = "id")]
    pub r#id: Option<i64>,
    /// name
    #[serde(rename = "name")]
    pub r#name: Option<String>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostAuthorGroupsItemUrls>,
}

/// groups
pub type r#ReturnsPostAuthorGroups = Vec<ReturnsPostAuthorGroupsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAuthorUrls {
    /// The URL for the use profile page
    #[serde(rename = "profile")]
    pub r#profile: Option<String>,
    /// The URL for the use profile image
    #[serde(rename = "profileimage")]
    pub r#profileimage: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAuthor {
    /// id
    #[serde(rename = "id")]
    pub r#id: Option<i64>,
    /// fullname
    #[serde(rename = "fullname")]
    pub r#fullname: Option<String>,
    /// isdeleted
    #[serde(rename = "isdeleted")]
    pub r#isdeleted: Option<bool>,
    /// groups
    #[serde(rename = "groups")]
    pub r#groups: Option<r#ReturnsPostAuthorGroups>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostAuthorUrls>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostCapabilities {
    /// Whether the user can view the post
    #[serde(rename = "view")]
    pub r#view: Option<bool>,
    /// Whether the user can edit the post
    #[serde(rename = "edit")]
    pub r#edit: Option<bool>,
    /// Whether the user can delete the post
    #[serde(rename = "delete")]
    pub r#delete: Option<bool>,
    /// Whether the user can split the post
    #[serde(rename = "split")]
    pub r#split: Option<bool>,
    /// Whether the user can reply to the post
    #[serde(rename = "reply")]
    pub r#reply: Option<bool>,
    /// Whether the user can self enrol into the course
    #[serde(rename = "selfenrol")]
    pub r#selfenrol: Option<bool>,
    /// Whether the user can export the post
    #[serde(rename = "export")]
    pub r#export: Option<bool>,
    /// Whether the user can control the read status of the post
    #[serde(rename = "controlreadstatus")]
    pub r#controlreadstatus: Option<bool>,
    /// Whether the user can post a private reply
    #[serde(rename = "canreplyprivately")]
    pub r#canreplyprivately: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostUrls {
    /// The URL used to view the post
    #[serde(rename = "view")]
    pub r#view: Option<String>,
    /// The URL used to view the post in isolation
    #[serde(rename = "viewisolated")]
    pub r#viewisolated: Option<String>,
    /// The URL used to view the parent of the post
    #[serde(rename = "viewparent")]
    pub r#viewparent: Option<String>,
    /// The URL used to edit the post
    #[serde(rename = "edit")]
    pub r#edit: Option<String>,
    /// The URL used to delete the post
    #[serde(rename = "delete")]
    pub r#delete: Option<String>,
    /// The URL used to split the discussion with the selected post being the first post in the new discussion
    #[serde(rename = "split")]
    pub r#split: Option<String>,
    /// The URL used to reply to the post
    #[serde(rename = "reply")]
    pub r#reply: Option<String>,
    /// The URL used to export the post
    #[serde(rename = "export")]
    pub r#export: Option<String>,
    /// The URL used to mark the post as read
    #[serde(rename = "markasread")]
    pub r#markasread: Option<String>,
    /// The URL used to mark the post as unread
    #[serde(rename = "markasunread")]
    pub r#markasunread: Option<String>,
    /// discuss
    #[serde(rename = "discuss")]
    pub r#discuss: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAttachmentsItemUrls {
    /// The URL used to export the attachment
    #[serde(rename = "export")]
    pub r#export: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAttachmentsItemHtml {
    /// The HTML source for the Plagiarism Response
    #[serde(rename = "plagiarism")]
    pub r#plagiarism: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostAttachmentsItem {
    /// contextid
    #[serde(rename = "contextid")]
    pub r#contextid: Option<i64>,
    /// component
    #[serde(rename = "component")]
    pub r#component: Option<String>,
    /// filearea
    #[serde(rename = "filearea")]
    pub r#filearea: Option<String>,
    /// itemid
    #[serde(rename = "itemid")]
    pub r#itemid: Option<i64>,
    /// filepath
    #[serde(rename = "filepath")]
    pub r#filepath: Option<String>,
    /// filename
    #[serde(rename = "filename")]
    pub r#filename: Option<String>,
    /// isdir
    #[serde(rename = "isdir")]
    pub r#isdir: Option<bool>,
    /// isimage
    #[serde(rename = "isimage")]
    pub r#isimage: Option<bool>,
    /// timemodified
    #[serde(rename = "timemodified")]
    pub r#timemodified: Option<i64>,
    /// timecreated
    #[serde(rename = "timecreated")]
    pub r#timecreated: Option<i64>,
    /// filesize
    #[serde(rename = "filesize")]
    pub r#filesize: Option<i64>,
    /// author
    #[serde(rename = "author")]
    pub r#author: Option<String>,
    /// license
    #[serde(rename = "license")]
    pub r#license: Option<String>,
    /// filenameshort
    #[serde(rename = "filenameshort")]
    pub r#filenameshort: Option<String>,
    /// filesizeformatted
    #[serde(rename = "filesizeformatted")]
    pub r#filesizeformatted: Option<String>,
    /// icon
    #[serde(rename = "icon")]
    pub r#icon: Option<String>,
    /// timecreatedformatted
    #[serde(rename = "timecreatedformatted")]
    pub r#timecreatedformatted: Option<String>,
    /// timemodifiedformatted
    #[serde(rename = "timemodifiedformatted")]
    pub r#timemodifiedformatted: Option<String>,
    /// url
    #[serde(rename = "url")]
    pub r#url: Option<String>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostAttachmentsItemUrls>,
    #[serde(rename = "html")]
    pub r#html: Option<ReturnsPostAttachmentsItemHtml>,
}

/// attachments
pub type r#ReturnsPostAttachments = Vec<ReturnsPostAttachmentsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostMessageinlinefilesItem {
    /// contextid
    #[serde(rename = "contextid")]
    pub r#contextid: Option<i64>,
    /// component
    #[serde(rename = "component")]
    pub r#component: Option<String>,
    /// filearea
    #[serde(rename = "filearea")]
    pub r#filearea: Option<String>,
    /// itemid
    #[serde(rename = "itemid")]
    pub r#itemid: Option<i64>,
    /// filepath
    #[serde(rename = "filepath")]
    pub r#filepath: Option<String>,
    /// filename
    #[serde(rename = "filename")]
    pub r#filename: Option<String>,
    /// isdir
    #[serde(rename = "isdir")]
    pub r#isdir: Option<bool>,
    /// isimage
    #[serde(rename = "isimage")]
    pub r#isimage: Option<bool>,
    /// timemodified
    #[serde(rename = "timemodified")]
    pub r#timemodified: Option<i64>,
    /// timecreated
    #[serde(rename = "timecreated")]
    pub r#timecreated: Option<i64>,
    /// filesize
    #[serde(rename = "filesize")]
    pub r#filesize: Option<i64>,
    /// author
    #[serde(rename = "author")]
    pub r#author: Option<String>,
    /// license
    #[serde(rename = "license")]
    pub r#license: Option<String>,
    /// filenameshort
    #[serde(rename = "filenameshort")]
    pub r#filenameshort: Option<String>,
    /// filesizeformatted
    #[serde(rename = "filesizeformatted")]
    pub r#filesizeformatted: Option<String>,
    /// icon
    #[serde(rename = "icon")]
    pub r#icon: Option<String>,
    /// timecreatedformatted
    #[serde(rename = "timecreatedformatted")]
    pub r#timecreatedformatted: Option<String>,
    /// timemodifiedformatted
    #[serde(rename = "timemodifiedformatted")]
    pub r#timemodifiedformatted: Option<String>,
    /// url
    #[serde(rename = "url")]
    pub r#url: Option<String>,
}

/// messageinlinefiles
pub type r#ReturnsPostMessageinlinefiles = Vec<ReturnsPostMessageinlinefilesItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostTagsItemUrls {
    /// The URL to view the tag
    #[serde(rename = "view")]
    pub r#view: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostTagsItem {
    /// The ID of the Tag
    #[serde(rename = "id")]
    pub r#id: Option<i64>,
    /// The tagid
    #[serde(rename = "tagid")]
    pub r#tagid: Option<i64>,
    /// Whether this is a standard tag
    #[serde(rename = "isstandard")]
    pub r#isstandard: Option<bool>,
    /// The display name of the tag
    #[serde(rename = "displayname")]
    pub r#displayname: Option<String>,
    /// Wehther this tag is flagged
    #[serde(rename = "flag")]
    pub r#flag: Option<bool>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostTagsItemUrls>,
}

/// tags
pub type r#ReturnsPostTags = Vec<ReturnsPostTagsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostHtml {
    /// The HTML source to rate the post
    #[serde(rename = "rating")]
    pub r#rating: Option<String>,
    /// The HTML source to view the list of tags
    #[serde(rename = "taglist")]
    pub r#taglist: Option<String>,
    /// The HTML source to view the author details
    #[serde(rename = "authorsubheading")]
    pub r#authorsubheading: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPost {
    /// id
    #[serde(rename = "id")]
    pub r#id: Option<i64>,
    /// subject
    #[serde(rename = "subject")]
    pub r#subject: Option<String>,
    /// replysubject
    #[serde(rename = "replysubject")]
    pub r#replysubject: Option<String>,
    /// message
    #[serde(rename = "message")]
    pub r#message: Option<String>,
    /// message format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN
    #[serde(rename = "messageformat")]
    pub r#messageformat: Option<i64>,
    #[serde(rename = "author")]
    pub r#author: Option<ReturnsPostAuthor>,
    /// discussionid
    #[serde(rename = "discussionid")]
    pub r#discussionid: Option<i64>,
    /// hasparent
    #[serde(rename = "hasparent")]
    pub r#hasparent: Option<bool>,
    /// parentid
    #[serde(rename = "parentid")]
    pub r#parentid: Option<i64>,
    /// timecreated
    #[serde(rename = "timecreated")]
    pub r#timecreated: Option<i64>,
    /// timemodified
    #[serde(rename = "timemodified")]
    pub r#timemodified: Option<i64>,
    /// unread
    #[serde(rename = "unread")]
    pub r#unread: Option<bool>,
    /// isdeleted
    #[serde(rename = "isdeleted")]
    pub r#isdeleted: Option<bool>,
    /// isprivatereply
    #[serde(rename = "isprivatereply")]
    pub r#isprivatereply: Option<bool>,
    /// haswordcount
    #[serde(rename = "haswordcount")]
    pub r#haswordcount: Option<bool>,
    /// wordcount
    #[serde(rename = "wordcount")]
    pub r#wordcount: Option<i64>,
    /// charcount
    #[serde(rename = "charcount")]
    pub r#charcount: Option<i64>,
    #[serde(rename = "capabilities")]
    pub r#capabilities: Option<ReturnsPostCapabilities>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostUrls>,
    /// attachments
    #[serde(rename = "attachments")]
    pub r#attachments: Option<r#ReturnsPostAttachments>,
    /// messageinlinefiles
    #[serde(rename = "messageinlinefiles")]
    pub r#messageinlinefiles: Option<r#ReturnsPostMessageinlinefiles>,
    /// tags
    #[serde(rename = "tags")]
    pub r#tags: Option<r#ReturnsPostTags>,
    #[serde(rename = "html")]
    pub r#html: Option<ReturnsPostHtml>,
}

/// warning
#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsWarningsItem {
    /// item
    #[serde(rename = "item")]
    pub r#item: Option<String>,
    /// item id
    #[serde(rename = "itemid")]
    pub r#itemid: Option<i64>,
    /// the warning code can be used by the client app to implement specific behaviour
    #[serde(rename = "warningcode")]
    pub r#warningcode: Option<String>,
    /// untranslated english message to explain the warning
    #[serde(rename = "message")]
    pub r#message: Option<String>,
}

/// list of warnings
pub type r#ReturnsWarnings = Vec<ReturnsWarningsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct Returns {
    #[serde(rename = "post")]
    pub r#post: Option<ReturnsPost>,
    /// list of warnings
    #[serde(rename = "warnings")]
    pub r#warnings: Option<r#ReturnsWarnings>,
}

pub async fn call<'a>(
    client: &'a mut moodle_client::MoodleClient,
    params: &'a mut Params,
) -> anyhow::Result<Returns> {
    let json = client.post("mod_forum_get_discussion_post", params).await?;

    serde_json::from_value(json).map_err(|e| e.into())
}

pub async fn call_raw<'a>(
    client: &'a mut moodle_client::MoodleClient,
    params: &'a mut Params,
) -> anyhow::Result<serde_json::Value> {
    client.post("mod_forum_get_discussion_post", params).await
}