UNPKG

4.71 kBMarkdownView Raw
1
2Node JavaScript wrapper for [the currencylayer API](https://currencylayer.com/).
3
4Supports both traditional callbacks and Promises/A+.
5
6 
7
8Installation
9---
10 npm install currency-conversion [--save]
11
12 
13
14Configuration
15---
16
17Before using the currencylayer API client you have to setup your account and obtain your API Access Key.
18You can get it by signing up at [https://currencylayer.com/product](https://currencylayer.com/product).
19
20 
21
22Usage
23---
24
25The general API is documented here: [https://currencylayer.com/documentation](https://currencylayer.com/documentation).
26You can find parameters, result set definitions and status codes documented here as well.
27
28
29### Setup
30
31 var API = require('currency-conversion');
32 var api = new API({
33 access_key: [ACCESS_KEY],
34 secure: [true|false] (Optional, defaults to false)
35 });
36
37#### Optional Parameters
38
39##### Secure (only available for Basic, Pro and Enterprise accounts)
40Boolean value to indicate if the calls to the API should use a secure protocol or insecure (HTTP/HTTPS). Defaults to false (HTTP, insecure).
41
42
43## Callbacks vs. Promises
44
45The Promises/A+ implementation used for this is this excellent bare bones library:
46[https://www.npmjs.com/package/promise](https://www.npmjs.com/package/promise)
47
48The language-detection library supports either mode and use of either one is not mutually exclusive to the alternative, so it's possible to use one exclusively or a combination, even in the same call, both the callback will be called and the promise handlers invoked.
49
50
51## Live
52Takes a simple string and detects the language with a list of detections.
53
54###### Define Query
55
56 var liveQuery = {
57 source: 'SGD',
58 currencies: ['USD', 'THB']
59 };
60
61###### Simple Request (using Callback)
62
63 api.live(liveQuery, function (err, result) {
64 if (err) {
65 return console.log('Live Callback (Error): ' + JSON.stringify(err));
66 }
67 console.log('Live Callback (Result): ' + JSON.stringify(result));
68 });
69
70###### Response
71 {
72 "success": true,
73 "terms": "https://currencylayer.com/terms",
74 "privacy": "https://currencylayer.com/privacy",
75 "currencies": {
76 "AED": "United Arab Emirates Dirham",
77 "AFN": "Afghan Afghani",
78 "ALL": "Albanian Lek",
79 ...
80 }
81 }
82
83## Example Application
84
85In the [rootdir]/example directory there is a fully functional application which runs all requests against all the endpoints in the API, the examples above can be seen there as source code.
86
87The example application uses a process.env variable to hold the access key.
88
89For running in development environments, it's easy to use the [https://www.npmjs.com/package/dotenv](https://www.npmjs.com/package/dotenv) to load variables from a local file into the environment.
90
91## Tests [![Travis](https://img.shields.io/travis/pmoelgaard/currency-conversion.svg)](Travis)
92
93The tests are written for any NodeJS testing library, but has been run and targeted at the [https://mochajs.org/](https://mochajs.org/) testing library.
94
95## Customer Support
96
97Need any assistance? [Get in touch with Customer Support](mailto:support@apilayer.net?subject=%5Blanguagelayer%5D).
98
99## Updates
100Stay up to date by following [@apilayernet](https://twitter.com/apilayernet) on Twitter.
101
102## Legal
103
104All usage of the languagelayer website, API, and services is subject to the [languagelayer Terms & Conditions](https://languagelayer.com/terms) and all annexed legal documents and agreements.
105
106Author
107---
108Peter Andreas Moelgaard ([GitHub](https://github.com/pmoelgaard), [Twitter](https://twitter.com/petermoelgaard))
109
110License
111---
112Licensed under the The MIT License (MIT)
113
114Copyright (©) 2016 Peter Andreas Moelgaard & apilayer
115
116Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
117
118The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
119
120THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\No newline at end of file