-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fe129fb
Showing
11 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
.coveralls.yml | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- 'iojs' | ||
- '0.10' | ||
- '0.12' | ||
before_install: | ||
- npm i -g gulp | ||
after_success: | ||
- gulp coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Javier Cejudo | ||
|
||
Permission 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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# oxr-to-linear-presets | ||
|
||
[![Build Status](https://travis-ci.org/javiercejudo/oxr-to-linear-presets.svg)](https://travis-ci.org/javiercejudo/oxr-to-linear-presets) | ||
[![Coverage Status](https://coveralls.io/repos/javiercejudo/oxr-to-linear-presets/badge.svg?branch=master)](https://coveralls.io/r/javiercejudo/oxr-to-linear-presets?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/javiercejudo/oxr-to-linear-presets/badges/gpa.svg)](https://codeclimate.com/github/javiercejudo/oxr-to-linear-presets) | ||
|
||
Transform [open exchange rates API response](https://openexchangerates.org/documentation#preview-api-response) to [linear presets](https://github.com/javiercejudo/linear-presets) format. | ||
|
||
## Install | ||
|
||
npm i oxr-to-linear-presets | ||
|
||
## Usage | ||
|
||
See [tested example](test/example.js). | ||
|
||
### Node.js | ||
|
||
```js | ||
var oxrTransform = require('oxr-to-linear-presets'); | ||
var oxr = require('open-exchange-rates'); | ||
|
||
oxr.set({ app_id: 'YOUR_APP_ID' }); | ||
|
||
oxr.latest(function() { | ||
console.log(oxrTransform(oxr.rates, oxr.base)); | ||
}); | ||
``` | ||
|
||
### jQuery | ||
|
||
```js | ||
// browserified or similar | ||
var oxrTransform = require('oxr-to-linear-presets'); | ||
|
||
$.ajax({ | ||
url: 'https://openexchangerates.org/api/latest.json?app_id=YOUR_APP_ID', | ||
dataType: 'jsonp', | ||
success: function(json) { | ||
console.log(oxrTransform(json.rates, json.base)); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"disclaimer": "Exchange rates are provided for informational purposes only, and do not constitute financial advice of any kind. Although every attempt is made to ensure quality, NO guarantees are given whatsoever of accuracy, validity, availability, or fitness for any purpose - please use at your own risk. All usage is subject to your acceptance of the Terms and Conditions of Service, available at: https://openexchangerates.org/terms/", | ||
"license": "Data sourced from various providers with public-facing APIs; copyright may apply; resale is prohibited; no warranties given of any kind. Bitcoin data provided by http://coindesk.com. All usage is subject to your acceptance of the License Agreement available at: https://openexchangerates.org/license/", | ||
"timestamp": 1445605209, | ||
"base": "USD", | ||
"rates": { | ||
"AUD": 1.379632, | ||
"EUR": 0.90489, | ||
"USD": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"base": "USD", | ||
"conversions": { | ||
"AUD": [[0, 1], [0, 1.379632]], | ||
"EUR": [[0, 1], [0, 0.90489]], | ||
"USD": [[0, 1], [0, 1]] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var gulp = require('gulp'); | ||
var mocha = require('gulp-mocha'); | ||
var istanbul = require('gulp-istanbul'); | ||
var rimraf = require('rimraf'); | ||
var coveralls = require('gulp-coveralls'); | ||
|
||
gulp.task('clean', function (cb) { | ||
rimraf('./coverage', cb); | ||
}); | ||
|
||
gulp.task('instrument', function () { | ||
return gulp.src(['src/*.js']) | ||
.pipe(istanbul()) | ||
.pipe(istanbul.hookRequire()); | ||
}); | ||
|
||
gulp.task('test', ['clean', 'instrument'], function () { | ||
return gulp.src(['test/*.js']) | ||
.pipe(mocha()) | ||
.pipe(istanbul.writeReports()); | ||
}); | ||
|
||
gulp.task('coveralls', function () { | ||
gulp.src('coverage/lcov.info') | ||
.pipe(coveralls()); | ||
}); | ||
|
||
gulp.task('default', ['test']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "oxr-to-linear-presets", | ||
"version": "0.0.0", | ||
"description": "Transform open exchange rates API response to linear presets format.", | ||
"main": "src/oxr-to-linear-presets.js", | ||
"scripts": { | ||
"test": "gulp test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/javiercejudo/oxr-to-linear-presets" | ||
}, | ||
"keywords": [ | ||
"all", | ||
"array", | ||
"every" | ||
], | ||
"author": "Javier Cejudo", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/javiercejudo/oxr-to-linear-presets/issues" | ||
}, | ||
"homepage": "https://github.com/javiercejudo/oxr-to-linear-presets", | ||
"devDependencies": { | ||
"arbitrary-precision": "^1.1.1", | ||
"floating-adapter": "^1.2.0", | ||
"gulp": "3.9.0", | ||
"gulp-coveralls": "0.1.4", | ||
"gulp-istanbul": "0.10.2", | ||
"gulp-mocha": "2.1.3", | ||
"linear-converter": "^7.0.2", | ||
"linear-preset-any-to-any": "^3.0.2", | ||
"rimraf": "2.4.3", | ||
"should": "7.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* jshint node:true */ | ||
|
||
'use strict'; | ||
|
||
module.exports = function transform(rates, base) { | ||
return { | ||
base: base, | ||
conversions: singlesToPreset(rates) | ||
}; | ||
}; | ||
|
||
function singlesToPreset(singles) { | ||
return Object.keys(singles).reduce(function(result, key) { | ||
result[key] = [[0, 1], [0, singles[key]]]; | ||
|
||
return result; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*jshint node:true, mocha:true */ | ||
|
||
'use strict'; | ||
|
||
require('should'); | ||
|
||
var response = require('../fixtures/response.json'); | ||
var oxrTransform = require('../src/oxr-to-linear-presets'); | ||
|
||
var Decimal = require('arbitrary-precision')(require('floating-adapter')); | ||
var anyToAny = require('linear-preset-any-to-any')(Decimal); | ||
var convert = require('linear-converter')(Decimal).convert; | ||
|
||
describe('oxr-to-linear-presets example', function() { | ||
it('should allow conversions from any to any', function() { | ||
var presets = oxrTransform(response.rates, response.base); | ||
var EUR_AUD = anyToAny(presets.conversions, 'EUR', 'AUD'); | ||
|
||
convert(EUR_AUD, 1).valueOf().toFixed(2).should.be.exactly('1.52'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*jshint node:true, mocha:true */ | ||
|
||
'use strict'; | ||
|
||
require('should'); | ||
|
||
var response = require('../fixtures/response.json'); | ||
var transformed = require('../fixtures/transformed.json'); | ||
var oxrTransform = require('../src/oxr-to-linear-presets'); | ||
|
||
describe('oxr-to-linear-presets', function() { | ||
it('should transform open exchange rates API response to linear presets format', function() { | ||
oxrTransform(response.rates, response.base).should.eql(transformed); | ||
}); | ||
}); |