Skip to content

Commit

Permalink
docs(samples): samples to use async/await (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliQlogic authored and JustinBeckwith committed Nov 21, 2018
1 parent af715b2 commit 289bca6
Showing 1 changed file with 48 additions and 49 deletions.
97 changes: 48 additions & 49 deletions packages/google-privacy-dlp/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,62 @@
// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

// Instantiates a client
const dlp = new DLP.DlpServiceClient();
async function quickStart() {
// Instantiates a client
const dlp = new DLP.DlpServiceClient();

// The string to inspect
const string = 'Robert Frost';
// The string to inspect
const string = 'Robert Frost';

// The project ID to run the API call under
const projectId = process.env.GCLOUD_PROJECT;
// The project ID to run the API call under
const projectId = process.env.GCLOUD_PROJECT;

// The minimum likelihood required before returning a match
const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';
// The minimum likelihood required before returning a match
const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';

// The maximum number of findings to report (0 = server maximum)
const maxFindings = 0;
// The maximum number of findings to report (0 = server maximum)
const maxFindings = 0;

// The infoTypes of information to match
const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];
// The infoTypes of information to match
const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];

// Whether to include the matching string
const includeQuote = true;
// Whether to include the matching string
const includeQuote = true;

// Construct item to inspect
const item = {value: string};
// Construct item to inspect
const item = {value: string};

// Construct request
const request = {
parent: dlp.projectPath(projectId),
inspectConfig: {
infoTypes: infoTypes,
minLikelihood: minLikelihood,
limits: {
maxFindingsPerRequest: maxFindings,
// Construct request
const request = {
parent: dlp.projectPath(projectId),
inspectConfig: {
infoTypes: infoTypes,
minLikelihood: minLikelihood,
limits: {
maxFindingsPerRequest: maxFindings,
},
includeQuote: includeQuote,
},
includeQuote: includeQuote,
},
item: item,
};
item: item,
};

// Run request
dlp
.inspectContent(request)
.then(response => {
const findings = response[0].result.findings;
if (findings.length > 0) {
console.log(`Findings:`);
findings.forEach(finding => {
if (includeQuote) {
console.log(`\tQuote: ${finding.quote}`);
}
console.log(`\tInfo type: ${finding.infoType.name}`);
console.log(`\tLikelihood: ${finding.likelihood}`);
});
} else {
console.log(`No findings.`);
}
})
.catch(err => {
console.error(`Error in inspectString: ${err.message || err}`);
});
// Run request
const [response] = await dlp.inspectContent(request);
const findings = response.result.findings;
if (findings.length > 0) {
console.log(`Findings:`);
findings.forEach(finding => {
if (includeQuote) {
console.log(`\tQuote: ${finding.quote}`);
}
console.log(`\tInfo type: ${finding.infoType.name}`);
console.log(`\tLikelihood: ${finding.likelihood}`);
});
} else {
console.log(`No findings.`);
}
}
quickStart().catch(err => {
console.error(`Error in inspectString: ${err.message || err}`);
});
// [END dlp_quickstart]

0 comments on commit 289bca6

Please sign in to comment.