src/telegram/Telegraph.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 50
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 30
mnd 0
bc 0
fnc 6
dl 0
loc 50
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A Telegraph.constructor 0 3 1
A Telegraph.js ➔ dumpPage 0 6 1
A Telegraph.authorize 0 7 1
A Telegraph.send 0 13 1
A Telegraph.js ➔ dumpAccount 0 3 1
A Telegraph.test 0 5 1
1
import remarkParse from 'remark-parse';
2
import unified from 'unified';
3
import { fill } from 'myrmidon';
4
import remarkTelegraph from 'remark-telegraph';
5
import Api from './TelegraphAPI';
6
7
function dumpAccount(account) {
8
    return account.short_name;
9
}
10
11
function dumpPage(page) {
12
    return {
13
        'telegraph_url'   : page.url,
14
        'telegraph_title' : page.title
15
    };
16
}
17
18
export default class Telegraph {
19
    constructor(token) {
20
        this.api = new Api(token);
21
    }
22
23
    async send(title, message, variables) {
24
        const mdTitle = fill(title, variables);
25
        const mdMessage = fill(message, variables);
26
27
        const content = await unified()
28
            .use(remarkParse)
29
            .use(remarkTelegraph)
30
            .process(mdMessage);
31
32
        const page = await this.api.createPage(mdTitle, String(content));
33
34
        return dumpPage(page);
35
    }
36
37
    async authorize() {
38
        const account = await this.api.createAccount('Semantic Release Telegram');
39
40
        this.api.setToken(account.access_token);
41
42
        return account.access_token;
43
    }
44
45
    async test() {
46
        const account = await this.api.getAccountInfo();
47
48
        return dumpAccount(account);
49
    }
50
}
51
52