-
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
0 parents
commit 91905bf
Showing
9 changed files
with
143 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
} |
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,12 @@ | ||
# Monoova | ||
|
||
## Prerequisite | ||
|
||
Make sure you have [deno](https://deno.land/#installation) installed. | ||
|
||
## Usage | ||
|
||
```sh | ||
$ export MONOOVA_API_KEY=xxx | ||
$ deno run --allow-net --allow-env scripts/ping.ts | ||
``` |
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,37 @@ | ||
export type Client = { | ||
apiKey: string; | ||
baseUrl: string; | ||
}; | ||
|
||
export function newSandboxClient(apiKey: string): Client { | ||
return { | ||
apiKey: apiKey, | ||
baseUrl: "https://api.m-pay.com.au", | ||
}; | ||
} | ||
|
||
export function newProductionClient(apiKey: string): Client { | ||
return { | ||
apiKey: apiKey, | ||
baseUrl: "https://api.mpay.com.au", | ||
}; | ||
} | ||
|
||
export async function request( | ||
client: Client, | ||
method: string, | ||
path: string, | ||
body?: Record<string, unknown>, | ||
): Promise<Record<string, unknown>> { | ||
const url = client.baseUrl + path; | ||
const headers = new Headers({ | ||
"Authorization": "Basic " + btoa(client.apiKey + ":"), | ||
"Content-Type": "application/json", | ||
}); | ||
const response = await fetch(url, { | ||
method, | ||
headers, | ||
body: JSON.stringify(body), | ||
}); | ||
return response.json(); | ||
} |
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,37 @@ | ||
import { | ||
Client, | ||
newProductionClient, | ||
newSandboxClient, | ||
} from "../lib/monoova_client.ts"; | ||
|
||
function getAPIKey(): string { | ||
const apiKey: string | undefined = Deno.env.get("MONOOVA_API_KEY"); | ||
|
||
if (apiKey === undefined) { | ||
console.error("MONOOVA_API_KEY is missing!"); | ||
Deno.exit(1); | ||
} | ||
|
||
return apiKey; | ||
} | ||
|
||
export function newClient(): Client { | ||
const apiKey = getAPIKey(); | ||
|
||
const env = getUserInput( | ||
"Please select environment:\n1. sandbox\n2. production\n>>", | ||
); | ||
|
||
if (env === "1") { | ||
return newSandboxClient(apiKey); | ||
} else if (env === "2") { | ||
return newProductionClient(apiKey); | ||
} else { | ||
Deno.exit(1); | ||
} | ||
} | ||
|
||
export function getUserInput(message: string): string { | ||
const input = prompt(message) || ""; | ||
return input.trim(); | ||
} |
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,8 @@ | ||
import { newClient } from "./_helpers.ts"; | ||
import { request } from "../lib/monoova_client.ts"; | ||
|
||
const client = newClient(); | ||
|
||
const json = await request(client, "GET", "/subscriptions/v1/list"); | ||
|
||
console.log(json); |
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,7 @@ | ||
import { newClient } from "./_helpers.ts"; | ||
import { request } from "../lib/monoova_client.ts"; | ||
|
||
const client = newClient(); | ||
const json = await request(client, "GET", "/tools/v1/ping"); | ||
|
||
console.log(json); |
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,15 @@ | ||
import { getUserInput, newClient } from "./_helpers.ts"; | ||
import { request } from "../lib/monoova_client.ts"; | ||
|
||
const client = newClient(); | ||
|
||
const eventName = getUserInput("event name:"); | ||
const targetUrl = getUserInput("target url:"); | ||
|
||
const json = await request(client, "POST", "/subscriptions/v1/create", { | ||
"eventName": eventName, | ||
"targetUrl": targetUrl, | ||
"subscriptionStatus": "On", | ||
}); | ||
|
||
console.log(json); |
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,10 @@ | ||
import { getUserInput, newClient } from "./_helpers.ts"; | ||
import { request } from "../lib/monoova_client.ts"; | ||
|
||
const client = newClient(); | ||
|
||
const id = getUserInput("id:"); | ||
|
||
const json = await request(client, "DELETE", "/subscriptions/v1/delete/" + id); | ||
|
||
console.log(json); |
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,10 @@ | ||
import { getUserInput, newClient } from "./_helpers.ts"; | ||
import { request } from "../lib/monoova_client.ts"; | ||
|
||
const client = newClient(); | ||
|
||
const bsbNumber = getUserInput("bsb number:"); | ||
|
||
const json = await request(client, "GET", "/tools/v1/bsbValidate/" + bsbNumber); | ||
|
||
console.log(json); |