letterxpress/ts/letterxpress.classes.account.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-11-16 16:54:45 +00:00
import * as plugins from './letterxpress.plugins';
export interface ILetterXpressConstructorOptions {
email: string;
apiKey: string;
}
2019-11-16 16:54:45 +00:00
export class LetterXpressAccount {
2019-11-21 14:01:41 +00:00
public baseApiUrl = 'https://api.letterxpress.de/v1/';
public options: ILetterXpressConstructorOptions;
2019-11-21 14:01:41 +00:00
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.smartletter.Letter>();
constructor(optionsArg: ILetterXpressConstructorOptions) {
this.options = optionsArg;
}
2019-11-21 14:01:41 +00:00
/**
* sends a letter
* @param letterArg
*/
public async sendLetter(letterArg: plugins.smartletter.Letter) {
const letterPdfResult = await letterArg.getPdfResult();
const response = await this.request('/setJob', 'POST', {});
}
/**
* fires the request
*/
private async request(routeArg: string, methodArg: 'GET' | 'POST', payload?: any) {
const requestUrl = `${this.baseApiUrl}`;
const requestData = {
auth: {
username: this.options.email,
apikey: this.options.apiKey
},
...payload
};
const response = await plugins.smartrequest.request(routeArg, {
method: methodArg,
headers: {
'Content-Type': 'application/json'
},
requestBody: JSON.stringify(requestData)
});
}
}