Test Failed
Push — master ( 1271ab...04a38e )
by Dmytro
03:35 queued 11s
created

TelegraphAPI.constructor   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
/* eslint-disable unicorn/filename-case */
2
import BaseAPI from 'base-api-client';
3
4
export default class TelegraphAPI extends BaseAPI {
5
    constructor(token) {
6
        super('https://api.telegra.ph');
7
        this.token = token;
8
    }
9
10
    onResponse(res) {
11
        return res.data.result;
12
    }
13
14
    setToken(token) {
15
        this.token = token;
16
    }
17
18
    _axios(opts) {
19
        // eslint-disable-next-line no-param-reassign
20
        if (opts.method === 'GET') delete opts.data;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
22
        return super._axios(opts);
23
    }
24
25
    createAccount(name) {
26
        return this.get('createAccount', {
27
            'short_name' : name
28
        });
29
    }
30
31
    getAccountInfo() {
32
        return this.get('getAccountInfo', {
33
            'access_token' : this.token
34
        });
35
    }
36
37
    createPage(title, content) {
38
        return this.post('createPage', {
39
            'access_token' : this.token,
40
            title,
41
            content
42
        });
43
    }
44
}
45