Socket
Socket
Sign inDemoInstall

google-contacts

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.1.0

105

index.js

@@ -6,3 +6,3 @@ /**

*
* To API test requests:
* To API test requests:
*

@@ -15,5 +15,5 @@ * @see https://developers.google.com/oauthplayground/

*
* Note: The Contacts API has a hard limit to the number of results it can return at a
* time even if you explicitly request all possible results. If the requested feed has
* more fields than can be returned in a single response, the API truncates the feed and adds
* Note: The Contacts API has a hard limit to the number of results it can return at a
* time even if you explicitly request all possible results. If the requested feed has
* more fields than can be returned in a single response, the API truncates the feed and adds
* a "Next" link that allows you to request the rest of the response.

@@ -27,17 +27,20 @@ */

https = require('https'),
debug = require('debug')('google-contacts'),
querystring = require('querystring');
var GoogleContacts = function (opts) {
if (typeof opts === 'string') {
opts = { token: opts }
var GoogleContacts = function (params) {
if (typeof params === 'string') {
params = { token: params }
}
if (!opts) {
opts = {};
if (!params) {
params = {};
}
this.contacts = [];
this.consumerKey = opts.consumerKey ? opts.consumerKey : null;
this.consumerSecret = opts.consumerSecret ? opts.consumerSecret : null;
this.token = opts.token ? opts.token : null;
this.refreshToken = opts.refreshToken ? opts.refreshToken : null;
this.consumerKey = params.consumerKey ? params.consumerKey : null;
this.consumerSecret = params.consumerSecret ? params.consumerSecret : null;
this.token = params.token ? params.token : null;
this.refreshToken = params.refreshToken ? params.refreshToken : null;
this.params = _.extend({thin:true},params);
};

@@ -64,7 +67,7 @@

headers: {
'Authorization': 'OAuth ' + this.token
'Authorization': 'OAuth ' + this.token
}
};
console.log(req);
debug(req);

@@ -74,2 +77,11 @@ https.request(req, function (res) {

res.on('data', function (chunk) {
debug('got ' + chunk.length + ' bytes');
data += chunk.toString('utf-8');
});
res.on('error', function (err) {
cb(err);
});
res.on('end', function () {

@@ -81,4 +93,4 @@ if (res.statusCode < 200 || res.statusCode >= 300) {

try {
data = JSON.parse(data);
cb(null, data);
debug(data);
cb(null, JSON.parse(data));
}

@@ -89,22 +101,11 @@ catch (err) {

});
res.on('data', function (chunk) {
//console.log(chunk.toString());
data += chunk;
});
res.on('error', function (err) {
cb(err);
});
//res.on('close', onFinish);
}).on('error', function (err) {
cb(err);
}).end();
})
.on('error', cb)
.end();
};
GoogleContacts.prototype.getContacts = function (cb, contacts) {
GoogleContacts.prototype.getContacts = function (cb, params) {
var self = this;
this._get({ type: 'contacts' }, receivedContacts);
this._get(_.extend({ type: 'contacts' },params,this.params), receivedContacts);
function receivedContacts(err, data) {

@@ -131,8 +132,14 @@ if (err) return cb(err);

var self = this;
//console.log(feed);
feed.entry.forEach(function (entry) {
var el;
try {
var name = entry.title['$t'];
var email = entry['gd$email'][0].address; // only save first email
self.contacts.push({ name: name, email: email });
if(self.params.thin){
el = {
name: entry.title['$t'],
email: entry['gd$email'][0].address // only save first email
};
}else{
el = entry;
}
self.contacts.push(el);
}

@@ -143,4 +150,2 @@ catch (e) {

});
//console.log(self.contacts);
//console.log(self.contacts.length);
}

@@ -151,6 +156,6 @@

params = params || {};
params = _.extend({},params,this.params);
params.type = params.type || 'contacts';
params.alt = params.alt || 'json';
params.projection = params.projection || 'thin';
params.projection = params.projection || (params.thin?'thin':'full');
params.email = params.email || 'default';

@@ -163,6 +168,8 @@ params['max-results'] = params['max-results'] || 2000;

};
if(params['updated-min'])
query['updated-min'] = params['updated-min'];
var path = '/m8/feeds/';
path += params.type + '/';
path += params.email + '/';
path += params.email + '/';
path += params.projection;

@@ -201,5 +208,2 @@ path += '?' + qs.stringify(query);

//console.log(opts);
//console.log(data);
var req = https.request(opts, function (res) {

@@ -214,3 +218,2 @@ var data = '';

data = JSON.parse(data);
//console.log(data);
cb(null, data.access_token);

@@ -224,14 +227,8 @@ }

res.on('data', function (chunk) {
//console.log(chunk.toString());
data += chunk;
});
res.on('error', function (err) {
cb(err);
});
res.on('error', cb);
//res.on('close', onFinish);
}).on('error', function (err) {
cb(err);
});
}).on('error', cb);

@@ -238,0 +235,0 @@ req.write(body);

{
"name": "google-contacts",
"version": "0.0.3",
"version": "0.1.0",
"description": "API wrapper for Google Contacts",

@@ -10,3 +10,3 @@ "main": "index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node tests/test.js"
},

@@ -23,6 +23,10 @@ "repository": {

"dependencies": {
"debug": "^2.2.0",
"underscore": ""
},
"author": "Ajnasz <ajnasz@ajnasz.hu>",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"inireader": "^0.3.3"
}
}

@@ -5,3 +5,5 @@ Node.js wrapper for the Google Contacts API.

npm install google-contacts
```
npm install google-contacts
```

@@ -15,19 +17,25 @@ # Usage

});
c.on('error', function (e) {
console.log('error', e);
});
c.on('contactsReceived', function (contacts) {
console.log('contacts: ' + contacts);
});
c.on('contactGroupsReceived', function (contactGroups) {
console.log('groups: ' + contactGroups);
});
c.getContacts('thin', 100);
c.getContactGroups('thin', 200);
c.getContacts(cb, params);
```
getContacts and getContactGroups has two optional parameter:
projection and limit
http://code.google.com/apis/contacts/docs/3.0/reference.html#Projections
limit max how many elements do you wan't to receive
Params:
**type** (default: 'contacts')
**alt** (default: json)
**projection**
**email** (default: 'default')
**max-results** (default: 2000)
See [https://developers.google.com/google-apps/contacts/v3/](https://developers.google.com/google-apps/contacts/v3/).
# Test
```
GOOGLE_TOKEN=sometoken npm run test
# verbose test
DEBUG=google-contacts GOOGLE_TOKEN=sometoken npm run test
```
You can get a test token at [https://developers.google.com/oauthplayground/](https://developers.google.com/oauthplayground/).
/*jslint indent:2*/
/*global require: true, console: true */
var IniReader = require('inireader').IniReader;
var iniReader = new IniReader();
var GoogleContacts = require('googlecontacts').GoogleContacts;
var GoogleContacts = require('../').GoogleContacts;
var assert = require('assert');
var concatsTested = false, groupsTested = false;
iniReader.on('fileParse', function () {
var cfg = this.param('account'), c;
c = new GoogleContacts({
email: cfg.email,
password: cfg.password
});
c.on('error', function (e) {
console.log('error', e);
});
c.on('contactsReceived', function (contacts) {
assert.ok(typeof contacts === 'object', 'Contacts is not an object');
concatsTested = true;
});
c.on('contactGroupsReceived', function (contactGroups) {
assert.ok(typeof contactGroups === 'object', 'Contact groups is not an object');
groupsTested = true;
});
c.getContacts();
c.getContactGroups();
var contactsTested = false;
var c = new GoogleContacts({
token: process.env.GOOGLE_TOKEN,
});
iniReader.load('/home/ajnasz/.google.ini');
c.getContacts(function (err, contacts) {
if (err) throw err;
assert.ok(typeof contacts === 'object', 'Contacts is not an object');
console.log(contacts);
contactsTested = true;
});
process.on('exit', function () {
if (!concatsTested) {
if (!contactsTested) {
throw new Error('contact test failed');
}
if (!groupsTested) {
throw new Error('group test failed');
}
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc