diff --git a/package-lock.json b/package-lock.json index c382ecd6eb0..6a4c7d1a40d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "googleapis", - "version": "28.1.0", + "version": "29.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/samples/blogger/insert.js b/samples/blogger/insert.js new file mode 100644 index 00000000000..8f095afc59a --- /dev/null +++ b/samples/blogger/insert.js @@ -0,0 +1,46 @@ +// Copyright 2018, Google, LLC. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {google} = require('googleapis'); +const sampleClient = require('../sampleclient'); + +const blogger = google.blogger({ + version: 'v3', + auth: sampleClient.oAuth2Client +}); + +async function runSample () { + const res = await blogger.posts.insert({ + blogId: '4340475495955554224', + resource: { + title: 'Hello from the googleapis npm module!', + content: 'Visit https://github.com/google/google-api-nodejs-client to learn more!' + } + }); + console.log(res.data); + return res.data; +} + +if (module === require.main) { + const scopes = ['https://www.googleapis.com/auth/blogger']; + sampleClient.authenticate(scopes) + .then(runSample) + .catch(console.error); +} + +module.exports = { + runSample, + client: sampleClient.oAuth2Client +}; diff --git a/samples/config.json b/samples/config.json deleted file mode 100644 index d34db27cb50..00000000000 --- a/samples/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "api_key": "YOUR_API_KEY", - "customsearch_engine_id": "YOUR_CUSTOMSEARCH_ENGINE_ID" -} \ No newline at end of file diff --git a/test/samples/test.samples.blog.ts b/test/samples/test.samples.blog.ts new file mode 100644 index 00000000000..088625bf19b --- /dev/null +++ b/test/samples/test.samples.blog.ts @@ -0,0 +1,44 @@ +// Copyright 2018, Google, LLC. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import * as assert from 'assert'; +import * as nock from 'nock'; +import {Utils} from '../utils'; + +nock.disableNetConnect(); + +// tslint:disable: no-any +const samples: any = { + post: require('../../../samples/blogger/insert'), +}; + +for (const p in samples) { + if (samples[p]) { + samples[p].client.credentials = {access_token: 'not-a-token'}; + } +} + +describe('blogger samples', () => { + afterEach(() => { + nock.cleanAll(); + }); + + it('should insert a blog post', async () => { + const scope = nock(Utils.baseUrl) + .post(`/blogger/v3/blogs/4340475495955554224/posts`) + .reply(200, {}); + const data = await samples.post.runSample(); + assert(data); + scope.done(); + }); +});