Commit 5e6ea17b authored by Mihkel Putrinš's avatar Mihkel Putrinš

fixed callback argument position

parent fc616d77
......@@ -28,24 +28,24 @@ Library for authenticated access to Entu database API
### javascript
#### var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url)
> - getEntity: function (callback, entity_id)
> - getEntity: function (entity_id, callback)
> - on success callback ({result: entity, time: 0.009})
> - else callback ({time: 0.009, error: "Entity with given ID is not found!"})
> - getChilds: function (callback, entity_id)
> - getChilds: function (entity_id, callback)
> - on success callback ({count: count, result: {}, time: 0.097})
> - else callback ({count: 0, result: {definition: {entities:[entities]}}, time: 0.094})
> - getReferrals: function (callback, entity_id)
> - getReferrals: function (entity_id, callback)
> - on success callback ({result: entity, time: 0.009})
> - else callback ({count: 0, result: {definition: {entities:[entities]}}, time: 0.095})
> - findEntity: function (callback, definition, query, limit)
> - findEntity: function (definition, query, limit, callback)
> - on success callback ({ count: count, result: [entitylist], time: 0.011})
> - else callback ({ count: 0, result: [], time: 0.086 })
> - createEntity: function (callback, parent_id, definition, properties)
> - createEntity: function (parent_id, definition, properties, callback)
> - on success callback ({result: { id: 685 }, time: 0.073})
> - else callback ({time: 0.01, error: message})
> - addProperties: function (callback, entity_id, definition, properties)
> - addProperties: function (entity_id, definition, properties, callback)
> - on success callback ({result: { id: '686' }, time: 0.024})
> - else callback ({time: 0.018, error: message})
> - addFile: function (callback, entity_id, property_definition, abspath)
> - addFile: function (entity_id, property_definition, abspath, callback)
> - on success callback ({time: 0.088})
> - else callback ({time: 0.018, error: message})
......@@ -33,7 +33,7 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
return querystring.stringify(entu_query)
}
var __submit_it = function __submit_it(callback, path, method, data) {
var __submit_it = function __submit_it(path, method, data, callback) {
var options = {
hostname: entu_url,
path: path,
......@@ -48,7 +48,7 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
}
var buffer = ''
var request = https.request(options)
request.on('response', function response_handler( response ) {
request.on('response', function response_handler(response) {
response.on('data', function chunk_sticher(chunk) {
buffer += chunk
})
......@@ -65,13 +65,13 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
}
return {
getEntity: function (callback, entity_id) {
getEntity: function (entity_id, callback) {
var data = __create_policy()
var path = API_VERSION + 'entity-' + entity_id + '?' + data
__submit_it(callback, path, 'GET')
__submit_it(path, 'GET', callback)
},
// definition = property's dataproperty name
findEntity: function (callback, definition, query, limit) {
findEntity: function (definition, query, limit, callback) {
var entu_query = {
'definition': definition,
'query': query,
......@@ -79,22 +79,22 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
}
var data = __create_policy(entu_query)
var path = API_VERSION + 'entity?' + data
__submit_it(callback, path, 'GET')
__submit_it(path, 'GET', callback)
},
// Return childs of entity
getChilds: function (callback, entity_id) {
getChilds: function (entity_id, callback) {
var data = __create_policy()
var path = API_VERSION + 'entity-' + entity_id + '/childs?' + data
__submit_it(callback, path, 'GET')
__submit_it(path, 'GET', callback)
},
// Return entity's referrals
getReferrals: function (callback, entity_id) {
getReferrals: function (entity_id, callback) {
var data = __create_policy()
var path = API_VERSION + 'entity-' + entity_id + '/referrals?' + data
__submit_it(callback, path, 'GET')
__submit_it(path, 'GET', callback)
},
// definition = property's dataproperty name
createEntity: function (callback, parent_id, definition, properties) {
createEntity: function (parent_id, definition, properties, callback) {
var entu_query = {}
entu_query.definition = definition
for (var key in properties) {
......@@ -102,22 +102,22 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
}
var data = __create_policy(entu_query)
var path = API_VERSION + 'entity-' + parent_id
__submit_it(callback, path, 'POST', data)
__submit_it(path, 'POST', data, callback)
},
// definition = property's dataproperty name
addProperties: function (callback, entity_id, definition, properties) {
addProperties: function (entity_id, definition, properties, callback) {
var entu_query = {}
for (var key in properties) {
entu_query[definition + '-' + key] = properties[key]
}
var data = __create_policy(entu_query)
var path = API_VERSION + 'entity-' + entity_id
__submit_it(callback, path, 'PUT', data)
__submit_it(path, 'PUT', data, callback)
},
// property_definition in form of entity_keyname + "-" + property_keyname
// as for entity with definition "person" and property with definition "photo"
// property_definition = "person-photo"
addFile: function (callback, entity_id, property_definition, abspath) {
addFile: function (entity_id, property_definition, abspath, callback) {
if (!fs.existsSync(abspath))
callback({'Error':'No such file','Path':abspath})
var entu_query = {
......@@ -128,7 +128,7 @@ var EntuLib = function EntuLib(entu_user_id, entu_user_key, entu_url) {
var data = __create_policy(entu_query)
var path = API_VERSION + 'file?' + data
file_contents = fs.readFileSync(abspath)
__submit_it(callback, path, 'POST', file_contents)
__submit_it(path, 'POST', file_contents, callback)
}
}
}
......
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