Skip to content

Add incentives examples#554

Open
dorasun wants to merge 3 commits into
mainfrom
add_incentives_example
Open

Add incentives examples#554
dorasun wants to merge 3 commits into
mainfrom
add_incentives_example

Conversation

@dorasun

@dorasun dorasun commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Change-Id: I57fa8a776fb8a1cbd43f6c1d3a1a71c3c63bdd19

Change-Id: I57fa8a776fb8a1cbd43f6c1d3a1a71c3c63bdd19
@dorasun
dorasun requested a review from a team as a code owner July 15, 2026 18:19
@dorasun
dorasun requested review from Raibaz and sundquist July 15, 2026 18:19
Raibaz
Raibaz previously approved these changes Jul 16, 2026
Change-Id: I2f4db5b40ddc0494f631b62d60b6992f786cbf57
@dorasun
dorasun requested a review from bobhancockg July 17, 2026 19:32
@bobhancockg

Copy link
Copy Markdown
Contributor

Code Vetting & Review Recommendations

Overall, the implementation for adding incentive examples (apply_incentive.rb and fetch_incentive.rb) is well-structured. Below are recommended improvements to align with google-ads-ruby repository standards, fix documentation indexing tags, ensure type safety, and standardize monetary formatting.


1. examples/incentives/apply_incentive.rb

  • Default Parameter Value: Add country_code = nil to the method signature so calling apply_incentive(customer_id, incentive_id) programmatically works without explicitly passing nil:
    def apply_incentive(customer_id, incentive_id, country_code = nil)
  • Type Safety for selected_incentive_id: Explicitly call .to_i on incentive_id when constructing request_args for protobuf field type safety (int64):
    request_args = {
      customer_id: customer_id,
      selected_incentive_id: incentive_id.to_i
    }
  • CLI Default Initializers & Validation: Initialize options[:incentive_id] = 'INSERT_INCENTIVE_ID_HERE' at the top of if __FILE__ == $0 to match the doc comments, and update argument validation accordingly:
    options[:customer_id] = 'INSERT_CUSTOMER_ID_HERE'
    options[:incentive_id] = 'INSERT_INCENTIVE_ID_HERE'
    if options[:customer_id].nil? ||
        options[:customer_id] == 'INSERT_CUSTOMER_ID_HERE' ||
        options[:incentive_id].nil? ||
        options[:incentive_id] == 'INSERT_INCENTIVE_ID_HERE'
      puts 'Missing required arguments. See usage:'
      puts 'Customer ID and Incentive ID are required.'
      exit 1
    end

2. examples/incentives/fetch_incentive.rb

  • Documentation Region Tags: Add # [START fetch_incentive] and # [END fetch_incentive] region tags around the main method so Google Developers documentation (devsite) can automatically index the code snippet.
  • Standardize Currency Formatting in format_money: Simplify calculation to cleanly format zero, fractional, and negative currency values with standard 2 decimal places:
    def format_money(money)
      return 'N/A' if money.nil?
    
      amount = money.units.to_f + (money.nanos.to_f / 1_000_000_000.0)
      sprintf('%.2f %s', amount, money.currency_code)
    end
  • CLI Option Placeholder & Check: Initialize options[:email] = 'INSERT_EMAIL_HERE' and validate against INSERT_EMAIL_HERE in if __FILE__ == $0.

@@ -0,0 +1,115 @@
# frozen_string_literal: 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.

See comments on main page.

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.

3 participants