fakenada 9.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +65 -0
- package/package.json +18 -0
package/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
const BASE_API_URL = 'https://getnada.com/api/v1';
|
|
4
|
+
const GET_INBOX_URL_TEMPLATE = `${BASE_API_URL}/inboxes/{email}`;
|
|
5
|
+
const DELETE_EMAIL_URL_TEMPLATE = `${BASE_API_URL}/messages/{uid}`;
|
|
6
|
+
|
|
7
|
+
class Pynada {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.inboxes = new Map();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async inbox(email) {
|
|
13
|
+
if (!this.inboxes.has(email)) {
|
|
14
|
+
const inbox = new PynadaInbox(email);
|
|
15
|
+
await inbox.getEmails();
|
|
16
|
+
this.inboxes.set(email, inbox);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this.inboxes.get(email);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class PynadaInbox {
|
|
24
|
+
constructor(email) {
|
|
25
|
+
this.inboxEmail = email;
|
|
26
|
+
this.emails = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getEmails() {
|
|
30
|
+
const response = await axios.get(GET_INBOX_URL_TEMPLATE.replace('{email}', this.inboxEmail));
|
|
31
|
+
if (response.status !== 200) {
|
|
32
|
+
throw new Error(`Can't get inbox ${this.inboxEmail}`);
|
|
33
|
+
}
|
|
34
|
+
const emailsData = response.data.msgs;
|
|
35
|
+
for (const emailData of emailsData) {
|
|
36
|
+
this.emails.push(emailData);
|
|
37
|
+
}
|
|
38
|
+
return this.emails; // Return the emails array
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async deleteEmail(uid) {
|
|
42
|
+
const response = await axios.delete(DELETE_EMAIL_URL_TEMPLATE.replace('{uid}', uid));
|
|
43
|
+
console.log(response.data);
|
|
44
|
+
console.log(response.status);
|
|
45
|
+
if (response.status !== 201) {
|
|
46
|
+
throw new Error(`Couldn't delete email: ${uid}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Usage example
|
|
52
|
+
const pynada = new Pynada();
|
|
53
|
+
const email = '147vienami@getnada.com';
|
|
54
|
+
pynada.inbox(email)
|
|
55
|
+
.then(inbox => {
|
|
56
|
+
return inbox.getEmails();
|
|
57
|
+
})
|
|
58
|
+
.then(emails => {
|
|
59
|
+
const uids = emails.map(email => email.uid);
|
|
60
|
+
console.log(uids);
|
|
61
|
+
})
|
|
62
|
+
.catch(error => {
|
|
63
|
+
console.error(error);
|
|
64
|
+
});
|
|
65
|
+
module.exports = Pynada;
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fakenada",
|
|
3
|
+
"version": "9.9.9",
|
|
4
|
+
"description": "clgrt",
|
|
5
|
+
"main": "node index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node index.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git.cl"
|
|
12
|
+
},
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "^1.4.0"
|
|
17
|
+
}
|
|
18
|
+
}
|