Skip to content

🔍 Examples of Generated Samples for Code Review [DO NOT MERGE] - #4264

Closed
beccasaurus wants to merge 2 commits into
googleapis:masterfrom
beccasaurus:generated-sample-syntax-review
Closed

beccasaurus wants to merge 2 commits into
googleapis:masterfrom
beccasaurus:generated-sample-syntax-review

Conversation

@beccasaurus

@beccasaurus beccasaurus commented Oct 22, 2019 •

Copy link
Copy Markdown

Pull Request to facilitate code review of GAPIC SampleGen rendered syntax. Do not merge.

This Pull Request contains two code samples which were generated using the GAPIC generator:

  • Natural Language API – "Analyze Sentiment" (language_sentiment_text) (config YAML)
  • Speech-to-Text API – "Long-Running Transcribe" (speech_transcribe_async) (config YAML)

These code samples demonstrate a few features of the code sample generator:

  • Overall code sample structure (imports, layout, etc)
  • Calling a synchronous API endpoint and printing fields from the API response
  • Calling a long-running API, waiting for completion, and printing fields from API response
  • Using local files with code samples, specifically a file to use for a bytes request field

You can find the existing, published hand-written versions of these code samples here:

For Ruby, existing hand-written code samples can be found in the ruby-docs-samples repository.

The goal is for these generated code samples to meet the expectations of hand-written samples.


Language experts, please TAL! 🧐

/cc @dazuma @frankyn @TheRoyalTnetennba @dizcology @blowmage


This is one of seven Pull Requests being sent for code review of rendered generated sample syntax.

Language Pull Request
#️⃣ C# googleapis/google-cloud-dotnet#3650
🐹 Go googleapis/google-cloud-go#1634
☕️ Java googleapis/google-cloud-java#6543
🚀Node.js googleapis/google-cloud-node#2953
🐘 PHP googleapis/google-cloud-php#2420
🐍 Python googleapis/google-cloud-python#9514
💎 Ruby #4264

📓 Internal doc for context

@beccasaurus

Copy link
Copy Markdown
Author

/cc @googleapis/samplegen

@dazuma dazuma added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 22, 2019
Comment thread language_sentiment_text.rb Resolved
# For list of supported languages:
# https://cloud.google.com/natural-language/docs/languages
language = "en"
document = {

This comment was marked as resolved.

This comment was marked as resolved.

# Available values: NONE, UTF8, UTF16, UTF32
encoding_type = :UTF8

response = language_client.analyze_sentiment(document, encoding_type: encoding_type)

This comment was marked as resolved.

text_content = "I am so happy and joyful."

ARGV.options do |opts|
opts.on("--text_content=val") { |val| text_content = val }

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 translate lower_snake_case to kebab-case for option names?

opts.parse!
end


This comment was marked as resolved.


# Analyzing Sentiment in a String
#
# @param text_content {String} The text content to analyze

This comment was marked as outdated.

response.results.each do |result|
# First alternative is the most probable result
alternative = result.alternatives[0]
puts "Transcript: #{alternative.transcript}"

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.

wow, this is impressive. I can't believe it's not manual.

# description: Analyzing Sentiment in a String
# bundle exec ruby samples/v1/language_sentiment_text.rb [--text_content "I am so happy and joyful."]

require "google/cloud/language"

This comment was marked as resolved.

Comment thread language_sentiment_text.rb Resolved
@beccasaurus

beccasaurus commented Nov 25, 2019 •

Copy link
Copy Markdown
Author

Changes incoming!

All kinds of changes in response to feedback.

  • Added padding between anything with comments
  • Sample code (between START/END) is procedural, not wrapped in a method
    • No more YARD with method etc
  • Imports moved into START/END

Overall, lots of vertical padding added for aesthetic goodness.

Generated from: https://github.com/beccasaurus/gapic-generator/compare/ruby-standalone-syntax-updates

GAPIC Generator PR:

@beccasaurus

Copy link
Copy Markdown
Author

Closing per recent conversation ~ while these updates look good and are close to the desired state, the generation of these files is planned to move to the µgenerator.

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

Labels

cla: yes This human has signed the Contributor License Agreement. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants