1 |
|
2 |
|
3 |
|
4 |
|
5 | import * as Request from 'request'
|
6 | import { CLDebug } from './CLDebug'
|
7 |
|
8 | export class AzureFunctions {
|
9 | public static Call(azureFunctionsUrl: string, azureFunctionsKey: string, funcName: string, args: string): Promise<string> {
|
10 | let apiPath = 'app'
|
11 |
|
12 | if (azureFunctionsKey) {
|
13 | if (args) {
|
14 | args += `&code=${azureFunctionsKey}`
|
15 | } else {
|
16 | args = `?code=${azureFunctionsKey}`
|
17 | }
|
18 | }
|
19 | return new Promise((resolve, reject) => {
|
20 | const requestData = {
|
21 | url: azureFunctionsUrl + funcName + '/' + args,
|
22 | |
23 |
|
24 |
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | json: true
|
33 | }
|
34 | CLDebug.LogRequest('GET', apiPath, requestData)
|
35 | Request.get(requestData, (error, response, body) => {
|
36 | if (error) {
|
37 | reject(error)
|
38 | } else if (response.statusCode && response.statusCode >= 300) {
|
39 | reject(body)
|
40 | } else {
|
41 | resolve(body.Result)
|
42 | }
|
43 | })
|
44 | })
|
45 | }
|
46 | }
|