Skip to content

Commit

Permalink
Unify to space indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Poitrey committed Mar 29, 2012
1 parent 7d30fce commit b34c09a
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions lib/c2dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,59 @@ var querystring = require('querystring');
var emitter = require('events').EventEmitter;

function C2DM(config) {
if (config) {
if ('user' in config)
this.user = config.user;
if ('password' in config)
this.password = config.password;
this.source = 'source' in config ? config.source : 'node-c2dm-client';
this.token = 'token' in config ? config.token : null;
this.keepAlive = 'keepAlive' in config ? config.keepAlive : false;
} else {
throw Error('No config given.');
}
this.loginOptions = {
host: 'www.google.com',
port: 443,
path: '/accounts/ClientLogin',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
};
this.c2dmOptions = {
host: 'android.apis.google.com',
port: 443,
path: '/c2dm/send',
method: 'POST',
headers: {}
};
if (config) {
if ('user' in config)
this.user = config.user;
if ('password' in config)
this.password = config.password;
this.source = 'source' in config ? config.source : 'node-c2dm-client';
this.token = 'token' in config ? config.token : null;
this.keepAlive = 'keepAlive' in config ? config.keepAlive : false;
} else {
throw Error('No config given.');
}
this.loginOptions = {
host: 'www.google.com',
port: 443,
path: '/accounts/ClientLogin',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
};
this.c2dmOptions = {
host: 'android.apis.google.com',
port: 443,
path: '/c2dm/send',
method: 'POST',
headers: {}
};
}

util.inherits(C2DM, emitter);

exports.C2DM = C2DM;

C2DM.prototype.captureToken = function(err, token) {
this.token = token;
this.token = token;
};

C2DM.prototype.login = function(cb) {
var self = this;
this.once('token', this.captureToken);
var self = this;
this.once('token', this.captureToken);

if (cb) this.once('token', cb);
if (cb) this.once('token', cb);

var postData = {
Email: this.user,
Passwd: this.password,
accountType: 'HOSTED_OR_GOOGLE',
source: this.source,
service: 'ac2dm'
};
var postData = {
Email: this.user,
Passwd: this.password,
accountType: 'HOSTED_OR_GOOGLE',
source: this.source,
service: 'ac2dm'
};

var request = https.request(this.loginOptions, function(res) {
var data = '';
var request = https.request(this.loginOptions, function(res) {
var data = '';
function respond() {
var idx = data.indexOf('Auth=');
var idx = data.indexOf('Auth=');
if (idx < 0) {
self.emit('token', data, null);
} else {
Expand All @@ -68,30 +68,30 @@ C2DM.prototype.login = function(cb) {
});
res.on('end', respond);
res.on('close', respond);
});
request.end(querystring.stringify(postData));
});
request.end(querystring.stringify(postData));
};

C2DM.prototype.send = function(packet, cb) {
var self = this;
if (cb) this.once('sent', cb);
var self = this;
if (cb) this.once('sent', cb);

var postData = querystring.stringify(packet);
var headers = {
//'Connection': 'keep-alive',
'Host': 'android.apis.google.com',
'Authorization': 'GoogleLogin ' + this.token,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-length': postData.length
};
this.c2dmOptions.headers = headers;
if (this.keepAlive)
headers.Connection = 'keep-alive';
var postData = querystring.stringify(packet);
var headers = {
//'Connection': 'keep-alive',
'Host': 'android.apis.google.com',
'Authorization': 'GoogleLogin ' + this.token,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-length': postData.length
};
this.c2dmOptions.headers = headers;
if (this.keepAlive)
headers.Connection = 'keep-alive';

var request = https.request(this.c2dmOptions, function(res) {
var data = '';
var request = https.request(this.c2dmOptions, function(res) {
var data = '';
function respond() {
var idx = data.indexOf('id=');
var idx = data.indexOf('id=');
if (idx < 0) {
self.emit('sent', data, null);
} else {
Expand All @@ -103,6 +103,6 @@ C2DM.prototype.send = function(packet, cb) {
});
res.on('end', respond);
res.on('close', respond);
});
request.end(postData);
});
request.end(postData);
};

0 comments on commit b34c09a

Please # to comment.