Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add blogger post sample #1140

Merged
merged 1 commit into from Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});