공장

factories는 클라이언트 라이브러리로 작업과 리소스를 만들기 위한 상위 수준 인터페이스를 제공합니다.

팩토리 메서드는 Google Ads API에서 제공하는 모든 리소스, enum, 작업, 서비스 유형에 대해 자동으로 생성됩니다. 이 페이지의 예시에서는 GoogleAdsClient 인스턴스와 타겟 customer_id를 초기화했다고 가정합니다.

require 'google/ads/google_ads'

client = Google::Ads::GoogleAds::GoogleAdsClient.new
customer_id = '1234567890'

작업

이 라이브러리는 Google Ads API 작업을 위한 작업을 빌드하는 client.operation.create_resource.<resource_type>, client.operation.update_resource.<resource_type>, client.operation.remove_resource.<resource_type> 편의 메서드를 제공합니다.

다음 예에서는 캠페인 예산 리소스를 만듭니다.

campaign_budget_operation =
  client.operation.create_resource.campaign_budget do |budget|
    budget.name = "Interplanetary Budget #{(Time.new.to_f * 1000).to_i}"
    budget.delivery_method = :STANDARD
    budget.amount_micros = 500_000
  end

return_budget = client.service.campaign_budget.mutate_campaign_budgets(
  customer_id: customer_id,
  operations: [campaign_budget_operation]
)

블록에 제공된 객체 (budget)는 변경할 수 있는 CampaignBudget의 새 인스턴스이며 CampaignBudgetService의 적절한 생성 작업이 반환됩니다.

마찬가지로 라이브러리는 리소스 업데이트를 위한 편의 메서드를 제공합니다.

campaign_service = client.service.campaign

# If you only have a resource name:
update_operation =
  client.operation.update_resource.campaign(campaign_resource_name) do |camp|
    camp.status = :PAUSED
  end

campaign_service.mutate_campaigns(
  customer_id: customer_id,
  operations: [update_operation]
)

# If you have a full resource proto:
update_operation = client.operation.update_resource.campaign(campaign) do |camp|
  camp.name = "A different Cruise #{(Time.new.to_f * 1000).to_i}"
end

campaign_service.mutate_campaigns(
  customer_id: customer_id,
  operations: [update_operation]
)

이러한 호출은 Google Ads API에서 리소스를 업데이트하기 위해 미리 채워진 필드 마스크가 있는 형식이 올바른 업데이트 작업을 반환합니다.

다음 예에서는 리소스 경로를 사용하여 리소스를 삭제합니다.

campaign_service = client.service.campaign
remove_operation =
  client.operation.remove_resource.campaign(campaign_resource_name)
campaign_service.mutate_campaigns(
  customer_id: customer_id,
  operations: [remove_operation]
)

작업을 직접 처리하려면 원시 작업을 가져와 필드를 수동으로 채우면 됩니다.

operation = client.operation.campaign

리소스

이 라이브러리는 리소스 객체를 초기화하는 client.resource.<resource_type>를 제공합니다.

campaign.network_settings = client.resource.network_settings do |ns|
  ns.target_google_search = true
  ns.target_search_network = true
  ns.target_content_network = false
  ns.target_partner_search_network = false
end

요청된 리소스 유형의 새 인스턴스가 필드를 설정하기 위해 전달된 블록에 제공됩니다.

서비스

이 라이브러리는 서비스 클라이언트 객체를 가져오는 client.service.<service_name>를 제공합니다.

campaign_service = client.service.campaign

열거형

기본적으로 enum 필드를 설정하려면 기호 문법을 사용합니다 (예: campaign.status = :PAUSED). enum의 모든 유효한 값을 열거하려면 client.enum 팩토리를 사용합니다.

client.enum.ad_type.each { |ad_type| p ad_type }
# Output:
# :UNSPECIFIED
# :UNKNOWN
# :TEXT_AD
# :EXPANDED_TEXT_AD
# :EXPANDED_DYNAMIC_SEARCH_AD
# :HOTEL_AD
# :SHOPPING_SMART_AD
# :SHOPPING_PRODUCT_AD
# :VIDEO_AD
# :IMAGE_AD
# :RESPONSIVE_SEARCH_AD
# :LEGACY_RESPONSIVE_DISPLAY_AD
# :APP_AD
# :LEGACY_APP_INSTALL_AD
# :RESPONSIVE_DISPLAY_AD
# :LOCAL_AD
# :HTML5_UPLOAD_AD
# :DYNAMIC_HTML5_AD
# :APP_ENGAGEMENT_AD
# :SHOPPING_COMPARISON_LISTING_AD
# :VIDEO_BUMPER_AD
# :VIDEO_NON_SKIPPABLE_IN_STREAM_AD
# :VIDEO_TRUEVIEW_IN_STREAM_AD
# :VIDEO_RESPONSIVE_AD
# :SMART_CAMPAIGN_AD
# :CALL_AD
# :APP_PRE_REGISTRATION_AD
# :IN_FEED_VIDEO_AD
# :DEMAND_GEN_MULTI_ASSET_AD
# :DEMAND_GEN_CAROUSEL_AD
# :TRAVEL_AD
# :DEMAND_GEN_VIDEO_RESPONSIVE_AD
# :DEMAND_GEN_PRODUCT_AD
# :YOUTUBE_AUDIO_AD

Google Ads API 버전을 명시적으로 설정

팩토리 호출 (예: v25)에서 주요 API 버전을 명시적으로 설정할 수도 있습니다. v25.1과 같은 부 API 출시에서는 주요 버전 메서드 v25를 사용합니다.

client.resource.v25.[entity]
client.operation.v25.[operation]
client.service.v25.[service]
client.enum.v25.[enum]