-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
94 lines (88 loc) · 3.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var soap = require('soap');
const client = (function () {
'use strict';
function methods(client, key) {
return {
searchLightningByCoords({ x, y, range }) {
return new Promise((resolve, reject) => {
client.szukaj_burzy({ x, y, promien: range, klucz: key }, (err, result) => {
if (err) {
return reject(err);
}
let returned = result.return;
resolve({
count: returned.liczba.$value,
distance: returned.odleglosc.$value,
direction: returned.kierunek.$value || '',
time: returned.okres.$value
});
});
});
},
searchCoordsByCityName({ city }) {
return new Promise((resolve, reject) => {
client.miejscowosc({ nazwa: city, klucz: key }, (err, result) => {
if (err) {
return reject(err);
}
let returned = result.return;
resolve({
x: Number(returned.x.$value),
y: Number(returned.y.$value)
})
});
});
},
searchWarningsByCoords({ x, y }) {
return new Promise((resolve, reject) => {
client.ostrzezenia_pogodowe({ x, y, klucz: key }, (err, result) => {
if (err) {
return reject(err);
}
let returned = result.return;
resolve({
frost: returned.mroz.$value,
frostOf: returned.mroz_od_dnia.$value,
frostTo: returned.mroz_do_dnia.$value,
heat: returned.upal.$value,
heatOf: returned.upal_od_dnia.$value,
heatTo: returned.upal_do_dnia.$value,
wind: returned.wiatr.$value,
windOf: returned.wiatr_od_dnia.$value,
windTo: returned.wiatr_do_dnia.$value,
rainfall: returned.opad.$value,
rainfallOf: returned.opad_od_dnia.$value,
rainfallTo: returned.opad_do_dnia.$value,
storm: returned.burza.$value,
stormOf: returned.burza_od_dnia.$value,
stormTo: returned.burza_do_dnia.$value,
whirlwind: returned.traba.$value,
whirlwindOf: returned.traba_od_dnia.$value,
whirlwindTo: returned.traba_do_dnia.$value
});
});
});
}
}
}
class Service {
constructor({ url, key }) {
this.url = url;
this.key = key;
}
connect() {
return new Promise((resolve, reject) => {
soap.createClient(this.url, (err, client) => {
if (err) {
return reject(err);
}
resolve(methods(client, this.key));
});
});
}
}
return {
Service
};
}());
module.exports = client;