Test Failed
Push — main ( 402e53...4169bc )
by Ehsan
03:02
created

src/actions/Retweet.ts   A

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 33
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4
mnd 3
bc 3
fnc 1
bpm 3
cpm 4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Retweet.run 0 21 4
1
import Tweet from '../entities/Tweet';
2
import {AbstractAction, runArgs} from './Action';
3
import Helper from '../Helper';
4
5
interface runRetweetArgs extends runArgs {
6
    tweet: Tweet
7
}
8
9
export default class Retweet extends AbstractAction {
10
    async run(args: runRetweetArgs): Promise<void> {
11
        const {tweet, onSuccess} = args;
12
13
        this.debug(`Retweeting tweet with id: '${tweet.rawTweet.id_str}' ...`);
14
        const result = await this.twit.post('statuses/retweet/:id', {
15
            id: tweet.rawTweet.id_str
16
        });
17
18
        if (this.isSuccessResponse(result)) {
19
            this.debug('Retweeted!');
20
21
            if (onSuccess) {
22
                onSuccess(tweet);
23
            }
24
        } else {
25
            this.debug('Cannot retweet.');
26
            if (Helper.objectExists(result.resp.statusMessage)) {
27
                this.debug(result.resp.statusMessage);
28
            }
29
30
            throw new Error('Cannot retweet');
31
        }
32
    }
33
}