Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions google-api-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ GoogleApi = {
_callAndRefresh: function(method, path, options, callback) {
var self = this;
options = options || {};
self._call(method, path, options,
// need to bind the env here so we can do mongo writes in the callback

self._call(method, path, options,
// need to bind the env here so we can do mongo writes in the callback
// (when refreshing), if we call this on the server
Meteor.bindEnvironment(function(error, result) {
if (error && error.response && error.response.statusCode == 401) {
Expand All @@ -19,33 +19,34 @@ GoogleApi = {
return self._refresh(options.user, function(error) {
if (error)
return callback(error);

// if we have the user, we'll need to re-fetch them, as their
// access token will have changed.
if (options.user)
options.user = Meteor.users.findOne(options.user._id);

self._call(method, path, options, callback);
});
} else {
callback(error, result);
}
}, 'Google Api callAndRefresh'));
},

// call a GAPI Meteor.http function if the accessToken is good
_call: function(method, path, options, callback) {
Log('GoogleApi._call, path:' + path);

options = options || {};
var user = options.user || Meteor.user();
if (user && user.services && user.services.google &&

if (user && user.services && user.services.google &&
user.services.google.accessToken) {
options.headers = options.headers || {};
options.headers.Authorization = 'Bearer ' + user.services.google.accessToken;

HTTP.call(method, this._host + '/' + path, options, function(error, result) {

var host = options.host || this._host;
HTTP.call(method, host + '/' + path, options, function(error, result) {
callback(error, result && result.data);
});
} else {
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'percolate:google-api',
summary: "A Meteor library to interact with Google's API",
version: '1.0.1',
version: '1.0.2',
git: 'https://github.com/percolatestudio/meteor-google-api'
});

Expand All @@ -12,10 +12,10 @@ Package.on_use(function (api, where) {
} else {
api.use(['http', 'livedata', 'google', 'q', 'accounts-base', 'underscore']);
}

api.add_files(['utils.js', 'google-api-async.js'], ['client', 'server']);
api.add_files(['google-api-methods.js'], ['server']);

api.export('GoogleApi', ['client', 'server']);
});

Expand Down