Skip to content

Commit a30aa5f

Browse files
committed
Bumped v1
Signed-off-by: Vishal Rana <[email protected]>
1 parent aaeafbf commit a30aa5f

15 files changed

+2831
-547
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
Axis: require('./lib/axis')
3-
}
2+
Client: require("./lib/client").Client
3+
};

lib/axis.js

-88
This file was deleted.

lib/client.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const got = require("got");
2+
const { CurrencyService } = require("./currency");
3+
const { EmailService } = require("./email");
4+
const { DomainService } = require("./domain");
5+
const { IPService } = require("./ip");
6+
const { WebpageService } = require("./webpage");
7+
8+
class Client {
9+
constructor(key) {
10+
this.key = key;
11+
}
12+
13+
_request(method, url, query, body, json) {
14+
console.log(method, url);
15+
return got(url, {
16+
method,
17+
headers: {
18+
Authorization: `Bearer ${this.key}`
19+
},
20+
query,
21+
body,
22+
json
23+
})
24+
.then(response => {
25+
if (json) {
26+
return response.body;
27+
}
28+
return JSON.parse(response.body);
29+
})
30+
.catch(error => {
31+
if (error instanceof got.HTTPError) {
32+
const body = JSON.parse(error.response.body);
33+
throw new LabStackError(body.code, body.message);
34+
} else {
35+
throw new LabStackError(0, error);
36+
}
37+
});
38+
}
39+
40+
currency() {
41+
return new CurrencyService(this);
42+
}
43+
44+
domain() {
45+
return new DomainService(this);
46+
}
47+
48+
email() {
49+
return new EmailService(this);
50+
}
51+
52+
ip() {
53+
return new IPService(this);
54+
}
55+
56+
webpage() {
57+
return new WebpageService(this);
58+
}
59+
}
60+
61+
class LabStackError extends Error {
62+
constructor(code, message) {
63+
super(message);
64+
this.code = code;
65+
Error.captureStackTrace(this, LabStackError);
66+
this.name = this.constructor.name;
67+
}
68+
}
69+
70+
module.exports = {
71+
Client,
72+
LabStackError
73+
};

lib/currency.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class CurrencyService {
2+
constructor(client) {
3+
this.client = client;
4+
this.url = "https://currency.labstack.com/api/v1";
5+
}
6+
7+
convert(request) {
8+
return this.client._request(
9+
"GET",
10+
`${this.url}/convert/${request.amount}/${request.from}/${request.to}`
11+
);
12+
}
13+
14+
list(request) {
15+
return this.client._request("GET", `${this.url}/list`);
16+
}
17+
}
18+
19+
module.exports = {
20+
CurrencyService
21+
};

lib/domain.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class DomainService {
2+
constructor(client) {
3+
this.client = client;
4+
this.url = "https://domain.labstack.com/api/v1";
5+
}
6+
7+
dns(request) {
8+
return this.client._request(
9+
"GET",
10+
`${this.url}/${request.type}/${request.domain}`
11+
);
12+
}
13+
14+
search(request) {
15+
return this.client._request("GET", `${this.url}/search/${request.domain}`);
16+
}
17+
18+
status(request) {
19+
return this.client._request("GET", `${this.url}/status/${request.domain}`);
20+
}
21+
22+
whois(request) {
23+
return this.client._request("GET", `${this.url}/whois/${request.domain}`);
24+
}
25+
}
26+
27+
module.exports = {
28+
DomainService
29+
};

lib/email.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class EmailService {
2+
constructor(client) {
3+
this.client = client;
4+
this.url = "https://email.labstack.com/api/v1";
5+
}
6+
7+
verify(request) {
8+
return this.client._request("GET", `${this.url}/verify/${request.email}`);
9+
}
10+
}
11+
12+
module.exports = {
13+
EmailService
14+
};

lib/ip.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class IPService {
2+
constructor(client) {
3+
this.client = client;
4+
this.url = "https://ip.labstack.com/api/v1";
5+
}
6+
7+
lookup(request) {
8+
return this.client._request("GET", `${this.url}/${request.ip}`);
9+
}
10+
}
11+
12+
module.exports = {
13+
IPService
14+
};

lib/webpage.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class WebpageService {
2+
constructor(client) {
3+
this.client = client;
4+
this.url = "https://webpage.labstack.com/api/v1";
5+
}
6+
7+
image(request) {
8+
return this.client._request("GET", `${this.url}/image`, {
9+
url: request.url
10+
});
11+
}
12+
13+
pdf(request) {
14+
return this.client._request("GET", `${this.url}/pdf`, {
15+
url: request.url
16+
});
17+
}
18+
}
19+
20+
module.exports = {
21+
WebpageService
22+
};

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "labstack",
3-
"version": "0.50.1",
4-
"description": "Official Node.js client library for the LabStack platform",
3+
"version": "1.0.1",
4+
"description": "Official Node.js client library for the LabStack API",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "ava"
88
},
99
"repository": {
1010
"type": "git",
@@ -18,10 +18,12 @@
1818
},
1919
"homepage": "https://github.com/labstack/labstack-node#readme",
2020
"dependencies": {
21-
"got": "^8.3.1",
22-
"mqtt": "^2.18.1"
21+
"got": "^9.6.0"
2322
},
2423
"engines": {
25-
"node": ">= 8"
24+
"node": ">= 10"
25+
},
26+
"devDependencies": {
27+
"ava": "^2.2.0"
2628
}
2729
}

test/currency.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import test from "ava";
2+
import { Client } from "..";
3+
4+
const cs = new Client(process.env.KEY).currency();
5+
6+
test("convert", async t => {
7+
await t.notThrowsAsync(async () => {
8+
const response = await cs.convert({
9+
amount: 10,
10+
from: "USD",
11+
to: "INR"
12+
});
13+
t.not(response.amount, "0");
14+
});
15+
});
16+
17+
test("list", async t => {
18+
await t.notThrowsAsync(async () => {
19+
const response = await cs.list();
20+
t.not(response.currencies.length, "0");
21+
});
22+
});

test/domain.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import test from "ava";
2+
import { Client } from "..";
3+
4+
const ds = new Client(process.env.KEY).domain();
5+
6+
test("dns", async t => {
7+
await t.notThrowsAsync(async () => {
8+
const response = await ds.dns({
9+
type: "A",
10+
domain: "twilio.com"
11+
});
12+
t.not(response.records.length, 0);
13+
});
14+
});
15+
16+
test("search", async t => {
17+
await t.notThrowsAsync(async () => {
18+
const response = await ds.search({
19+
domain: "twilio.com"
20+
});
21+
t.not(response.results.length, 0);
22+
});
23+
});
24+
25+
test("status", async t => {
26+
await t.notThrowsAsync(async () => {
27+
const response = await ds.status({
28+
domain: "twilio.com"
29+
});
30+
t.is(response.result, "unavailable");
31+
});
32+
});
33+
34+
test("whois", async t => {
35+
await t.notThrowsAsync(async () => {
36+
const response = await ds.whois({
37+
domain: "twilio.com"
38+
});
39+
t.not(response.raw, "");
40+
});
41+
});

test/email.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test from "ava";
2+
import { Client } from "..";
3+
4+
const es = new Client(process.env.KEY).email();
5+
6+
test("verify", async t => {
7+
await t.notThrowsAsync(async () => {
8+
const response = await es.verify({
9+
10+
});
11+
t.is(response.result, "deliverable");
12+
});
13+
});

test/ip.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test from "ava";
2+
import { Client } from "..";
3+
4+
const is = new Client(process.env.KEY).ip();
5+
6+
test("lookup", async t => {
7+
await t.notThrowsAsync(async () => {
8+
const response = await is.lookup({
9+
ip: "96.45.83.67"
10+
});
11+
t.not(response.country, "");
12+
});
13+
});

0 commit comments

Comments
 (0)