Repository navigation
Conversation
Change-Id: I57fa8a776fb8a1cbd43f6c1d3a1a71c3c63bdd19
Change-Id: I2f4db5b40ddc0494f631b62d60b6992f786cbf57
Code Vetting & Review RecommendationsOverall, the implementation for adding incentive examples ( 1.
|
Change-Id: I19de34550a54efaa8095b503bd5e8c449930e9d4
Change-Id: I4f3b19fe5ace2a6d88f7f0c3b90906f97b0d454b
bobhancockg
left a comment
There was a problem hiding this comment.
Overall, the implementation for adding incentive examples is well-structured and incorporates previous feedback nicely. Here are a few remaining recommendations and optimizations before merging:
-
examples/incentives/apply_incentive.rb:- Clean up redundant
request_args[:country_code] = country_code if country_codeduplicate assignment on line 36.
- Clean up redundant
-
examples/incentives/fetch_incentive.rb:- Update request field name from
type: :ACQUISITIONtoincentive_type: :ACQUISITIONto match current Google Ads API protobuf definitions (v24+) and avoid runtimeArgumentError. - Provide default
nilarguments indef fetch_incentive(email, language_code = nil, country_code = nil)and construct request args using.compact. - Fix missing whitespace in string continuation on lines 51-52 (
"type." \ "Non-CYO"->"type.Non-CYO"). - Defensively format monetary currency strings against empty protobuf defaults (
"").
- Update request field name from
Change-Id: I6dfd7bc56bafdf1910e5e35209600f3bc52a6e84
…traversal, and CLI validation
|
Updated the PR with the following optimizations:
|
- Add shebang and Encoding header - Remove trailing whitespace after .compact - Surface consolidated terms and conditions URL when present in fetch_incentive - Validate against empty email string in CLI options - Add fallback confirmation message when incentive applied without coupon code or creation time Change-Id: I5a0ed0cd2a2ef3744b28c6f83a47a12dfd2cb24d
| @@ -0,0 +1,168 @@ | |||
| #!/usr/bin/env ruby | |||
There was a problem hiding this comment.
- DevSite filename alignment (
fetch_incentives.rb): The DevSite Incentives guide (docs/billing/incentives.md) and sample page (samples/fetch-incentives.md) referencecode_example_id='incentives/fetch_incentives'(plural, matchingfetch_incentives.pyin Python,FetchIncentives.javain Java, andFetchIncentives.csin .NET), which resolves toexamples/incentives/fetch_incentives.rb. Consider renaming this file toexamples/incentives/fetch_incentives.rbso DevSite snippet inclusion works out of the box without custom path overrides. - Executable file mode (
100755) & header: Since#!/usr/bin/env rubyandUsage: %s [options]were added for standalone script execution, pleasechmod +x(100755) this file (currently100644). Also,# Encoding: utf-8on line 2 can be removed since UTF-8 is the default source encoding in Ruby 2.0+.
| response = client.service.incentive.fetch_incentive(request_args) | ||
|
|
||
| # Processes the response. | ||
| if response.incentive_offer.nil? |
There was a problem hiding this comment.
When no incentive is available for a user, the API returns a populated IncentiveOffer with offer_type == :NO_INCENTIVE and cyo_incentives unset (nil). Currently, that case skips this nil? check and falls into the else branch on line 58 (printing 'Incentive offer is not a CHOOSE_YOUR_OWN_INCENTIVE type...').
Checking for :NO_INCENTIVE here handles empty offers accurately (and allows removing the redundant &. on line 49):
| if response.incentive_offer.nil? | |
| if response.incentive_offer.nil? || response.incentive_offer.offer_type == :NO_INCENTIVE |
| parser.parse! | ||
|
|
||
| # Check if required parameters are present. | ||
| if options[:email].to_s.empty? || options[:email] == 'INSERT_EMAIL_HERE' |
There was a problem hiding this comment.
Since fetch_incentive strips whitespace on line 32 (email.to_s.strip), using .strip.empty? here ensures whitespace-only input (e.g., -E " ") is caught during CLI validation rather than sending an empty email: "" to the API:
| if options[:email].to_s.empty? || options[:email] == 'INSERT_EMAIL_HERE' | |
| if options[:email].to_s.strip.empty? || options[:email] == 'INSERT_EMAIL_HERE' |
| @@ -0,0 +1,138 @@ | |||
| #!/usr/bin/env ruby | |||
There was a problem hiding this comment.
Since #!/usr/bin/env ruby and Usage: %s [options] are used for standalone execution, please chmod +x (100755) this file (currently committed with mode 100644). Also, # Encoding: utf-8 on line 2 is redundant in Ruby 2.0+ and can be removed.
| # Issues the request. | ||
| request_args = { | ||
| customer_id: customer_id.to_s.tr('-', ''), | ||
| selected_incentive_id: incentive_id&.to_i, |
There was a problem hiding this comment.
If apply_incentive is called programmatically with a non-numeric string (such as an unreplaced placeholder 'INSERT_INCENTIVE_ID_HERE'), incentive_id&.to_i silently coerces it to 0 (selected_incentive_id: 0). Using Integer(incentive_id) when incentive_id is present fails fast with an ArgumentError on invalid input:
| selected_incentive_id: incentive_id&.to_i, | |
| selected_incentive_id: incentive_id ? Integer(incentive_id) : nil, |
| exit 1 | ||
| end | ||
|
|
||
| if options[:country_code].to_s.empty? |
There was a problem hiding this comment.
Use .strip.empty? (and strip country_code in request_args on line 38) to guard against whitespace-only --country-code values:
| if options[:country_code].to_s.empty? | |
| if options[:country_code].to_s.strip.empty? |
…ssions, NO_INCENTIVE handling, and validation Change-Id: I3fc292a3b6a8f3180c12ede0f1e7982e32179b38
Change-Id: I57fa8a776fb8a1cbd43f6c1d3a1a71c3c63bdd19