-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import ImportEndPoint from './endpoints/import'; | ||
import ImportResponse from './endpoints/importresponse'; | ||
import MessageEndpoint from './endpoints/message'; | ||
import Environment from './environment'; | ||
import IImportModel from './models/base/iimportmodel'; | ||
import { Severity } from './models/constants/severity'; | ||
|
||
class DimeSchedulerClient { | ||
private importEndPoint: ImportEndPoint; | ||
private messageEndPoint: MessageEndpoint; | ||
|
||
constructor(apiKey: string, env: Environment = Environment.Production) { | ||
this.importEndPoint = new ImportEndPoint(env, apiKey); | ||
this.messageEndPoint = new MessageEndpoint(env, apiKey); | ||
} | ||
|
||
import(importable: IImportModel | Array<IImportModel>, append: boolean = true) { | ||
import(importable: IImportModel | Array<IImportModel>, append: boolean = true): Promise<ImportResponse> { | ||
return this.importEndPoint.processAsync(importable, append); | ||
} | ||
|
||
sendMessage(text: string, severity: Severity, user?: string): Promise<void> { | ||
return this.messageEndPoint.processAsync(text, severity, user); | ||
} | ||
} | ||
|
||
export default DimeSchedulerClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import axios from 'axios'; | ||
import Endpoint from './endpoint'; | ||
import Environment from '../environment'; | ||
import { Severity } from '../models/constants/severity'; | ||
|
||
class MessageEndpoint extends Endpoint { | ||
constructor(env: Environment, apiKey: string) { | ||
super(env, apiKey); | ||
} | ||
|
||
async processAsync(text: string, severity: Severity, user?: string): Promise<void> { | ||
const params = { | ||
Text: text, | ||
User: user, | ||
Severity: severity | ||
}; | ||
|
||
const body = JSON.stringify(params); | ||
|
||
const headers = { | ||
'X-API-KEY': this.apiKey, | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
}; | ||
|
||
const url = this.uri + '/message'; | ||
await axios.post(url, body, { headers: headers }); | ||
} | ||
} | ||
|
||
export default MessageEndpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DimeSchedulerClient, { Environment } from '../dist'; | ||
|
||
import { apiKey } from "./testvars"; | ||
import { Severity } from '../dist/lib/models/constants/severity'; | ||
|
||
describe('Message', function () { | ||
describe('#sendMessage()', function () { | ||
it.only('Should successfully send message', async () => { | ||
const client = new DimeSchedulerClient(apiKey, Environment.Test); | ||
await client.sendMessage("Hello world!", Severity.Warning); | ||
}); | ||
}); | ||
}); |