Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update V15 example ProductCategoryConstant #459

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example fetches the set of valid ProductBiddingCategories.
# This example fetches the set of all ProductCategoryConstants.

require 'optparse'
require 'google/ads/google_ads'
Expand All @@ -32,19 +32,17 @@ def display_categories(categories, prefix: '')
end
end

def get_product_bidding_category_constant(customer_id)
def get_product_category_constant(customer_id)
# GoogleAdsClient will read a config file from
# ENV['HOME']/google_ads_config.rb when called without parameters
client = Google::Ads::GoogleAds::GoogleAdsClient.new

query = <<~EOD
SELECT
product_bidding_category_constant.localized_name,
product_bidding_category_constant.product_bidding_category_constant_parent
product_category_constant.localizations,
product_category_constant.product_category_constant_parent
FROM
product_bidding_category_constant
WHERE
product_bidding_category_constant.country_code IN ('US')
product_category_constant
EOD

ga_service = client.service.google_ads
Expand All @@ -63,17 +61,17 @@ def get_product_bidding_category_constant(customer_id)
root_categories = Set.new

response.each do |row|
product_bidding_category = row.product_bidding_category_constant
product_category = row.product_category_constant
category = {
name: product_bidding_category.localized_name,
id: product_bidding_category.resource_name,
name: product_category.localizations,
jradcliff marked this conversation as resolved.
Show resolved Hide resolved
id: product_category.resource_name,
children: []
}

all_categories[category.fetch(:id)] = category

parent_id = product_bidding_category
.product_bidding_category_constant_parent
parent_id = product_category
.product_category_constant_parent

if parent_id
all_categories[parent_id][:children] << category
Expand Down Expand Up @@ -119,7 +117,7 @@ def get_product_bidding_category_constant(customer_id)
end.parse!

begin
get_product_bidding_category_constant(
get_product_category_constant(
options.fetch(:customer_id).tr("-", "")
)
rescue Google::Ads::GoogleAds::Errors::GoogleAdsError => e
Expand Down