Conversation
This commit translates the Python examples for applying and fetching incentives into Ruby examples under `examples/incentives`. These match the existing coding styles of other examples. Co-authored-by: dorasun <10905385+dorasun@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| $stderr.printf("\tType: %s\n\tCode: %s\n", k, v) | ||
| end | ||
| end | ||
| raise |
There was a problem hiding this comment.
Consider adding a comment to explain why the error is re-raised or apply the comment from fetch_incentives.rb.
| require "google/ads/google_ads" | ||
|
|
||
| # [START fetch_incentives] | ||
| def fetch_incentives(email_address, language_code, country_code) |
There was a problem hiding this comment.
Dependency Injection: Instead of instantiating the client inside the method, pass it as an argument. This allows you to share one authenticated session across multiple API calls, reducing overhead.
| # incentives in the response. At the time this example was written, all | ||
| # incentive offers are CYO incentive offers. | ||
| cyo_incentives = response.incentive_offer.cyo_incentives | ||
| puts cyo_incentives.low_offer.inspect |
There was a problem hiding this comment.
Human-Readable Output: Replace .inspect with a helper method to print specific attributes like offer_id or expiration_date. Raw object inspection is difficult for end-users to parse."
| # code. | ||
| # | ||
| # Running the example with -h will print the command line usage. | ||
| options[:email_address] = "INSERT_EMAIL_ADDRESS_HERE" |
There was a problem hiding this comment.
Placeholder Check: Add a check to ensure the user actually replaced INSERT_EMAIL_ADDRESS_HERE. You could raise an error immediately if the string still contains 'INSERT' to prevent an unnecessary API round-trip.
| $stderr.printf("\tType: %s\n\tCode: %s\n", k, v) | ||
| end | ||
| end | ||
| raise |
There was a problem hiding this comment.
Error Bubbling: Instead of re-raising the raw GoogleAdsError, consider wrapping it in a domain-specific error (e.g., IncentiveFetchError). This makes it easier for higher-level services to catch and handle logic errors separately from network errors.
|
|
||
| response = client.service.incentive.apply_incentive(request_params) | ||
|
|
||
| puts "Applied incentive." |
There was a problem hiding this comment.
Conditional Feedback: The message 'Applied incentive' might be misleading if the user already had one (as per the header comments). Change this to 'Incentive details retrieved/applied' for better accuracy.
|
|
||
| puts "Applied incentive." | ||
| puts "Coupon Code: #{response.coupon_code}" | ||
| puts "Creation Time: #{response.creation_time}" |
There was a problem hiding this comment.
Date Formatting: The raw creation time might be a timestamp object. Formatting this (e.g., .strftime('%Y-%m-%d %H:%M:%S')) makes the console output much more readable.
| # code. | ||
| # | ||
| # Running the example with -h will print the command line usage. | ||
| options[:customer_id] = "INSERT_CUSTOMER_ID_HERE" |
There was a problem hiding this comment.
Safety Guard: Implement a check to ensure INSERT_ placeholders are replaced. Running this with dummy strings results in a wasted API call and a 400-range error.
|
|
||
| begin | ||
| apply_incentive( | ||
| options.fetch(:customer_id).tr("-", ""), |
There was a problem hiding this comment.
Input Sanitation: Moving the .tr("-", "") logic into a helper method or the apply_incentive method itself ensures consistency if you ever call this function from a different part of the app.
| $stderr.printf("\tOn field: %s\n", field_path_element.field_name) | ||
| end | ||
| error.error_code.to_h.each do |k, v| | ||
| next if v == :UNSPECIFIED |
There was a problem hiding this comment.
Detailed Logging: "In a production environment, you should log these errors to a persistent file (e.g., ads_api.log) rather than just printing to $stderr, which is lost after the terminal closes."
Translates the
fetch_incentives.pyandapply_incentive.pyexamples into Ruby under theexamples/incentivesdirectory. They feature standard boilerplate and argument parsing seen in other repository examples.PR created automatically by Jules for task 12559570931346782113 started by @dorasun