googleapis
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -29,2 +29,3 @@ /** | ||
* @param {string=} keyFile path to private key file. | ||
* @param {string=} key value of key | ||
* @param {array=} scopes list of requested scopes. | ||
@@ -60,3 +61,3 @@ * @param {string=} subject impersonated account's email address. | ||
keyFile: that.keyFile, | ||
key : that.key | ||
key: that.key | ||
}, function(err) { | ||
@@ -63,0 +64,0 @@ if (err) { |
@@ -262,3 +262,3 @@ /** | ||
this.getFederatedSignonCerts(function(err, certs) { | ||
if(err) { | ||
if (err) { | ||
callback(err, null); | ||
@@ -265,0 +265,0 @@ } |
/** | ||
* @constructor | ||
* OData batch request parser. | ||
@@ -23,3 +24,3 @@ * TODO: ridiculously experimental, dont use on prod. | ||
for (var i = 0; i < lines.length; i++) { | ||
switch(lines[i]) { | ||
switch (lines[i]) { | ||
case '--' + this.boundary: | ||
@@ -32,5 +33,5 @@ // started | ||
default: | ||
if (lines[i].indexOf('Content-ID') >= 0) { | ||
if (/^Content\-ID: response\-/.test(lines[i])) { | ||
currentIndex = lines[i].replace('Content-ID: response-', ''); | ||
} | ||
} | ||
if (lines[i][0] == '{') { | ||
@@ -44,2 +45,5 @@ this.results[currentIndex] = JSON.parse(lines[i]); | ||
/** | ||
* Export BatchParser | ||
*/ | ||
module.exports = BatchParser; |
@@ -28,2 +28,3 @@ /** | ||
* GoogleApisClient constructor. | ||
* @param {OAuth2Client} authClient OAuth2Client for authentication | ||
*/ | ||
@@ -30,0 +31,0 @@ function GoogleApisClient(authClient) { |
@@ -109,6 +109,5 @@ /** | ||
* | ||
* @param {string} root Root of the url e.g. http://myserver | ||
* @param {Array} paths An array of string that will be joined to a | ||
single path | ||
* @param {object} queryParams Query parameters of the path, we be also used | ||
* @param {string} root Root of the url e.g. http://myserver | ||
* @param {Array} paths Array of strings that will be joined to single path | ||
* @param {object} params Query parameters of the path, we be also used | ||
* to replace inline path parameters e.g. {param} | ||
@@ -124,11 +123,11 @@ * @return {string} A URL. | ||
fullPath = url.resolve(root, path); | ||
// duplicate params so as not to mangle an object passed by reference | ||
var queryParams = {}; | ||
if (params) { | ||
Object.keys(params).forEach(function(key) { | ||
queryParams[key] = params[key]; | ||
}); | ||
} | ||
// duplicate params so as not to mangle an object passed by reference | ||
var queryParams = {}; | ||
if (params) { | ||
Object.keys(params).forEach(function(key) { | ||
queryParams[key] = params[key]; | ||
}); | ||
} | ||
// replace path query parameters, if there are on the path | ||
@@ -135,0 +134,0 @@ for (var paramName in queryParams) { |
{ | ||
"name": "googleapis", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"author": "Google Inc.", | ||
@@ -5,0 +5,0 @@ "description": "Google APIs Client Library for Node.js", |
228
README.md
@@ -40,10 +40,18 @@ # google-api-nodejs-client [alpha] | ||
.execute(function(err, client) { | ||
if (err) { | ||
console.log('Problem during the client discovery.', err); | ||
return; | ||
} | ||
var params = { shortUrl: 'http://goo.gl/DdUKX' }; | ||
var req1 = client.urlshortener.url.get(params); | ||
req1.execute(function (err, response) { | ||
var getUrlReq = client.urlshortener.url.get(params); | ||
getUrlReq.execute(function (err, response) { | ||
console.log('Long url is', response.longUrl); | ||
}); | ||
var req2 = client.plus.people.get({ userId: '+burcudogan' }); | ||
req2.execute(); | ||
var getUserReq = client.plus.people.get({ userId: '+burcudogan' }); | ||
getUserReq.execute(function(err, user) { | ||
console.log('User id is: ' + user.id); | ||
}); | ||
}); | ||
@@ -68,70 +76,2 @@ ~~~~ | ||
### API Client | ||
Client libraries are generated during runtime by metadata provided by Google | ||
APIs Discovery Service. Metadata provided by Discovery Service is cached, | ||
and won't be requested each time you load a client. Below, there is an | ||
example of loading a client for | ||
[URL Shortener API](https://developers.google.com/url-shortener/). | ||
~~~~ js | ||
googleapis | ||
.discover('urlshortener', 'v1') | ||
.execute(function(err, client) { | ||
// make requests | ||
}); | ||
~~~~ | ||
### Requests | ||
The following sample loads a client for URL Shortener and retrieves the long url | ||
of the given short url: | ||
~~~~ js | ||
googleapis.discover('urlshortener', 'v1').execute(function(err, client) { | ||
client.urlshortener.url.get({ shortUrl: 'http://goo.gl/DdUKX' }) | ||
.execute(function(err, result) { | ||
// result.longUrl contains the long url. | ||
}); | ||
}); | ||
~~~~ | ||
Alternatively, you may need to send an API key with the | ||
request you are going to make. The following creates and executes a request from the Google+ API service to retrieve a person profile given a userId: | ||
~~~~ js | ||
googleapis | ||
.discover('plus', 'v1') | ||
.execute(function(err, client) { | ||
var request1 = client.plus.people.get({ userId: '+burcudogan' }) | ||
.withApiKey(API_KEY); | ||
request1.execute(function(err, result) { | ||
console.log("Result: " + (err ? err.message : result.displayName)); | ||
}); | ||
}); | ||
~~~~ | ||
To learn more about API keys, please see the [documentation](https://developers.google.com/console/help/#UsingKeys). | ||
### Batch requests (experimental) | ||
You can combine multiple requests in a single one by using batch requests. | ||
~~~~ js | ||
var request1 = | ||
client.plus.people.get({ userId: '+BurcuDogan' }); | ||
var request2 = | ||
client.urlshortener.url.insert({ longUrl: 'http://google.com' }); | ||
client | ||
.newBatchRequest() | ||
.add(request1) | ||
.add(request2) | ||
.execute(function(err, results) { | ||
}); | ||
~~~~ | ||
### Authorization and Authentication | ||
@@ -163,5 +103,10 @@ | ||
// for Google+ scope. | ||
var scopes = [ | ||
'https://www.googleapis.com/auth/plus.me', | ||
'https://www.googleapis.com/auth/calendar' | ||
]; | ||
var url = oauth2Client.generateAuthUrl({ | ||
access_type: 'offline', | ||
scope: 'https://www.googleapis.com/auth/plus.me' | ||
scope: scopes.join(" ") // space delimited string of scopes | ||
}); | ||
@@ -185,2 +130,55 @@ ~~~~ | ||
### API Client | ||
Client libraries are generated during runtime by metadata provided by Google | ||
APIs Discovery Service. Metadata provided by Discovery Service is cached, | ||
and won't be requested each time you load a client. Below, there is an | ||
example of loading a client for | ||
[URL Shortener API](https://developers.google.com/url-shortener/). | ||
~~~~ js | ||
googleapis | ||
.discover('urlshortener', 'v1') | ||
.execute(function(err, client) { | ||
// handle discovery errors | ||
// make requests | ||
}); | ||
~~~~ | ||
### Requests | ||
The following sample loads a client for URL Shortener and retrieves the long url | ||
of the given short url: | ||
~~~~ js | ||
googleapis | ||
.discover('urlshortener', 'v1') | ||
.execute(function(err, client) { | ||
// handle discovery errors | ||
client.urlshortener.url.get({ shortUrl: 'http://goo.gl/DdUKX' }) | ||
.execute(function(err, result) { | ||
// result.longUrl contains the long url. | ||
}); | ||
}); | ||
~~~~ | ||
Alternatively, you may need to send an API key with the | ||
request you are going to make. The following creates and executes a request from the Google+ API service to retrieve a person profile given a userId: | ||
~~~~ js | ||
googleapis | ||
.discover('plus', 'v1') | ||
.execute(function(err, client) { | ||
// handle discovery errors | ||
var getUserAuthdReq = client.plus.people.get({ userId: '+burcudogan' }) | ||
.withApiKey(API_KEY); | ||
getUserAuthdReq.execute(function(err, user) { | ||
console.log("Result: " + (err ? err.message : user.displayName)); | ||
}); | ||
}); | ||
~~~~ | ||
To learn more about API keys, please see the [documentation](https://developers.google.com/console/help/#UsingKeys). | ||
#### Making Authenticated Requests | ||
@@ -190,3 +188,3 @@ | ||
requests to Google APIs with the retrieved tokens. If you provide a | ||
refresh_token, the access_token is automatically refreshed and the request is replayed in | ||
refresh_token, the access_token is automatically refreshed and the request is replayed in | ||
case the access_token has expired. | ||
@@ -197,2 +195,7 @@ | ||
~~~~ js | ||
var oauth2Client = | ||
new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); | ||
// Retrieve tokens via token exchange explaind above. | ||
// Or you can set them. | ||
oauth2Client.credentials = { | ||
@@ -204,7 +207,27 @@ access_token: 'ACCESS TOKEN HERE', | ||
client | ||
.plus.people.get({ userId: 'me' }) | ||
.withAuthClient(oauth2Client) | ||
.execute(callback); | ||
.plus.people.get({ userId: 'me' }) | ||
.withAuthClient(oauth2Client) | ||
.execute(callback); | ||
~~~~ | ||
### Batch requests (experimental) | ||
You can combine multiple requests in a single one by using batch requests. | ||
~~~~ js | ||
var getUserReq = | ||
client.plus.people.get({ userId: '+BurcuDogan' }); | ||
var insertUrlReq = | ||
client.urlshortener.url.insert({ longUrl: 'http://google.com' }); | ||
client | ||
.newBatchRequest() | ||
.add(getUserReq) | ||
.add(insertUrlReq) | ||
.execute(function(err, results) { | ||
// handle results | ||
}); | ||
~~~~ | ||
### Media Uploads | ||
@@ -218,4 +241,4 @@ | ||
.drive.files.insert({ title: 'Test', mimeType: 'text/plain' }) | ||
.withMedia('text/plain', 'Hello World') | ||
.execute(); | ||
.withMedia('text/plain', 'Hello World') | ||
.execute(); | ||
~~~~ | ||
@@ -228,47 +251,4 @@ | ||
## Contributors | ||
## Contributing | ||
Before making any contributions, please sign one of the contributor | ||
license agreements below. | ||
Fork the repo, develop and test your code changes. | ||
Install all dependencies including development requirements by running: | ||
~~~~ sh | ||
$ npm install -d | ||
~~~~ | ||
Tests use mocha. To run all tests you can use | ||
~~~~ sh | ||
$ npm test | ||
~~~~ | ||
which looks for tests in the `./tests` directory. | ||
Your code should honor the | ||
[Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml). | ||
You can use | ||
[Closure Linter](https://code.google.com/p/closure-linter/) | ||
to detect style issues. | ||
Submit a pull request. The repo owner will review your request. If it is | ||
approved, the change will be merged. If it needs additional work, the repo | ||
owner will respond with useful comments. | ||
#### Contributor License Agreements | ||
Before creating a pull request, please fill out either the individual or | ||
corporate Contributor License Agreement. | ||
* If you are an individual writing original source code and you're sure you | ||
own the intellectual property, then you'll need to sign an | ||
[individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). | ||
* If you work for a company that wants to allow you to contribute your work | ||
to this client library, then you'll need to sign a | ||
[corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). | ||
Follow either of the two links above to access the appropriate CLA and | ||
instructions for how to sign and return it. Once we receive it, we'll add you | ||
to the official list of contributors and be able to accept your patches. | ||
See [CONTRIBUTING](https://github.com/google/google-api-nodejs-client/tree/master/CONTRIBUTING.md). |
@@ -84,3 +84,4 @@ /** | ||
var req = | ||
client.plus.withDefaultParams({a: 1, b: 'foo'}).newRequest('doIt', {a: 2}, {}); | ||
client.plus.withDefaultParams({a: 1, b: 'foo'}) | ||
.newRequest('doIt', {a: 2}, {}); | ||
assert.equal(2, req.params.a); | ||
@@ -92,3 +93,4 @@ assert.equal('foo', req.params.b); | ||
it('should be able to add defaultParams on new requests with no params and a body', function(done) { | ||
it('should be able to add defaultParams on new' + | ||
'requests with no params and a body', function(done) { | ||
new googleapis.GoogleApis() | ||
@@ -98,3 +100,4 @@ .discover('plus', 'v1') | ||
var req = | ||
client.plus.withDefaultParams({a: 1, b: 'foo'}).newRequest('doIt', {has_body: true}); | ||
client.plus.withDefaultParams({a: 1, b: 'foo'}) | ||
.newRequest('doIt', {has_body: true}); | ||
assert.equal(1, req.params.a); | ||
@@ -101,0 +104,0 @@ assert.equal('foo', req.params.b); |
@@ -81,4 +81,4 @@ /** | ||
it('should cache discovery metadata should be stored in the configurable ' | ||
+ 'cache directory', function(done) { | ||
it('should cache discovery metadata should be stored in the configurable ' + | ||
'cache directory', function(done) { | ||
var customPath = './b041042364d89046c003ca151a6254ef'; | ||
@@ -85,0 +85,0 @@ new googleapis.GoogleApis() |
@@ -41,3 +41,3 @@ /** | ||
} | ||
} | ||
}; | ||
}; | ||
@@ -44,0 +44,0 @@ jwt.authorize(function() { |
@@ -393,4 +393,2 @@ /** | ||
'utf-8'); | ||
var privateKey = fs.readFileSync('./test/data/private.pem', | ||
'utf-8'); | ||
@@ -417,11 +415,6 @@ var maxLifetimeSecs = 86400; | ||
var data = new Buffer(envelope).toString('base64') + | ||
'.' + new Buffer(idToken).toString('base64'); | ||
var data = new Buffer(envelope).toString('base64') + | ||
'.' + new Buffer(idToken).toString('base64') + | ||
'.' + 'broken-signature'; | ||
var signer = crypto.createSign('sha256'); | ||
signer.update(data); | ||
var signature = signer.sign('Broken signature', 'base64'); | ||
data += '.' + signature; | ||
var oauth2client = | ||
@@ -428,0 +421,0 @@ new googleapis.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); |
@@ -64,3 +64,4 @@ /** | ||
assert.equal(payload.uri, 'https://www.googleapis.com/urlshortener/v1/url'); | ||
assert.equal(payload.uri, | ||
'https://www.googleapis.com/urlshortener/v1/url'); | ||
assert.equal(payload.method, 'POST'); | ||
@@ -80,3 +81,3 @@ assert.equal(payload.json.longUrl, 'http://someurl...'); | ||
req.transporter = invalidGrantMockTransporter; | ||
req.execute(function (err, res) { | ||
req.execute(function(err, res) { | ||
assert.equal(err, 'invalid_grant'); | ||
@@ -98,3 +99,4 @@ done(); | ||
var payload = request.generatePayload(); | ||
assert.equal(payload.uri, 'https://www.googleapis.com/urlshortener/v1/url?shortUrl=a'); | ||
assert.equal(payload.uri, | ||
'https://www.googleapis.com/urlshortener/v1/url?shortUrl=a'); | ||
assert.equal(payload.method, 'GET'); | ||
@@ -168,9 +170,12 @@ done(); | ||
requests.add(client.urlshortener.url.get()); | ||
requests.add(client.urlshortener.url.get({ shortUrl: 'http://goo.gl/mR2d' })); | ||
requests.add(client.urlshortener.url.get({ | ||
shortUrl: 'http://goo.gl/mR2d' })); | ||
// should construct the payload in the given order. | ||
var payload = requests.generatePayload(); | ||
assert.equal(payload.multipart[0].body, 'GET /urlshortener/v1/url/history\r\n'); | ||
assert.equal(payload.multipart[0].body, | ||
'GET /urlshortener/v1/url/history\r\n'); | ||
assert.equal(payload.multipart[1].body, 'GET /urlshortener/v1/url\r\n'); | ||
assert.equal(payload.multipart[2].body, 'GET /urlshortener/v1/url?shortUrl=http%3A%2F%2Fgoo.gl%2FmR2d\r\n'); | ||
assert.equal(payload.multipart[2].body, | ||
'GET /urlshortener/v1/url?shortUrl=http%3A%2F%2Fgoo.gl%2FmR2d\r\n'); | ||
done(); | ||
@@ -185,4 +190,6 @@ }); | ||
var requests = client.newBatchRequest(); | ||
requests.add(client.urlshortener.url.get({ shortUrl: 'http://goo.gl/mR2d' })); | ||
requests.add(client.urlshortener.url.get({ shortUrl: 'http://goo.gl/mR2d' })); | ||
requests.add(client.urlshortener.url.get({ | ||
shortUrl: 'http://goo.gl/mR2d' })); | ||
requests.add(client.urlshortener.url.get({ | ||
shortUrl: 'http://goo.gl/mR2d' })); | ||
requests.execute(function(err, results) { | ||
@@ -195,5 +202,5 @@ assert.ifError(err); | ||
it('should generate a valid basic upload payload if media is set, ' | ||
+ 'metadata is not set', function(done) { | ||
googleapis.discover('drive', 'v2').execute(function(err, client){ | ||
it('should generate a valid basic upload payload if media is set, ' + | ||
'metadata is not set', function(done) { | ||
googleapis.discover('drive', 'v2').execute(function(err, client) { | ||
var req = client.drive.files.insert().withMedia('text/plain', 'hey'); | ||
@@ -203,3 +210,4 @@ | ||
assert.equal(payload.method, 'POST'); | ||
assert.equal(payload.uri, 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media'); | ||
assert.equal(payload.uri, | ||
'https://www.googleapis.com/upload/drive/v2/files?uploadType=media'); | ||
assert.equal(payload.headers['Content-Type'], 'text/plain'); | ||
@@ -211,4 +219,4 @@ assert.equal(payload.body, 'hey'); | ||
it('should generate a valid multipart upload payload if media and metadata ' | ||
+ 'are set both', function(done) { | ||
it('should generate valid multipart upload payload if media and metadata ' + | ||
'are both set', function(done) { | ||
googleapis.discover('drive', 'v2').execute(function(err, client) { | ||
@@ -221,3 +229,4 @@ var req = client.drive.files | ||
assert.equal(payload.method, 'POST'); | ||
assert.equal(payload.uri, 'https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart'); | ||
assert.equal(payload.uri, 'https://www.googleapis.com/upload/drive/' + | ||
'v2/files?uploadType=multipart'); | ||
assert.equal(payload.multipart[0]['Content-Type'], 'application/json'); | ||
@@ -267,3 +276,2 @@ assert.equal(payload.multipart[0].body, '{"title":"title"}'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193961
36
5250
246