-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add google plus post sample (#1125)
- Loading branch information
1 parent
f8d4705
commit 0b4d13c
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |