48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import * as plugins from './letterxpress.plugins';
|
|
|
|
export interface ILetterXpressConstructorOptions {
|
|
email: string;
|
|
apiKey: string;
|
|
}
|
|
|
|
export class LetterXpressAccount {
|
|
public baseApiUrl = 'https://api.letterxpress.de/v1/';
|
|
public options: ILetterXpressConstructorOptions;
|
|
|
|
public letterSentObservable = new plugins.smartrx.rxjs.Subject<plugins.smartletter.Letter>();
|
|
|
|
constructor(optionsArg: ILetterXpressConstructorOptions) {
|
|
this.options = optionsArg;
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
});
|
|
}
|
|
}
|