Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2a1ec38

Browse files
committed
- Refactoring
- code format - adding travis-ci - change package name - adding request timeout
1 parent b37e382 commit 2a1ec38

31 files changed

+1642
-1462
lines changed

.gitignore

-68 Bytes
Binary file not shown.

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
- "0.12"
5+
- "1.8"
6+
- "2.5"
7+
- "3.3"
8+
- "4.2"
9+
- "5.5"
10+
sudo: false
11+
script:
12+
- "npm run-script test-travis"
13+
after_script:
14+
- "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

LICENSE

+118-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,118 @@
1-
The MIT License (MIT)
2-
3-
Copyright (c) 2016 Tajawal.com
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
1+
Apache License
2+
3+
Version 2.0, January 2004
4+
5+
http://www.apache.org/licenses/
6+
7+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8+
9+
1. Definitions.
10+
11+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through
12+
9 of this document.
13+
14+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
15+
16+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or
17+
are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct
18+
or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership
19+
of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
20+
21+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
22+
23+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source
24+
code, documentation source, and configuration files.
25+
26+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including
27+
but not limited to compiled object code, generated documentation, and conversions to other media types.
28+
29+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as
30+
indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix
31+
below).
32+
33+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work
34+
and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an
35+
original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain
36+
separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
37+
38+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or
39+
additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the
40+
Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner.
41+
For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent
42+
to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source
43+
code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of
44+
discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in
45+
writing by the copyright owner as "Not a Contribution."
46+
47+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been
48+
received by Licensor and subsequently incorporated within the Work.
49+
50+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to
51+
You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce,
52+
prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such
53+
Derivative Works in Source or Object form.
54+
55+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You
56+
a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent
57+
license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license
58+
applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution
59+
(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You
60+
institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that
61+
the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then
62+
any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is
63+
filed.
64+
65+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with
66+
or without modifications, and in Source or Object form, provided that You meet the following conditions:
67+
68+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
69+
You must cause any modified files to carry prominent notices stating that You changed the files; and
70+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and
71+
attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the
72+
Derivative Works; and
73+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute
74+
must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices
75+
that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text
76+
file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the
77+
Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices
78+
normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License.
79+
You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to
80+
the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the
81+
License.
82+
83+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms
84+
and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a
85+
whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in
86+
this License.
87+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for
88+
inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any
89+
additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any
90+
separate license agreement you may have executed with Licensor regarding such Contributions.
91+
92+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product
93+
names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
94+
reproducing the content of the NOTICE file.
95+
96+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and
97+
each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
98+
express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
99+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness
100+
of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this
101+
License.
102+
103+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract,
104+
or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in
105+
writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or
106+
consequential damages of any character arising as a result of this License or out of the use or inability to use the
107+
Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or
108+
any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such
109+
damages.
110+
111+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may
112+
choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations
113+
and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own
114+
behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify,
115+
defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor
116+
by reason of your accepting any such warranty or additional liability.
117+
118+
END OF TERMS AND CONDITIONS

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22
Exchange rates library for nodejs
33

44
## Motivation
5-
Swap is designed to be a simple and universal exchange rate library with support for multiple providers. This library is heavily inspired from [PHP Swap](https://github.com/florianv/swap)
5+
node-currency-swap is designed to be a simple and universal exchange rate library with support for multiple providers. This library is heavily inspired from [PHP Swap](https://github.com/florianv/swap)
66

77
## Installation
88

99
```bashp
10-
npm install node-swap
10+
npm install node-currency-swap
1111
```
1212
## Usage
1313

1414
First, you need to add a provider to swap by using addProvider() method
1515

1616
```js
17-
var swap = require('node-swap');
17+
var swap = require('node-currency-swap');
1818

19-
// Add the google finance provider
19+
// Add the google finance provider
2020
swap.addProvider(new swap.providers.GoogleFinance());
2121
```
2222

2323
You can also add multiple providers
2424

2525
```js
26-
var swap = require('node-swap');
26+
var swap = require('node-currency-swap');
2727

28-
// Add the google finance provider
28+
// Add the google finance provider
2929
swap.addProvider(new swap.providers.GoogleFinance());
3030

31-
// Add the yahoo finance provider
31+
// Add the yahoo finance provider
3232
swap.addProvider(new swap.providers.YahooFinance());
3333
```
3434

@@ -65,10 +65,10 @@ __Arguments__
6565
swap.quote({currency: 'USD/SAR'}, function (err, rate) {
6666
// print the exchange rate
6767
console.log(rate[0].value);
68-
68+
6969
// print the date from the provider
7070
console.log(rate[0].date);
71-
71+
7272
// print the provider name
7373
console.log(rate[0].provider);
7474
});
@@ -82,10 +82,10 @@ var rate = swap.quoteSync({currency: 'USD/SAR'});
8282

8383
// print the exchange rate
8484
console.log(rate[0].value);
85-
85+
8686
// print the date from the provider
8787
console.log(rate[0].date);
88-
88+
8989
// print the provider name
9090
console.log(rate[0].provider);
9191
```
@@ -98,10 +98,10 @@ var rates = swap.quoteSync({currency: 'USD/SAR', fetchMultipleRate: true});
9898
rates.forEach(function(rate){
9999
// print the exchange rate
100100
console.log(rate.value);
101-
101+
102102
// print the date from the provider
103103
console.log(rate.date);
104-
104+
105105
// print the provider name
106106
console.log(rate.provider);
107107

@@ -116,10 +116,10 @@ var rates = swap.quoteSync({currency: 'USD/SAR', cache: true});
116116
rates.forEach(function(rate){
117117
// print the exchange rate
118118
console.log(rate.value);
119-
119+
120120
// print the date from the provider
121121
console.log(rate.date);
122-
122+
123123
// print the provider name
124124
console.log(rate.provider);
125125

@@ -135,7 +135,7 @@ Swap provides an object of currency codes so you can use it to avoid typos.
135135
```js
136136
var rates = swap.quoteSync({
137137
currency: {
138-
baseCurrency: swap.currencyCodes.ISO_USD,
138+
baseCurrency: swap.currencyCodes.ISO_USD,
139139
quoteCurrency: swap.currencyCodes.ISO_AED
140140
}
141141
});
@@ -188,4 +188,4 @@ swap.addProvider(new swap.providers.NationalBankOfRomania());
188188

189189
## Copyright and license
190190

191-
Code released under the [MIT license](https://github.com/tajawal/swap/blob/master/LICENSE)
191+
Code released under the [Apache Software License v2.0](http://www.apache.org/licenses/LICENSE-2.0)

lib/cache/index.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/*
2-
* This file is part of Swap.
2+
* This file is part of node-currency-swap.
33
*
4-
* (C) 2016 Tajawal
5-
* MIT LICENCE
4+
* (C) 2016 tajawal
5+
* Apache Software License v2.0
66
*
77
*/
88

99
var cache = require('memory-cache');
1010

1111
module.exports = {
12-
/**
13-
* set exchange rate in memory
14-
* @param key
15-
* @param data
16-
* @param ttl
17-
*/
18-
setExchangeRate: function (key, data, ttl) {
19-
cache.put(key, data, ttl);
20-
},
12+
/**
13+
* set exchange rate in memory
14+
* @param key
15+
* @param data
16+
* @param ttl
17+
*/
18+
setExchangeRate: function (key, data, ttl) {
19+
cache.put(key, data, ttl);
20+
},
2121

22-
/**
23-
* get exchange rate from memory
24-
* @param key
25-
*/
26-
getExchangeRate: function (key) {
27-
return cache.get(key);
28-
}
29-
};
22+
/**
23+
* get exchange rate from memory
24+
* @param key
25+
*/
26+
getExchangeRate: function (key) {
27+
return cache.get(key);
28+
}
29+
};

lib/error/InvalidArgumentException.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* This file is part of Swap.
2+
* This file is part of node-currency-swap.
33
*
4-
* (C) 2016 Tajawal
5-
* MIT LICENCE
4+
* (C) 2016 tajawal
5+
* Apache Software License v2.0
66
*
77
*/
88

@@ -11,9 +11,9 @@
1111
* @param message
1212
*/
1313
var InvalidArgumentException = module.exports = function (message) {
14-
Error.captureStackTrace(this, this.constructor);
15-
this.name = this.constructor.name;
16-
this.message = message;
14+
Error.captureStackTrace(this, this.constructor);
15+
this.name = this.constructor.name;
16+
this.message = message;
1717
};
1818

19-
require('util').inherits(InvalidArgumentException, Error);
19+
require('util').inherits(InvalidArgumentException, Error);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* This file is part of Swap.
2+
* This file is part of node-currency-swap.
33
*
4-
* (C) 2016 Tajawal
5-
* MIT LICENCE
4+
* (C) 2016 tajawal
5+
* Apache Software License v2.0
66
*
77
*/
88

@@ -13,9 +13,10 @@ var sprintf = require("sprintf-js").sprintf;
1313
* @param message
1414
*/
1515
var UnsupportedCurrencyPairException = module.exports = function (currencyPair, providerName) {
16-
Error.captureStackTrace(this, this.constructor);
17-
this.name = this.constructor.name;
18-
this.message = sprintf('The currency pair "%s" is not supported or "%s" changed the response format', currencyPair, providerName);
16+
Error.captureStackTrace(this, this.constructor);
17+
this.name = this.constructor.name;
18+
this.message = sprintf('The currency pair "%s" is not supported or "%s" changed the response format', currencyPair,
19+
providerName);
1920
};
2021

21-
require('util').inherits(UnsupportedCurrencyPairException, Error);
22+
require('util').inherits(UnsupportedCurrencyPairException, Error);

0 commit comments

Comments
 (0)