Skip to content

Commit

Permalink
feat: add google plus post sample (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Apr 18, 2018
1 parent f8d4705 commit 0b4d13c
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
57 changes: 57 additions & 0 deletions samples/plus/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 plus = google.plusDomains({
version: 'v1',
auth: sampleClient.oAuth2Client
});

async function runSample () {
const res = await plus.activities.insert({
userId: 'me',
resource: {
object: {
originalContent: 'Hello from the Node.js Google API Client!'
},
access: {
items: [{
type: 'domain'
}],
domainRestricted: true
}
}
});
console.log(res.data);
return res.data;
}

const scopes = [
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.stream.write'
];

if (module === require.main) {
sampleClient.authenticate(scopes)
.then(c => runSample())
.catch(console.error);
}

module.exports = {
runSample,
client: sampleClient.oAuth2Client
};
44 changes: 44 additions & 0 deletions test/samples/test.samples.plus.ts
Original file line number Diff line number Diff line change
@@ -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/plus/post'),
};

for (const p in samples) {
if (samples[p]) {
samples[p].client.credentials = {access_token: 'not-a-token'};
}
}

describe('plus samples', () => {
afterEach(() => {
nock.cleanAll();
});

it('should insert a new activity', async () => {
const scope = nock(Utils.baseUrl)
.post(`/plusDomains/v1/people/me/activities`)
.reply(200, {});
const data = await samples.post.runSample();
assert(data);
scope.done();
});
});

0 comments on commit 0b4d13c

Please sign in to comment.