aboutsummaryrefslogtreecommitdiff
path: root/scripts/load-docs.p6
blob: d3a1f810c19ae25b7e20663377484c7350fb6005 (plain)
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
#!/usr/bin/env perl6
use v6;
use HTTP::UserAgent;
use JSON::Fast;

sub get-api-docs {
    my $url = "https://matrix.org/docs/api/client-server/json/api-docs.json";
    my $ua = HTTP::UserAgent.new;

    my $res = $ua.get($url);
    die "Cannot get response $res" unless $res.is-success;

    my $data = from-json($res.content);

    my %tags;

    for $data<paths> -> $path {
        $path.kv.map: -> $p, $methods {
            for $methods.kv -> $method, $description {
                for $description<tags> -> $tag {
                    unless %tags{$tag}:exists {
                        %tags{$tag} = Array.new;
                    }
                    %tags{$tag}.push("{$method.uc} - $p");
                }
            }
        }
    }

    %tags
}

sub MAIN(:$spec?) {
    my %tags = get-api-docs;
    for %tags.sort -> $pair {
        my $tag = $pair.key;
        my $methods = $pair.value;
        say qq:to/EOF/;
        # $tag
        EOF

        for $methods.Seq -> $m {
            my Str $method = $m;
            if $spec {
                $method = $m.subst(/unstable/, $spec)
            }
            say "- [ ] " ~ $method;
        }
        say "";
    }
}