node-parse-api
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -16,3 +16,3 @@ var qs = require('querystring'); | ||
_api_port: 443, | ||
// add object to class store | ||
@@ -22,3 +22,3 @@ insert: function (className, object, callback) { | ||
}, | ||
// add files | ||
@@ -28,3 +28,3 @@ insertFile: function(fileName, data, contentType, callback){ | ||
}, | ||
// get an object from the class store | ||
@@ -56,3 +56,3 @@ find: function (className, query, callback) { | ||
}, | ||
// do a batch of requests at once | ||
@@ -62,3 +62,3 @@ batch: function (requests,callback) { | ||
}, | ||
// get a user from the Parse's special User class. See https://parse.com/questions/why-does-querying-for-a-user-create-a-second-user-class | ||
@@ -68,3 +68,3 @@ getUser: function (userName, passWord, callback) { | ||
}, | ||
// get an object belonging to a certain User | ||
@@ -109,3 +109,3 @@ getFileByUser: function(userId, className, callback) { | ||
}, | ||
// upload installation data | ||
@@ -151,3 +151,24 @@ insertInstallationData: function (deviceType, deviceToken, callback) { | ||
}, | ||
updateInstallationDataChannels: function(objectId, channels, callback) { | ||
parseRequest.call(this, 'PUT', '/1/installations/' + objectId, { | ||
channels: channels | ||
}, callback); | ||
}, | ||
getInstallationDataForDeviceToken: function(deviceToken, callback) { | ||
parseRequest.call(this, 'GET', '/1/installations?where={"deviceToken":"'+deviceToken+'"}', null, callback); | ||
}, | ||
insertOrUpdateInstallationDataWithChannels: function(deviceType, deviceToken, channels, callback) { | ||
var that = this; | ||
this.getInstallationDataForDeviceToken(deviceToken, function(err, results) { | ||
if (!err && results.results.length) { | ||
that.updateInstallationDataChannels(results.results[0].objectId, channels); | ||
return; | ||
} | ||
that.insertInstallationDataWithChannels(deviceType, deviceToken, channels, callback); | ||
}); | ||
}, | ||
countObjects: function (className, query, callback) { | ||
@@ -163,3 +184,3 @@ if (typeof(query) === "function") { | ||
}, | ||
addRelation: function( relationName, className1, objectId1, className2, objectId2, callback) { | ||
@@ -170,3 +191,3 @@ data = {} | ||
}, | ||
removeRelation: function( relationName, className1, objectId1, className2, objectId2, callback) { | ||
@@ -209,2 +230,10 @@ data = {} | ||
parseRequest.call(this, 'POST', '/1/push/', data, callback); | ||
}, | ||
deleteAll: function(modelName, callback){ | ||
var that = this; | ||
this.findMany(modelName, '', function(err, response){ | ||
var requests = toDeleteOps(modelName, response.results); | ||
that.batch(requests, callback); | ||
}); | ||
} | ||
@@ -220,9 +249,9 @@ }; | ||
}; | ||
var body = null; | ||
switch (method) { | ||
case 'GET': | ||
if (data) { | ||
path += '?' + qs.stringify(data); | ||
path += (path.indexOf("?") == -1 ? '?' : '&') + qs.stringify(data); | ||
} | ||
@@ -244,3 +273,3 @@ break; | ||
} | ||
var options = { | ||
@@ -253,3 +282,3 @@ host: this._api_host, | ||
}; | ||
var req = this._api_protocol.request(options, function (res) { | ||
@@ -259,3 +288,3 @@ if (!callback) { | ||
} | ||
if (res.statusCode < 200 || res.statusCode >= 300) { | ||
@@ -269,3 +298,3 @@ var err = new Error('HTTP error ' + res.statusCode); | ||
} | ||
// if ((!err) && (res.statusCode === 200 || res.statusCode === 201)) { | ||
@@ -277,7 +306,7 @@ // res.success = res.statusCode; | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
json += chunk; | ||
}); | ||
res.on('end', function () { | ||
@@ -292,3 +321,3 @@ var err = null; | ||
}); | ||
res.on('close', function (err) { | ||
@@ -298,3 +327,3 @@ callback(err); | ||
}); | ||
body && req.write(body, contentType ? 'binary' : 'utf8'); | ||
@@ -307,1 +336,11 @@ req.end(); | ||
} | ||
function toDeleteOps(className, objects){ | ||
return objects.map(function(object){ | ||
return { | ||
method: 'DELETE', | ||
path: '/1/classes/' + className + '/' + object.objectId, | ||
body: {} | ||
} | ||
}); | ||
} |
{ | ||
"name": "node-parse-api", | ||
"description": "A Parse.com REST API client for Node.js", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"author": "Chris Johnson <tenorviol@yahoo.com>, Michael Leveton <mleveton@prepcloud.com>, Seth Gholson", | ||
"repository": "git://github.com/leveton/node-parse-api", | ||
"main": "index", | ||
"engines": { "node": ">= 0.4.0" } | ||
"scripts":{ | ||
"test":"nodeunit" | ||
}, | ||
"engines": { | ||
"node": ">= 0.4.0" | ||
}, | ||
"devDependencies": { | ||
"nodeunit": "~0.9.0" | ||
} | ||
} |
@@ -15,6 +15,6 @@ Node Parse API | ||
var Parse = require('node-parse-api').Parse; | ||
var APP_ID = ...; | ||
var MASTER_KEY = ...; | ||
var app = new Parse(APP_ID, MASTER_KEY); | ||
@@ -29,3 +29,3 @@ | ||
### insert a User | ||
### insert a User | ||
@@ -36,3 +36,3 @@ app.insertCustom('users', { foo: 'bar' }, function (err, response) { | ||
### insert a User with GeoPoints | ||
### insert a User with GeoPoints | ||
@@ -91,5 +91,11 @@ app.insertCustom('users', { foo: 'bar', location: {__type: 'GeoPoint', latitude: <int>, longitude: <int>} }, function (err, response) { | ||
### deleteAll | ||
app.deleteAll('Foo', function (err) { | ||
// nothing to see here | ||
}); | ||
### reset a password | ||
//email is built into Parse's special User class | ||
//email is built into Parse's special User class | ||
app.passwordReset(email, function(err, response){ | ||
@@ -101,3 +107,3 @@ console.log(response); | ||
//email is built into Parse's special User class | ||
//email is built into Parse's special User class | ||
app.updateUserEmail(objectId, email, function(err, response){ | ||
@@ -158,3 +164,3 @@ if (err) { | ||
### create a role for a particular user | ||
//create a data object that links the user object's objectId to the role | ||
@@ -198,3 +204,3 @@ | ||
//pass the role object's objectId | ||
app.getRole("<objectId>", function(err, resp){ | ||
app.getRole("<objectId>", function(err, resp){ | ||
console.log(resp); | ||
@@ -216,6 +222,6 @@ }); | ||
] | ||
} | ||
} | ||
}; | ||
app.updateRole("<objectId>", data, function(err, resp){ | ||
app.updateRole("<objectId>", data, function(err, resp){ | ||
console.log(resp); | ||
@@ -225,4 +231,4 @@ }); | ||
### delete a role | ||
//pass the objectId of the role | ||
//pass the objectId of the role | ||
app.deleteRole("<objectId>", function(err, resp){}); | ||
@@ -237,3 +243,3 @@ | ||
var params = { | ||
where: { name: "Administrator" } | ||
where: { name: "Administrator" } | ||
}; | ||
@@ -246,3 +252,3 @@ | ||
### send a push notification | ||
//The data param has to follow the data structure as described in the [Parse REST API](https://www.parse.com/docs/rest#push) | ||
@@ -260,7 +266,7 @@ var notification = { | ||
### note on sending dates | ||
//when inserting a data, you must use the Parse date object structure, i.e.: | ||
{ | ||
"__type": "Date", | ||
"__type": "Date", | ||
"iso": new Date("<year>", "<month>", "<day>").toJSON() | ||
} |
@@ -33,4 +33,4 @@ var Parse = require('../index').Parse; | ||
}); | ||
}; | ||
@@ -82,3 +82,3 @@ | ||
object.foo = num; | ||
parse.update(className, stub.objectId, object, function (err, response) { | ||
@@ -119,1 +119,12 @@ err && console.log(err); | ||
}; | ||
exports['delete all'] = function(assert){ | ||
parse.insert(className2,object2, function(err,response){ | ||
parse.deleteAll(className2, function(){ | ||
parse.findMany(className2, '', function(err, response){ | ||
assert.equal(0, response.results.length); | ||
assert.done(); | ||
}); | ||
}); | ||
}); | ||
} |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
21924
382
1
261
1