Learn the real value of your data
@doubleface on twitter and github
There is an app for that : my accounts
With login and passwords, gets a lot of your data back
Every data has its own connector
The connector to your data is missing ?
You can do something!
the My Accounts app handles storage / sync
module.exports = baseKonnector.createNew({
name: 'Trainline',
vendorLink: 'www.trainline.fr',
fields: {
login: 'email',
password: 'password',
folderPath: 'folder',
},
models: [Bill]
}
Your "target" offers you an API ? your really lucky!
Using "request-promise" "cheerio" npm modules
request({ method: 'GET', jar: true, url: "https://login.uber.com/login"})
.then((res, body) => {
const $ = cheerio.load(body)
const token = $('input[name=_csrf_token]').val()
log.info('Logging in')
return request({method: 'POST', jar: true,
url: "https://login.uber.com/login",
form: {
email: requiredFields.login,
password: requiredFields.password,
_csrf_token: token
}})
.then((result, body) => {
log.info('Login succeeded')
})
You can create your own cozy application
A cozy application is just a simple static javascript application using the cozy client sdk and with a special package.json file in a github repository
Example :
<!DOCTYPE html>
<html lang="en">
<head>
<title>TODO</title>
<script src="cozy-client.js"></script>
<script src="app.js"></script>
</head>
<body>
<button id="create_special">
Create Task for last bill
</button>
<ul id="todo" class="list-group"></ul>
</body>
</html>
{
"name": "todo",
"version": "0.0.1",
"description": "Next tasks to do in your cozy",
"cozy-type": "static",
"cozy-displayName": "todo",
"cozy-permissions": {
"TodoDemo": {
"description": "Todo demo items"
},
"File": {
"description": "Find bills in your file"
}
}
}
function displayTodos() {
cozy.defineIndex("tododemo", ["completed"])
.then((index) => cozy.query(index, {
selector: {"completed": false},
}))
.then(list => {
todo.innerHTML = list.map(item => {
return `${item.description} `;
}).join("");
});
}
function getLastBill() {
cozy.defineIndex('file', ["class", "lastModified"])
.then((index) => cozy.query(index, {
selector: {"class": "document"},
sort: "lastModified",
descending true
limit: 1,
}))
.then(list => list[0])
.then(file => {
if (file === undefined) {
window.alert("no document found");
}
}
getLastBill()
.then( (file) => {
let url = `/apps/files/files/${file._id}/attach/${file.name}`;
cozy.create("tododemo", {
description: `Pay bill `,
})
})
.then(displayTodos);
Connector : Make a PR to the konnectors repository.
Talk with us about your new connector on the forum : https://forum.cozy.io
Application : Create your repository, Install it in cozy.