Commit 114045eb authored by Aurel's avatar Aurel

split jio code & remove clearroad parts

parent 384d5dea
......@@ -198,7 +198,7 @@ module.exports = function (grunt) {
'src/jio.date/*.js',
'src/jio.js',
'src/jio-nodejs.js',
'src/jio.storage/replicatestorage.js',
'src/jio.storage/uuidstorage.js',
......
This diff is collapsed.
{
"name": "clearroad",
"version": "1.0.0",
"description": "ClearRoad Lib based on JIO",
"main": "clearroad.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "lab.nexedi.com/nexedi/jio"
},
"keywords": [
"clearroad",
"jio"
],
"author": "Aurélien Calonne",
"license": "ISC"
}
{
"//1": "describes your app and its dependencies",
"//2": "https://docs.npmjs.com/files/package.json",
"//3": "updating this file will download and update your packages",
"name": "clearroad-nodejs",
"version": "0.0.1",
"description": "ClearRoad API on Node.js",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.14.1",
"stream-buffer": "latest",
"xhr2": "latest",
"rsvp": "git+https://lab.nexedi.com/nexedi/rsvp.js.git",
"uritemplate": "latest",
"moment": "file:lib/moment",
"navigator": "latest",
"rusha": "latest",
"form-data": "latest",
"atob": "latest",
"html5": "file:lib/html5",
"node-localstorage": "latest",
"btoa": "latest",
"xhr2": "latest",
"stream-buffers": "latest",
"clearroad": "file:lib/clearroad",
"jio": "file:lib/jio",
"urijs": "latest"
},
"engines": {
"node": "6.9.x"
},
"repository": {
"url": ""
},
"license": "",
"keywords": [
"node",
"jio",
"clearroad"
]
}
// server.js
// where your node app starts
"use strict"
global.URI = require("urijs");
global.RSVP = require('rsvp');
global.UriTemplate = require("uritemplate");
global.moment = require('moment');
global.navigator = require('navigator');
global.Rusha = require('rusha');
global.FormData = require('form-data');
global.atob = require('atob');
global.FileReader = require("html5").FileReader;
global.Blob = require("html5").Blob;
global.localStorage = require('node-localstorage');
global.btoa = require('btoa');
global.XMLHttpRequest = require('xhr2');
global.StreamBuffers = require('stream-buffers');
global.window = global;
global.sessionStorage = {};
var jIO = require('jio');
var clearroad = require("clearroad");
var i = 0;
var cr = new clearroad.ClearRoadBillingPeriodRegistration("testam", "testam");
console.log("init");
cr.post({
"reference" : "Q421",
"start_date" : "2017-02-01T00:00:00Z",
"stop_date" : "2017-03-01T00:00:00Z"
}).push(function (){
console.log("start sync...");
return cr.sync();
}).push(function (){
console.info("Sync done");
}).push(function() {
cr = new clearroad.ClearRoadBillingPeriodRegistrationReport("testam", "testam", 100);
return cr.sync();
}).push(function (){
console.log("sync done && loading result...")
return cr.allDocs()
}).push(function (result) {
console.log("browsing results : "+result.data.total_rows);
for (i = 0; i < result.data.total_rows; i += 1) {
console.log("Ref : "+result.data.rows[i].value.reference+", state : "+result.data.rows[i].value.state+", comment"+result.data.rows[i].value.comment);
}
console.log("Finished");
}).push(undefined, function (error) {
throw error;
});
// init project
var express = require('express');
var app = express();
// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (request, response) {
response.sendFile(__dirname + '/views/index.html');
});
// listen for requests :)
var listener = app.listen(3000, function () {
console.log('Your app is listening on port ' + listener.address().port);
});
This diff is collapsed.
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator, FormData, StreamBuffers */
FileReader, ArrayBuffer, Uint8Array, navigator */
(function (window, RSVP, Blob, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator) {
"use strict";
......@@ -47,7 +47,7 @@
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function (resolve, reject, notify) {
var k, buffer = new StreamBuffers.WritableStreamBuffer();
var k;
xhr.open(param.type || "GET", param.url, true);
xhr.responseType = param.dataType || "";
if (typeof param.headers === 'object' && param.headers !== null) {
......@@ -57,7 +57,6 @@
}
}
}
xhr.setRequestHeader("Accept", "*/*");
xhr.addEventListener("load", function (e) {
if (e.target.status >= 400) {
return reject(e);
......@@ -76,14 +75,7 @@
if (typeof param.beforeSend === 'function') {
param.beforeSend(xhr);
}
if (param.data instanceof FormData) {
xhr.setRequestHeader("Content-Type",
"multipart\/form-data; boundary=" + param.data.getBoundary());
param.data.pipe(buffer);
xhr.send(buffer.getContents());
} else {
xhr.send(param.data);
}
xhr.send(param.data);
}, function () {
xhr.abort();
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment