Skip to content

Commit

Permalink
docs: add blogger post sample (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Apr 30, 2018
1 parent 3729b90 commit 6fc8a61
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions 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
};
4 changes: 0 additions & 4 deletions samples/config.json

This file was deleted.

44 changes: 44 additions & 0 deletions 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();
});
});

0 comments on commit 6fc8a61

Please sign in to comment.