Passed
Pull Request — master (#19)
by Muhammad Dyas
01:38
created

src/cards/BaseCard.ts   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 57
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 44
mnd 0
bc 0
fnc 5
dl 0
loc 57
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A BaseCard.buildSections 0 2 1
A BaseCard.createButton 0 11 1
A BaseCard.createMessage 0 3 1
A BaseCard.create 0 2 1
A BaseCard.createCardWithId 0 5 1
1
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1';
2
3
interface Card {
4
  buildHeader?(): void;
5
6
  buildSections(): void;
7
8
  buildButtons?(): void;
9
10
  buildFooter?(): void;
11
12
  create(): chatV1.Schema$GoogleAppsCardV1Card;
13
14
  createCardWithId(): chatV1.Schema$CardWithId;
15
16
  createMessage(): chatV1.Schema$Message;
17
}
18
19
export default abstract class BaseCard implements Card {
20
  private id: string = 'cardId';
21
  private _content: chatV1.Schema$GoogleAppsCardV1Section[] = [];
22
23
  protected card: chatV1.Schema$GoogleAppsCardV1Card = {
24
    sections: this._content,
25
  };
26
27
  protected createButton(
28
    text: string, action: string, interaction: string | undefined = undefined,
29
    parameters = []): chatV1.Schema$GoogleAppsCardV1Button {
30
    return {
31
      text,
32
      'onClick': {
33
        'action': {
34
          'function': action,
35
          interaction,
36
          parameters,
37
        },
38
      },
39
    };
40
  }
41
42
  abstract buildSections(): void;
43
44
  abstract create(): chatV1.Schema$GoogleAppsCardV1Card;
45
46
  createCardWithId(): chatV1.Schema$CardWithId {
47
    return {
48
      'cardId': this.id,
49
      'card': this.create(),
50
    };
51
  }
52
53
  createMessage(): chatV1.Schema$Message {
54
    return {cardsV2: [this.createCardWithId()]};
55
  }
56
}
57