Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 50 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |