Skip to content

Instantly share code, notes, and snippets.

@cyberatz
Created March 5, 2018 12:35
Show Gist options
  • Save cyberatz/3a622d3a90ec7ff0b54900f305db1ecd to your computer and use it in GitHub Desktop.
Save cyberatz/3a622d3a90ec7ff0b54900f305db1ecd to your computer and use it in GitHub Desktop.
login
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com
get key
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Authorization: Password pppppwwwwdddd" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/account/user%40exmaple.com/own-history-keys
get index
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/history/xxx-xxx-xxx
get items
curl -H "Host: cloud.culturedcode.com" -H "Content-Type: application/json; charset=UTF-8" -H "Proxy-Connection: keep-alive" -H "Accept: */*" -H "User-Agent: ThingsMac/20803501mas (x86_64; OS X 10.11.3; en_US)" -H "Accept-Language: en-us" --compressed https://cloud.culturedcode.com/version/1/history/xxx-xxx-xxx/items?start-index=0
Create item (from: simonbs/thingsapp):
var uuid4 = require('uuid/v4')
var moment = require('moment')
var request = require('request')
function Things(accountId, startIndex) {
this.accountId = accountId
this.startIndex = startIndex
}
Things.prototype.createTodo = function(todo, callback) {
var things = this
this.getCurrentIndex(this.startIndex, function(err, idx) {
if (err) { return callback(err) }
things.constructTodoItem(todo, function(err, todoItem) {
var url = 'https://cloud.culturedcode.com/version/1/history/' + things.accountId + '/items'
if (err) { return callback(err) }
request.post({
url: url,
json: {
'current-item-index': idx,
'items': [ todoItem ],
'schema': 1
},
headers: {
'User-Agent': 'ThingsMac/20808500mas (x86_64; OS X 10.12.2; en_DK)',
'Content-Type': 'application/json; charset=UTF-8',
'Content-Encoding': 'UTF-8'
}
},
function(err, httpResponse, body) {
callback(err)
})
})
})
}
Things.prototype.constructTodoItem = function(todo, callback) {
title = todo['title'] || 'New todo'
duedate = todo['duedate'] || null
note = todo['note'] || null
destination = todo['where'] || 'inbox'
uid = uuid4().toUpperCase()
now = Date.now() / 1000
if (destination == 'today') {
st = 2
} else if (destination == 'inbox') {
st = 0
} else {
return callback('Unsupported destination \'' + destination + '\'.')
}
if (st == 2) {
sr = moment(moment(new Date()).format('YYYY-MM-DD')).unix()
} else {
sr = null
}
if (note != null) {
note = '<note xml:space=\"preserve\">' + note + '</note>'
}
item = {}
item[uid] = {
"t": 0,
"e": "Task2",
"p": {
"acrd": null,
"ar": [],
"cd": now,
"dd": duedate,
"dl": [],
"do": 0,
"icc": 0,
"icp": false,
"icsd": null,
"ix": 0,
"md": now,
"nt": note,
"pr": [],
"rr": null,
"rt": [],
"sp": null,
"sr": sr,
"ss": 0,
"st": st,
"tg": [],
"ti": 0,
"tp": 0,
"tr": false,
"tt": title
}
}
callback(null, item)
}
Things.prototype.getCurrentIndex = function(startIndex, callback) {
url = 'https://thingscloud.appspot.com/version/1/history/'
+ this.accountId + '/items?start-index=' + startIndex
request.get({
url: url,
},
function(err, httpResponse, body) {
if (err) { return callback(err) }
var json = JSON.parse(body)
callback(null, json['current-item-index'])
})
}
module.exports = Things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment