File tree 4 files changed +55
-2
lines changed
4 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " dimescheduler" ,
3
3
"description" : " The Dime.Scheduler SDK" ,
4
- "version" : " 0.1.1 " ,
4
+ "version" : " 0.2.0 " ,
5
5
"main" : " ./dist/index.ts" ,
6
6
"types" : " ./dist/index.d.ts" ,
7
7
"module" : " ./dist/esm/index.js" ,
Original file line number Diff line number Diff line change 1
1
import ImportEndPoint from './endpoints/import' ;
2
+ import ImportResponse from './endpoints/importresponse' ;
3
+ import MessageEndpoint from './endpoints/message' ;
2
4
import Environment from './environment' ;
3
5
import IImportModel from './models/base/iimportmodel' ;
6
+ import { Severity } from './models/constants/severity' ;
4
7
5
8
class DimeSchedulerClient {
6
9
private importEndPoint : ImportEndPoint ;
10
+ private messageEndPoint : MessageEndpoint ;
7
11
8
12
constructor ( apiKey : string , env : Environment = Environment . Production ) {
9
13
this . importEndPoint = new ImportEndPoint ( env , apiKey ) ;
14
+ this . messageEndPoint = new MessageEndpoint ( env , apiKey ) ;
10
15
}
11
16
12
- import ( importable : IImportModel | Array < IImportModel > , append : boolean = true ) {
17
+ import ( importable : IImportModel | Array < IImportModel > , append : boolean = true ) : Promise < ImportResponse > {
13
18
return this . importEndPoint . processAsync ( importable , append ) ;
14
19
}
20
+
21
+ sendMessage ( text : string , severity : Severity , user ?: string ) : Promise < void > {
22
+ return this . messageEndPoint . processAsync ( text , severity , user ) ;
23
+ }
15
24
}
16
25
17
26
export default DimeSchedulerClient ;
Original file line number Diff line number Diff line change
1
+ import axios from 'axios' ;
2
+ import Endpoint from './endpoint' ;
3
+ import Environment from '../environment' ;
4
+ import { Severity } from '../models/constants/severity' ;
5
+
6
+ class MessageEndpoint extends Endpoint {
7
+ constructor ( env : Environment , apiKey : string ) {
8
+ super ( env , apiKey ) ;
9
+ }
10
+
11
+ async processAsync ( text : string , severity : Severity , user ?: string ) : Promise < void > {
12
+ const params = {
13
+ Text : text ,
14
+ User : user ,
15
+ Severity : severity
16
+ } ;
17
+
18
+ const body = JSON . stringify ( params ) ;
19
+
20
+ const headers = {
21
+ 'X-API-KEY' : this . apiKey ,
22
+ 'Content-Type' : 'application/json' ,
23
+ 'Accept' : 'application/json'
24
+ } ;
25
+
26
+ const url = this . uri + '/message' ;
27
+ await axios . post ( url , body , { headers : headers } ) ;
28
+ }
29
+ }
30
+
31
+ export default MessageEndpoint ;
Original file line number Diff line number Diff line change
1
+ import DimeSchedulerClient , { Environment } from '../dist' ;
2
+
3
+ import { apiKey } from "./testvars" ;
4
+ import { Severity } from '../dist/lib/models/constants/severity' ;
5
+
6
+ describe ( 'Message' , function ( ) {
7
+ describe ( '#sendMessage()' , function ( ) {
8
+ it . only ( 'Should successfully send message' , async ( ) => {
9
+ const client = new DimeSchedulerClient ( apiKey , Environment . Test ) ;
10
+ await client . sendMessage ( "Hello world!" , Severity . Warning ) ;
11
+ } ) ;
12
+ } ) ;
13
+ } ) ;
You can’t perform that action at this time.
0 commit comments