Skip to content

Commit

Permalink
Add message endpoint (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbulens authored Apr 27, 2024
1 parent c75c18f commit b47e121
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dimescheduler",
"description": "The Dime.Scheduler SDK",
"version": "0.1.1",
"version": "0.2.0",
"main": "./dist/index.ts",
"types": "./dist/index.d.ts",
"module": "./dist/esm/index.js",
Expand Down
11 changes: 10 additions & 1 deletion src/lib/client.ts
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;
31 changes: 31 additions & 0 deletions src/lib/endpoints/message.ts
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;
13 changes: 13 additions & 0 deletions test/message.ts
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);
});
});
});

0 comments on commit b47e121

Please sign in to comment.