Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added support for several things #3

Closed
wants to merge 17 commits into
from
View
@@ -17,33 +17,124 @@ Parse.prototype = {
parseRequest.call(this, 'POST', '/1/classes/' + className, object, callback);
},
- // get objects from class store
+ // add files
+ insertFile: function(fileName, data, contentType, callback){
+ parseRequest.call(this, 'POST', '/1/files/' + fileName, data, callback, contentType);
+ },
+
+ // get an object from the class store
find: function (className, query, callback) {
+ if (typeof query === 'string') {
+ parseRequest.call(this, 'GET', '/1/' + className + '/' + query, null, callback);
+ } else {
+ parseRequest.call(this, 'GET', '/1/' + className, { where: JSON.stringify(query) }, callback);
+ }
+ },
+
+ // get a collection of objects
+ findMany: function (className, query, callback) {
if (typeof query === 'string') {
parseRequest.call(this, 'GET', '/1/classes/' + className + '/' + query, null, callback);
} else {
parseRequest.call(this, 'GET', '/1/classes/' + className, { where: JSON.stringify(query) }, 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
+ getUser: function (userName, passWord, callback) {
+ parseRequest.call(this, 'GET', '/1/login/?username=' + userName + '&password=' + passWord, null, callback);
+ },
+
+ // get an object belonging to a certain User
+ getFileByUser: function(userId, className, callback) {
+ queryString = 'where={"user":' + '"' + userId + '"' + '}'
+ encodedString = encodeURIComponent(queryString);
+ parseRequest.call(this, 'GET', '/1/classes/' + className + '?' + encodedString, null, callback)
+ },
+
+ // insert an object into Parse
+ insertCustom: function (className, object, callback) {
+ parseRequest.call(this, 'POST', '/1/' + className, object, callback);
+ },
+
// update an object in the class store
- update: function (className, objectId, object, callback) {
+ update: function (className, objectId, object, callback) {
parseRequest.call(this, 'PUT', '/1/classes/' + className + '/' + objectId, object, callback);
},
-
+
+ // update a User object's email address
+ updateUserEmail: function(objectId, data, callback) {
+ data = { email: data }
+ parseRequest.call(this, 'PUT', '/1/users/' + objectId, data, callback)
+ },
+
+ // update a User object's username*
+ updateUserName: function(objectId, data, callback) {
+ data = { username: data }
+ parseRequest.call(this, 'PUT', '/1/users/' + objectId, data, callback)
+ },
+
+ // reset a User object's password
+ passwordReset: function (data, callback) {
+ data = { email: data }
+ parseRequest.call(this, 'POST', '/1/requestPasswordReset/', data, callback)
+ },
+
// remove an object from the class store
- 'delete': function (className, objectId, callback) {
+ delete: function (className, objectId, callback) {
parseRequest.call(this, 'DELETE', '/1/classes/' + className + '/' + objectId, null, callback);
+ },
+
+ // upload installation data
+ insertInstallationData: function (deviceType, deviceToken, callback) {
+ if (deviceType === 'ios'){
+ data = { deviceType: deviceType, deviceToken: deviceToken }
+ }
+ else {
+ data = { deviceType: deviceType, installationId: deviceToken }
+ }
+ parseRequest.call(this, 'POST', '/1/installations/', data, callback);
+ },
+
+ insertInstallationDataWithTimeZone: function (deviceType, deviceToken, timeZone, callback) {
+ if (deviceType === 'ios'){
+ data = { deviceType: deviceType, deviceToken: deviceToken, timeZone: timeZone }
+ }
+ else {
+ data = { deviceType: deviceType, installationId: deviceToken, timeZone: timeZone }
+ }
+ parseRequest.call(this, 'POST', '/1/installations/', data, callback);
+ },
+
+ insertInstallationDataWithChannels: function (deviceType, deviceToken, channels, callback) {
+ if (deviceType === 'ios'){
+ data = { deviceType: deviceType, deviceToken: deviceToken, channels: channels }
+ }
+ else {
+ data = { deviceType: deviceType, installationId: deviceToken, channels: channels }
+ }
+ parseRequest.call(this, 'POST', '/1/installations/', data, callback);
+ },
+
+ insertInstallationDataWithTimeZoneAndChannels: function (deviceType, deviceToken, timeZone, channels, callback) {
+ if (deviceType === 'ios'){
+ data = { deviceType: deviceType, deviceToken: deviceToken, timeZone: timeZone, channels: channels }
+ }
+ else {
+ data = { deviceType: deviceType, installationId: deviceToken, timeZone: timeZone, channels: channels }
+ }
+ parseRequest.call(this, 'POST', '/1/installations/', data, callback);
}
};
// Parse.com https api request
-function parseRequest(method, path, data, callback) {
+function parseRequest(method, path, data, callback, contentType) {
var auth = 'Basic ' + new Buffer(this._application_id + ':' + this._master_key).toString('base64');
var headers = {
Authorization: auth,
Connection: 'Keep-alive'
};
+
var body = null;
switch (method) {
@@ -54,8 +145,14 @@ function parseRequest(method, path, data, callback) {
break;
case 'POST':
case 'PUT':
- body = JSON.stringify(data);
+ if(contentType){
+ body = data;
+ headers['Content-type'] = contentType;
+ console.log('Sending data type: ' + contentType + ' of length: ' + body.length);
+ }else{
headers['Content-type'] = 'application/json';
+ body = JSON.stringify(data);
+ }
headers['Content-length'] = body.length;
break;
case 'DELETE':
@@ -109,10 +206,15 @@ function parseRequest(method, path, data, callback) {
});
});
+ if(contentType)
+ {
+ body && req.write(body,'binary');
+ }else{
body && req.write(body);
+ }
req.end();
req.on('error', function (err) {
callback && callback(err);
});
-}
+}
View
@@ -0,0 +1,128 @@
+info it worked if it ends with ok
+verbose cli [ 'node', '/home/ghilly/.nvm/v0.6.9/bin/npm', 'publish' ]
+info using npm@1.1.0-3
+info using node@v0.6.9
+verbose config file /home/ghilly/.npmrc
+verbose config file /home/ghilly/.nvm/v0.6.9/etc/npmrc
+verbose config file /home/ghilly/.nvm/v0.6.9/lib/node_modules/npm/npmrc
+verbose publish [ '.' ]
+verbose caching /home/ghilly/Documents/node/node-parse-api/package.json
+verbose loadDefaults node-parse-api@0.1.0
+info prepublish node-parse-api@0.1.0
+verbose cache add [ '.', null ]
+silly cache add: name, spec, args [ undefined, '.', [ '.', null ] ]
+verbose parsed url { pathname: '.', path: '.', href: '.' }
+verbose caching package.json
+verbose loadDefaults node-parse-api@0.1.0
+verbose pack /home/ghilly/Documents/node/node-parse-api
+verbose pack /home/ghilly/Documents/node/node-parse-api /tmp/npm-1341024639569/1341024639568-0.9406838221475482/tmp.tgz
+silly makeList /home/ghilly/Documents/node/node-parse-api
+silly dir, dirLen [ '/home/ghilly/Documents/node/node-parse-api', 43 ]
+verbose tarball /tmp/npm-1341024639569/1341024639568-0.9406838221475482/tmp.tgz
+verbose parent /home/ghilly/Documents/node/node-parse-api
+verbose mkdir (expected) error ENOENT, no such file or directory '/tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm'
+verbose mkdir done: /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm 755
+verbose unpack_ uid, gid [ undefined, undefined ]
+verbose unpackTarget /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package
+silly gunzTarPerm modes [ '755', '644' ]
+silly afterUntar undefined
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/package.json
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/makefile
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/readme.md
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/index.js
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/test
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/test/Parse.test.js
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/lib
+silly asyncMap in gTP /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api/lib/Parse.js
+verbose gunzed /tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api
+verbose rm'ed /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package
+verbose renamed [ '/tmp/npm-1341024639569/1341024639568-0.9406838221475482/___package.npm/node-parse-api',
+verbose renamed '/tmp/npm-1341024639569/1341024639568-0.9406838221475482/package' ]
+verbose caching /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package/package.json
+verbose loadDefaults node-parse-api@0.1.0
+verbose tarball contents [ 'tmp.tgz', 'package' ]
+verbose from cache /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package/package.json
+verbose pack /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package
+verbose pack /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package /home/ghilly/.npm/node-parse-api/0.1.0/package.tgz
+silly makeList /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package
+silly dir, dirLen [ '/tmp/npm-1341024639569/1341024639568-0.9406838221475482/package',
+silly dir, dirLen 64 ]
+verbose tarball /home/ghilly/.npm/node-parse-api/0.1.0/package.tgz
+verbose parent /tmp/npm-1341024639569/1341024639568-0.9406838221475482/package
+verbose mkdir (expected) error ENOENT, no such file or directory '/home/ghilly/.npm/node-parse-api/0.1.0/___package.npm'
+verbose mkdir done: /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm 755
+verbose unpack_ uid, gid [ undefined, undefined ]
+verbose unpackTarget /home/ghilly/.npm/node-parse-api/0.1.0/package
+silly gunzTarPerm modes [ '755', '644' ]
+silly afterUntar undefined
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/package.json
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/makefile
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/readme.md
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/index.js
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/test
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/test/Parse.test.js
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/lib
+silly asyncMap in gTP /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package/lib/Parse.js
+verbose gunzed /home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package
+verbose rm'ed /home/ghilly/.npm/node-parse-api/0.1.0/package
+verbose renamed [ '/home/ghilly/.npm/node-parse-api/0.1.0/___package.npm/package',
+verbose renamed '/home/ghilly/.npm/node-parse-api/0.1.0/package' ]
+verbose caching /home/ghilly/.npm/node-parse-api/0.1.0/package/package.json
+verbose loadDefaults node-parse-api@0.1.0
+silly updated sha bytes 2994
+info shasum 6d9fee3bc4cf199ab732ae29e0d414e16f91f103
+info shasum /home/ghilly/.npm/node-parse-api/0.1.0/package.tgz
+verbose from cache /home/ghilly/.npm/node-parse-api/0.1.0/package/package.json
+verbose chmod /home/ghilly/.npm/node-parse-api/0.1.0/package.tgz 644
+verbose chown [ '/home/ghilly/.npm/node-parse-api/0.1.0/package.tgz',
+verbose chown 1000,
+verbose chown 1000 ]
+silly publish { name: 'node-parse-api',
+silly publish description: 'API for accessing Parse.com applications',
+silly publish version: '0.1.0',
+silly publish author: { name: 'Chris Johnson', email: 'tenorviol@yahoo.com' },
+silly publish repository:
+silly publish { type: 'git',
+silly publish url: 'git://github.com/leveton/node-parse-api.git' },
+silly publish main: 'index',
+silly publish engines: { node: '>= 0.4.0' },
+silly publish _npmUser: { name: 'leveton', email: 'mleveton@prepcloud.com' },
+silly publish _id: 'node-parse-api@0.1.0',
+silly publish dependencies: {},
+silly publish devDependencies: {},
+silly publish optionalDependencies: {},
+silly publish _engineSupported: true,
+silly publish _npmVersion: '1.1.0-3',
+silly publish _nodeVersion: 'v0.6.9',
+silly publish _defaultsLoaded: true,
+silly publish dist:
+silly publish { shasum: '6d9fee3bc4cf199ab732ae29e0d414e16f91f103',
+silly publish tarball: 'http://registry.npmjs.org/node-parse-api/-/node-parse-api-0.1.0.tgz' } }
+verbose raw, before any munging node-parse-api
+verbose url resolving [ 'https://registry.npmjs.org/', './node-parse-api' ]
+verbose url resolved https://registry.npmjs.org/node-parse-api
+http PUT https://registry.npmjs.org/node-parse-api
+http 409 https://registry.npmjs.org/node-parse-api
+verbose raw, before any munging node-parse-api
+verbose url resolving [ 'https://registry.npmjs.org/', './node-parse-api' ]
+verbose url resolved https://registry.npmjs.org/node-parse-api
+http GET https://registry.npmjs.org/node-parse-api
+http 200 https://registry.npmjs.org/node-parse-api
+info Already published node-parse-api@0.1.0
+verbose uploading bin dists []
+ERR! publish fail Cannot publish over existing version.
+ERR! publish fail Bump the 'version' field, set the --force flag, or
+ERR! publish fail npm unpublish 'node-parse-api@0.1.0'
+ERR! publish fail and try again
+ERR!
+ERR! System Linux 2.6.38-15-generic
+ERR! command "node" "/home/ghilly/.nvm/v0.6.9/bin/npm" "publish"
+ERR! cwd /home/ghilly/Documents/node/node-parse-api
+ERR! node -v v0.6.9
+ERR! npm -v 1.1.0-3
+ERR! code EPUBLISHCONFLICT
+ERR! message publish fail
+ERR! errno {}
+verbose exit [ 1, true ]
View
@@ -1,9 +1,9 @@
{
- "name": "parse-api",
+ "name": "node-parse-api",
"description": "API for accessing Parse.com applications",
- "version": "0.1.0",
- "author": "Chris Johnson <tenorviol@yahoo.com>",
- "repository": "git://github.com/tenorviol/node-parse-api",
+ "version": "0.1.5",
+ "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" }
}
Oops, something went wrong.