Skip to content

Commit 9081343

Browse files
committed
Add readme
1 parent 96cd7e9 commit 9081343

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
11
# typescript-sdk
2-
Typescript SDK for GetTestMail
2+
Typescript client for interacting with the GetTestMail API, which provides a simple way to create temporary email addresses and receive emails sent to them.
3+
4+
## Installation
5+
```bash
6+
npm install @gettestmail/typescript-sdk
7+
```
8+
9+
## Compatibility
10+
11+
>Works on Browser, Node.js and React Native!
12+
13+
14+
## Usage
15+
16+
To create a new GetTestMail API client, you need to instantiate the GetTestMail class with your API key. To get an API key, sign up for a free [account](https://gettestmail.com).
17+
18+
19+
```typescript
20+
import { GetTestMail } from "@gettestmail/typescript-sdk";
21+
22+
const testMail = new GetTestMail('YOUR_API_KEY')
23+
```
24+
25+
### Create a new email address
26+
27+
```typescript
28+
const mailBox = await testMail.createNew()
29+
```
30+
31+
### Wait for an email to be received
32+
33+
```typescript
34+
const { message } = await testMail.waitForMessage(mailBox.emailAddress)
35+
```
36+

lib/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIError, CreateNewRequest, CreateNewResponse, GetTestMail, Problem, WaitForMessageResponse } from "./models";
1+
import { APIError, CreateNewRequest, GetTestMail, Problem } from "./models";
22

33
class GetTestMailClient {
44
private apiKey: string;
@@ -9,7 +9,7 @@ class GetTestMailClient {
99
this.baseUrl = baseUrl;
1010
}
1111

12-
async createNew(request?: CreateNewRequest): Promise<CreateNewResponse> {
12+
async createNew(request?: CreateNewRequest): Promise<GetTestMail> {
1313
const response = await fetch(`${this.baseUrl}/gettestmail`, {
1414
method: 'POST',
1515
headers: {
@@ -23,12 +23,12 @@ class GetTestMailClient {
2323
const problem: Problem = await response.json();
2424
throw new APIError(problem);
2525
}
26-
2726
const getTestMail: GetTestMail = await response.json();
28-
return { getTestMail };
27+
28+
return getTestMail;
2929
}
3030

31-
async waitForMessage(id: string): Promise<WaitForMessageResponse> {
31+
async waitForMessage(id: string): Promise<GetTestMail> {
3232
const response = await fetch(`${this.baseUrl}/gettestmail/${id}`, {
3333
method: 'GET',
3434
redirect: 'follow',
@@ -42,9 +42,9 @@ class GetTestMailClient {
4242
const problem: Problem = await response.json();
4343
throw new APIError(problem);
4444
}
45-
4645
const getTestMail: GetTestMail = await response.json();
47-
return { getTestMail };
46+
47+
return getTestMail;
4848
}
4949
}
5050

lib/models.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,3 @@ export class APIError extends Error {
4444
export type CreateNewRequest = {
4545
expiresAt: string;
4646
};
47-
48-
export interface CreateNewResponse {
49-
getTestMail: GetTestMail;
50-
}
51-
52-
export interface WaitForMessageResponse {
53-
getTestMail: GetTestMail;
54-
}

0 commit comments

Comments
 (0)