swiftyper-node 1.0.1 → 1.0.2
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/LICENSE +19 -19
- package/README.md +2 -2
- package/lib/Error.js +76 -76
- package/lib/SwiftyperMethod.js +21 -21
- package/lib/SwiftyperResource.js +349 -349
- package/lib/makeRequest.js +103 -103
- package/lib/resources/Business.js +23 -23
- package/lib/resources/Places.js +53 -53
- package/lib/resources/Translation.js +33 -0
- package/lib/resources.js +1 -0
- package/lib/swiftyper.js +159 -159
- package/lib/utils.js +277 -277
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Copyright (C) 2021 Swiftyper (https://swiftyper.sk)
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
|
1
|
+
Copyright (C) 2021 Swiftyper (https://swiftyper.sk)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Pred začatím používania je nutné nastaviť API kľúč ktorý môžete spra
|
|
|
22
22
|
|
|
23
23
|
**API kľúče sú predvolene neobmedzené.** Neobmedzené kľúče nie sú bezpečné, pretože ich môže používať ktokoľvek a odkiaľkoľvek. Pre produkčné aplikácie odporúčame nastaviť obmedzenia API kľúča nakoľko pomáhajú zabrániť neoprávnenému použitiu a vyčerpávaniu kvót. Obmedzenia určujú, ktoré webové stránky alebo IP adresy môžu používať API kľúč.
|
|
24
24
|
```js
|
|
25
|
-
const swiftyper = require('swiftyper')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
|
|
25
|
+
const swiftyper = require('swiftyper-node')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
|
|
26
26
|
|
|
27
27
|
swiftyper.business.query({query: 'Google Slovakia', country: 'SK'})
|
|
28
28
|
.then(business => console.log(business))
|
|
@@ -39,7 +39,7 @@ swiftyper.business.detail('sk_WbilvhDEDokFTWk0FbNjeQ', function(err, result) {
|
|
|
39
39
|
Alebo s použitím `async`/`await`:
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
import Swiftyper from 'swiftyper';
|
|
42
|
+
import Swiftyper from 'swiftyper-node';
|
|
43
43
|
const swiftyper = new Swiftyper('VÁŠ_API_KĽÚČ_SLUŽBY_PLACES');
|
|
44
44
|
|
|
45
45
|
(async () => {
|
package/lib/Error.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class SwiftyperError extends Error {
|
|
4
|
-
constructor(raw = {}) {
|
|
5
|
-
super(raw.message);
|
|
6
|
-
this.type = this.constructor.name;
|
|
7
|
-
|
|
8
|
-
this.raw = raw;
|
|
9
|
-
this.rawType = raw.type;
|
|
10
|
-
this.code = raw.code;
|
|
11
|
-
this.param = raw.param;
|
|
12
|
-
this.headers = raw.headers;
|
|
13
|
-
this.statusCode = raw.statusCode;
|
|
14
|
-
this.message = raw.message;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static generate(rawSwiftyperError) {
|
|
18
|
-
switch (rawSwiftyperError.code) {
|
|
19
|
-
case "over_query_limit":
|
|
20
|
-
return new SwiftyperQuotaError(rawSwiftyperError);
|
|
21
|
-
case "missing":
|
|
22
|
-
return new SwiftyperMissingError(rawSwiftyperError);
|
|
23
|
-
case "restricted":
|
|
24
|
-
return new SwiftyperRestrictedError(rawSwiftyperError);
|
|
25
|
-
case 'unexpected_parameter':
|
|
26
|
-
return new SwiftyperUnexpectedParameterError(rawSwiftyperError);
|
|
27
|
-
case 'invalid_request':
|
|
28
|
-
return new SwiftyperInvalidRequestError(rawSwiftyperError);
|
|
29
|
-
case 'invalid_parameter':
|
|
30
|
-
return new SwiftyperInvalidParameterError(rawSwiftyperError);
|
|
31
|
-
case 'missing_parameter':
|
|
32
|
-
return new SwiftyperMissingParameterError(rawSwiftyperError);
|
|
33
|
-
case 'invalid_api_key':
|
|
34
|
-
return new SwiftyperInvalidApiKeyError(rawSwiftyperError);
|
|
35
|
-
case 'rate_limit':
|
|
36
|
-
return new SwiftypeRateLimitError(rawSwiftyperError);
|
|
37
|
-
default:
|
|
38
|
-
return new GenericError({message: 'Unknown Error'});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class GenericError extends SwiftyperError {}
|
|
44
|
-
|
|
45
|
-
class SwiftyperUnexpectedParameterError extends SwiftyperError {}
|
|
46
|
-
|
|
47
|
-
class SwiftypeRateLimitError extends SwiftyperError {}
|
|
48
|
-
|
|
49
|
-
class SwiftyperInvalidRequestError extends SwiftyperError {}
|
|
50
|
-
|
|
51
|
-
class SwiftyperInvalidParameterError extends SwiftyperError {}
|
|
52
|
-
|
|
53
|
-
class SwiftyperMissingParameterError extends SwiftyperError {}
|
|
54
|
-
|
|
55
|
-
class SwiftyperInvalidApiKeyError extends SwiftyperError {}
|
|
56
|
-
|
|
57
|
-
class SwiftyperAPIError extends SwiftyperError {}
|
|
58
|
-
|
|
59
|
-
class SwiftyperQuotaError extends SwiftyperError {}
|
|
60
|
-
|
|
61
|
-
class SwiftyperMissingError extends SwiftyperError {}
|
|
62
|
-
|
|
63
|
-
class SwiftyperRestrictedError extends SwiftyperError {}
|
|
64
|
-
|
|
65
|
-
class SwiftyperConnectionError extends SwiftyperError {}
|
|
66
|
-
|
|
67
|
-
module.exports.generate = SwiftyperError.generate;
|
|
68
|
-
module.exports.SwiftyperError = SwiftyperError;
|
|
69
|
-
module.exports.SwiftyperUnexpectedParameterError = SwiftyperUnexpectedParameterError;
|
|
70
|
-
module.exports.SwiftypeRateLimitError = SwiftypeRateLimitError;
|
|
71
|
-
module.exports.SwiftyperInvalidApiKeyError = SwiftyperInvalidApiKeyError;
|
|
72
|
-
module.exports.SwiftyperInvalidParameterError = SwiftyperInvalidParameterError;
|
|
73
|
-
module.exports.SwiftyperAPIError = SwiftyperAPIError;
|
|
74
|
-
module.exports.SwiftyperMissingError = SwiftyperMissingError;
|
|
75
|
-
module.exports.SwiftyperRestrictedError = SwiftyperRestrictedError;
|
|
76
|
-
module.exports.SwiftyperConnectionError = SwiftyperConnectionError;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class SwiftyperError extends Error {
|
|
4
|
+
constructor(raw = {}) {
|
|
5
|
+
super(raw.message);
|
|
6
|
+
this.type = this.constructor.name;
|
|
7
|
+
|
|
8
|
+
this.raw = raw;
|
|
9
|
+
this.rawType = raw.type;
|
|
10
|
+
this.code = raw.code;
|
|
11
|
+
this.param = raw.param;
|
|
12
|
+
this.headers = raw.headers;
|
|
13
|
+
this.statusCode = raw.statusCode;
|
|
14
|
+
this.message = raw.message;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static generate(rawSwiftyperError) {
|
|
18
|
+
switch (rawSwiftyperError.code) {
|
|
19
|
+
case "over_query_limit":
|
|
20
|
+
return new SwiftyperQuotaError(rawSwiftyperError);
|
|
21
|
+
case "missing":
|
|
22
|
+
return new SwiftyperMissingError(rawSwiftyperError);
|
|
23
|
+
case "restricted":
|
|
24
|
+
return new SwiftyperRestrictedError(rawSwiftyperError);
|
|
25
|
+
case 'unexpected_parameter':
|
|
26
|
+
return new SwiftyperUnexpectedParameterError(rawSwiftyperError);
|
|
27
|
+
case 'invalid_request':
|
|
28
|
+
return new SwiftyperInvalidRequestError(rawSwiftyperError);
|
|
29
|
+
case 'invalid_parameter':
|
|
30
|
+
return new SwiftyperInvalidParameterError(rawSwiftyperError);
|
|
31
|
+
case 'missing_parameter':
|
|
32
|
+
return new SwiftyperMissingParameterError(rawSwiftyperError);
|
|
33
|
+
case 'invalid_api_key':
|
|
34
|
+
return new SwiftyperInvalidApiKeyError(rawSwiftyperError);
|
|
35
|
+
case 'rate_limit':
|
|
36
|
+
return new SwiftypeRateLimitError(rawSwiftyperError);
|
|
37
|
+
default:
|
|
38
|
+
return new GenericError({message: 'Unknown Error'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class GenericError extends SwiftyperError {}
|
|
44
|
+
|
|
45
|
+
class SwiftyperUnexpectedParameterError extends SwiftyperError {}
|
|
46
|
+
|
|
47
|
+
class SwiftypeRateLimitError extends SwiftyperError {}
|
|
48
|
+
|
|
49
|
+
class SwiftyperInvalidRequestError extends SwiftyperError {}
|
|
50
|
+
|
|
51
|
+
class SwiftyperInvalidParameterError extends SwiftyperError {}
|
|
52
|
+
|
|
53
|
+
class SwiftyperMissingParameterError extends SwiftyperError {}
|
|
54
|
+
|
|
55
|
+
class SwiftyperInvalidApiKeyError extends SwiftyperError {}
|
|
56
|
+
|
|
57
|
+
class SwiftyperAPIError extends SwiftyperError {}
|
|
58
|
+
|
|
59
|
+
class SwiftyperQuotaError extends SwiftyperError {}
|
|
60
|
+
|
|
61
|
+
class SwiftyperMissingError extends SwiftyperError {}
|
|
62
|
+
|
|
63
|
+
class SwiftyperRestrictedError extends SwiftyperError {}
|
|
64
|
+
|
|
65
|
+
class SwiftyperConnectionError extends SwiftyperError {}
|
|
66
|
+
|
|
67
|
+
module.exports.generate = SwiftyperError.generate;
|
|
68
|
+
module.exports.SwiftyperError = SwiftyperError;
|
|
69
|
+
module.exports.SwiftyperUnexpectedParameterError = SwiftyperUnexpectedParameterError;
|
|
70
|
+
module.exports.SwiftypeRateLimitError = SwiftypeRateLimitError;
|
|
71
|
+
module.exports.SwiftyperInvalidApiKeyError = SwiftyperInvalidApiKeyError;
|
|
72
|
+
module.exports.SwiftyperInvalidParameterError = SwiftyperInvalidParameterError;
|
|
73
|
+
module.exports.SwiftyperAPIError = SwiftyperAPIError;
|
|
74
|
+
module.exports.SwiftyperMissingError = SwiftyperMissingError;
|
|
75
|
+
module.exports.SwiftyperRestrictedError = SwiftyperRestrictedError;
|
|
76
|
+
module.exports.SwiftyperConnectionError = SwiftyperConnectionError;
|
package/lib/SwiftyperMethod.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('./utils');
|
|
4
|
-
const makeRequest = require('./makeRequest');
|
|
5
|
-
|
|
6
|
-
function swiftyperMethod(spec) {
|
|
7
|
-
return function(...args) {
|
|
8
|
-
const callback = typeof args[args.length - 1] == 'function' && args.pop();
|
|
9
|
-
|
|
10
|
-
spec.urlParams = utils.extractUrlParams(
|
|
11
|
-
this.createResourcePathWithSymbols(spec.path || '')
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
return utils.callbackifyPromiseWithTimeout(
|
|
15
|
-
makeRequest(this, args, spec, {}),
|
|
16
|
-
callback
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = swiftyperMethod;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utils = require('./utils');
|
|
4
|
+
const makeRequest = require('./makeRequest');
|
|
5
|
+
|
|
6
|
+
function swiftyperMethod(spec) {
|
|
7
|
+
return function(...args) {
|
|
8
|
+
const callback = typeof args[args.length - 1] == 'function' && args.pop();
|
|
9
|
+
|
|
10
|
+
spec.urlParams = utils.extractUrlParams(
|
|
11
|
+
this.createResourcePathWithSymbols(spec.path || '')
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return utils.callbackifyPromiseWithTimeout(
|
|
15
|
+
makeRequest(this, args, spec, {}),
|
|
16
|
+
callback
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = swiftyperMethod;
|