1 | ;
|
2 |
|
3 | var _ = require('lodash');
|
4 | var utils = require('./lib/utils');
|
5 |
|
6 | /**
|
7 | * A module for interacting with currency-conversion API
|
8 | * @module currency-conversion
|
9 | */
|
10 |
|
11 | /**
|
12 | * currency-conversion constructor.
|
13 | * @param {object} options Options to be passed in
|
14 | * @constructor
|
15 | */
|
16 | function API(options) {
|
17 |
|
18 | this.options = utils.extend(
|
19 | {},
|
20 | options,
|
21 | {
|
22 | host: 'apilayer.net',
|
23 | context: 'api',
|
24 | key_type: 'access_key',
|
25 | secure: false,
|
26 | followRedirect: false
|
27 | }
|
28 | );
|
29 |
|
30 | /**
|
31 | * Load the apis from apis directory
|
32 | * This file holds all version information
|
33 | * @private
|
34 | */
|
35 | var apis = require('./api');
|
36 | this.addAPIs(apis);
|
37 | }
|
38 |
|
39 | /**
|
40 | * Add API endpoints to object
|
41 | *
|
42 | * @param {Array} api Api to be added
|
43 | * @private
|
44 | */
|
45 | API.prototype.addAPIs = function (apis) {
|
46 |
|
47 | for (var apiName in apis) {
|
48 |
|
49 | var API = apis[apiName];
|
50 | var api = API.bind(this);
|
51 | _.extend(api, API);
|
52 |
|
53 | this[apiName] = api;
|
54 | }
|
55 | };
|
56 |
|
57 | /**
|
58 | * Exports currency-conversion.
|
59 | */
|
60 | module.exports = API; |
\ | No newline at end of file |