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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
use serde::{self, Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Params {
    /// The ID of the discussion from which to fetch posts.
    #[serde(rename = "discussionid")]
    pub r#discussionid: Option<i64>,
    /// Sort by this element: id, created or modified
    #[serde(rename = "sortby")]
    pub r#sortby: Option<String>,
    /// Sort direction: ASC or DESC
    #[serde(rename = "sortdirection")]
    pub r#sortdirection: Option<String>,
    /// Whether inline attachments should be included or not
    #[serde(rename = "includeinlineattachments")]
    pub r#includeinlineattachments: Option<bool>,
}

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

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemAuthorGroupsItem {
    /// 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<ReturnsPostsItemAuthorGroupsItemUrls>,
}

/// groups
pub type r#ReturnsPostsItemAuthorGroups = Vec<ReturnsPostsItemAuthorGroupsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemAuthorUrls {
    /// 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 ReturnsPostsItemAuthor {
    /// 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#ReturnsPostsItemAuthorGroups>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostsItemAuthorUrls>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemCapabilities {
    /// 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 ReturnsPostsItemUrls {
    /// 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 ReturnsPostsItemAttachmentsItemUrls {
    /// The URL used to export the attachment
    #[serde(rename = "export")]
    pub r#export: Option<String>,
}

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

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemAttachmentsItem {
    /// 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<ReturnsPostsItemAttachmentsItemUrls>,
    #[serde(rename = "html")]
    pub r#html: Option<ReturnsPostsItemAttachmentsItemHtml>,
}

/// attachments
pub type r#ReturnsPostsItemAttachments = Vec<ReturnsPostsItemAttachmentsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemMessageinlinefilesItem {
    /// 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#ReturnsPostsItemMessageinlinefiles = Vec<ReturnsPostsItemMessageinlinefilesItem>;

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

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemTagsItem {
    /// 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<ReturnsPostsItemTagsItemUrls>,
}

/// tags
pub type r#ReturnsPostsItemTags = Vec<ReturnsPostsItemTagsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsPostsItemHtml {
    /// 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 ReturnsPostsItem {
    /// 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<ReturnsPostsItemAuthor>,
    /// 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<ReturnsPostsItemCapabilities>,
    #[serde(rename = "urls")]
    pub r#urls: Option<ReturnsPostsItemUrls>,
    /// attachments
    #[serde(rename = "attachments")]
    pub r#attachments: Option<r#ReturnsPostsItemAttachments>,
    /// messageinlinefiles
    #[serde(rename = "messageinlinefiles")]
    pub r#messageinlinefiles: Option<r#ReturnsPostsItemMessageinlinefiles>,
    /// tags
    #[serde(rename = "tags")]
    pub r#tags: Option<r#ReturnsPostsItemTags>,
    #[serde(rename = "html")]
    pub r#html: Option<ReturnsPostsItemHtml>,
}

pub type r#ReturnsPosts = Vec<ReturnsPostsItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsRatinginfoScalesItemItemsItem {
    /// Scale value/option id.
    #[serde(rename = "value")]
    pub r#value: Option<i64>,
    /// Scale name.
    #[serde(rename = "name")]
    pub r#name: Option<String>,
}

/// Scale items. Only returned for not numerical scales.
pub type r#ReturnsRatinginfoScalesItemItems = Vec<ReturnsRatinginfoScalesItemItemsItem>;

/// Scale information
#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsRatinginfoScalesItem {
    /// Scale id.
    #[serde(rename = "id")]
    pub r#id: Option<i64>,
    /// Course id.
    #[serde(rename = "courseid")]
    pub r#courseid: Option<i64>,
    /// Scale name (when a real scale is used).
    #[serde(rename = "name")]
    pub r#name: Option<String>,
    /// Max value for the scale.
    #[serde(rename = "max")]
    pub r#max: Option<i64>,
    /// Whether is a numeric scale.
    #[serde(rename = "isnumeric")]
    pub r#isnumeric: Option<bool>,
    /// Scale items. Only returned for not numerical scales.
    #[serde(rename = "items")]
    pub r#items: Option<r#ReturnsRatinginfoScalesItemItems>,
}

/// Different scales used information
pub type r#ReturnsRatinginfoScales = Vec<ReturnsRatinginfoScalesItem>;

#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsRatinginfoRatingsItem {
    /// Item id.
    #[serde(rename = "itemid")]
    pub r#itemid: Option<i64>,
    /// Scale id.
    #[serde(rename = "scaleid")]
    pub r#scaleid: Option<i64>,
    /// User who rated id.
    #[serde(rename = "userid")]
    pub r#userid: Option<i64>,
    /// Aggregated ratings grade.
    #[serde(rename = "aggregate")]
    pub r#aggregate: Option<f64>,
    /// Aggregated ratings as string.
    #[serde(rename = "aggregatestr")]
    pub r#aggregatestr: Option<String>,
    /// The aggregation label.
    #[serde(rename = "aggregatelabel")]
    pub r#aggregatelabel: Option<String>,
    /// Ratings count (used when aggregating).
    #[serde(rename = "count")]
    pub r#count: Option<i64>,
    /// The rating the user gave.
    #[serde(rename = "rating")]
    pub r#rating: Option<i64>,
    /// Whether the user can rate the item.
    #[serde(rename = "canrate")]
    pub r#canrate: Option<bool>,
    /// Whether the user can view the aggregated grade.
    #[serde(rename = "canviewaggregate")]
    pub r#canviewaggregate: Option<bool>,
}

/// The ratings
pub type r#ReturnsRatinginfoRatings = Vec<ReturnsRatinginfoRatingsItem>;

/// Rating information
#[derive(Serialize, Deserialize, Debug)]
pub struct ReturnsRatinginfo {
    /// Context id.
    #[serde(rename = "contextid")]
    pub r#contextid: Option<i64>,
    /// Context name.
    #[serde(rename = "component")]
    pub r#component: Option<String>,
    /// Rating area name.
    #[serde(rename = "ratingarea")]
    pub r#ratingarea: Option<String>,
    /// Whether the user can view all the individual ratings.
    #[serde(rename = "canviewall")]
    pub r#canviewall: Option<bool>,
    /// Whether the user can view aggregate of ratings of others.
    #[serde(rename = "canviewany")]
    pub r#canviewany: Option<bool>,
    /// Different scales used information
    #[serde(rename = "scales")]
    pub r#scales: Option<r#ReturnsRatinginfoScales>,
    /// The ratings
    #[serde(rename = "ratings")]
    pub r#ratings: Option<r#ReturnsRatinginfoRatings>,
}

/// 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 = "posts")]
    pub r#posts: Option<r#ReturnsPosts>,
    /// The forum id
    #[serde(rename = "forumid")]
    pub r#forumid: Option<i64>,
    /// The forum course id
    #[serde(rename = "courseid")]
    pub r#courseid: Option<i64>,
    /// Rating information
    #[serde(rename = "ratinginfo")]
    pub r#ratinginfo: Option<ReturnsRatinginfo>,
    /// 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_posts", 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_posts", params).await
}