Skip to content

New GenerateKeywordIdeas example for the KeywordPlanService#49

Merged
jradcliff merged 4 commits intomasterfrom
keywordideas
Dec 20, 2018
Merged

New GenerateKeywordIdeas example for the KeywordPlanService#49
jradcliff merged 4 commits intomasterfrom
keywordideas

Conversation

@jradcliff
Copy link
Copy Markdown
Member

No description provided.

[keywordideas]

Change-Id: Ide39a516a945f51d96f9786f18a4ebddd826d1ad
@jradcliff jradcliff self-assigned this Dec 17, 2018
StringValue.of(ResourceNames.geoTargetConstant(locationId)));
}

// Add each keyword seed to the request's keyword seed list.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some more commentary on the different seed types perhaps? Maybe call each of the different seed methods separately?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked this to handle the three supported seed types:

  • UrlSeed for just a page URL
  • KeywordSeed for just a list of keywords
  • KeywordAndUrlSeed for both of the above

} else {
// Convert the list of keywords into a list of StringValues.
List<StringValue> keywordStringValues =
keywords.stream().map(keyword -> StringValue.of(keyword)).collect(Collectors.toList());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can replace map(keyword -> StringValue.of(keyword) with map(StringValue::of)

throw new IllegalArgumentException(
"At least one of keywords or page URL is required, but neither was specified.");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment here explaining the oneof semantics.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the existing comment on lines 162-163

"At least one of keywords or page URL is required, but neither was specified.");
}

if (keywords.isEmpty()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to reduce the nesting here, as in

if (keywords.isEmpty() && pageUrl != null) {
} else if (pageUrl != null) {
} else {
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add the above error branch to bring the entire oneof handling into a single block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked to reduce nesting. I did not include the error case here because if that's true, the example will throw an exception. I personally prefer separating out the error case, but LMK if you feel strongly about combining them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point, thanks.

Copy link
Copy Markdown
Contributor

@nwbirnie nwbirnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment, otherwise LGTM.

"At least one of keywords or page URL is required, but neither was specified.");
}

if (keywords.isEmpty()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point, thanks.

// Only keywords were specified, so use a KeywordSeed.
requestBuilder
.getKeywordSeedBuilder()
.addAllKeywords(keywords.stream().map(StringValue::of).collect(Collectors.toList()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code for the stream().map(), maybe make a local variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, if I do that I'd want to move back to the 2nd level of nesting. With the current nesting layout, creating the local variable is unnecessary for the if case. I'm concerned that it will just confuse readers.

I like the current nesting you suggested, so I'd prefer to keep it with the tradeoff of a bit of duplication. Also, the duplication means the else if and else blocks are a bit more amenable to copy/pasting.

@AnashOommen , what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Josh, I prefer the ease of copy-pasting over a bit of duplication here.

Copy link
Copy Markdown
Contributor

@nwbirnie nwbirnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github is really misleading when there's an open comment with LGTM. Also with two reviewers it looks like you can submit with one LGTM.

Removing my LGTM, but the comment on duplicated code is the only open issue from my side. Over to @AnashOommen for review and approvals.

@jradcliff jradcliff merged commit 3199063 into master Dec 20, 2018
@jradcliff jradcliff deleted the keywordideas branch December 20, 2018 15:55
"At least one of keywords or page URL is required, but neither was specified.");
}

if (keywords.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read this correctly, it looks like the keyword texts will always be at least ['INSERT_KEYWORD_TEXT_1', 'INSERT_KEYWORD_TEXT_2']?
In that case, this condition would never be true?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are only used when the flags fail to parse (e.g. missing required, invalid number formats etc.)

Also this flag is optional, so specifying --locationId 123 --languageId abc should be sufficient to clear the value here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants