diff --git a/ruby/v3.3/.rubocop.yml b/ruby/v3.3/.rubocop.yml deleted file mode 100644 index c01887b..0000000 --- a/ruby/v3.3/.rubocop.yml +++ /dev/null @@ -1,11 +0,0 @@ -inherit_from: .rubocop_todo.yml - -Layout/AlignParameters: - EnforcedStyle: with_fixed_indentation - -Metrics/AbcSize: - Max: 25 - -Naming/AccessorMethodName: - Exclude: - - 'user_profiles/get_user_profiles.rb' \ No newline at end of file diff --git a/ruby/v3.3/.rubocop_todo.yml b/ruby/v3.3/.rubocop_todo.yml deleted file mode 100644 index ace8857..0000000 --- a/ruby/v3.3/.rubocop_todo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-02-04 15:29:22 +0900 using RuboCop version 0.61.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 64 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 46 - -# Offense count: 201 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Enabled: false diff --git a/ruby/v3.4/.rubocop.yml b/ruby/v3.4/.rubocop.yml deleted file mode 100644 index c01887b..0000000 --- a/ruby/v3.4/.rubocop.yml +++ /dev/null @@ -1,11 +0,0 @@ -inherit_from: .rubocop_todo.yml - -Layout/AlignParameters: - EnforcedStyle: with_fixed_indentation - -Metrics/AbcSize: - Max: 25 - -Naming/AccessorMethodName: - Exclude: - - 'user_profiles/get_user_profiles.rb' \ No newline at end of file diff --git a/ruby/v3.4/.rubocop_todo.yml b/ruby/v3.4/.rubocop_todo.yml deleted file mode 100644 index ace8857..0000000 --- a/ruby/v3.4/.rubocop_todo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-02-04 15:29:22 +0900 using RuboCop version 0.61.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 64 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 46 - -# Offense count: 201 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Enabled: false diff --git a/ruby/v3.5/.rubocop.yml b/ruby/v3.5/.rubocop.yml deleted file mode 100644 index c01887b..0000000 --- a/ruby/v3.5/.rubocop.yml +++ /dev/null @@ -1,11 +0,0 @@ -inherit_from: .rubocop_todo.yml - -Layout/AlignParameters: - EnforcedStyle: with_fixed_indentation - -Metrics/AbcSize: - Max: 25 - -Naming/AccessorMethodName: - Exclude: - - 'user_profiles/get_user_profiles.rb' \ No newline at end of file diff --git a/ruby/v3.5/.rubocop_todo.yml b/ruby/v3.5/.rubocop_todo.yml deleted file mode 100644 index ace8857..0000000 --- a/ruby/v3.5/.rubocop_todo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-02-04 15:29:22 +0900 using RuboCop version 0.61.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 64 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 46 - -# Offense count: 201 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Enabled: false diff --git a/ruby/v4/.rubocop.yml b/ruby/v4/.rubocop.yml deleted file mode 100644 index c01887b..0000000 --- a/ruby/v4/.rubocop.yml +++ /dev/null @@ -1,11 +0,0 @@ -inherit_from: .rubocop_todo.yml - -Layout/AlignParameters: - EnforcedStyle: with_fixed_indentation - -Metrics/AbcSize: - Max: 25 - -Naming/AccessorMethodName: - Exclude: - - 'user_profiles/get_user_profiles.rb' \ No newline at end of file diff --git a/ruby/v4/.rubocop_todo.yml b/ruby/v4/.rubocop_todo.yml deleted file mode 100644 index ace8857..0000000 --- a/ruby/v4/.rubocop_todo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-02-04 15:29:22 +0900 using RuboCop version 0.61.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 64 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 46 - -# Offense count: 201 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: - Enabled: false diff --git a/ruby/v4/Gemfile b/ruby/v4/Gemfile deleted file mode 100644 index f0babf7..0000000 --- a/ruby/v4/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'google-api-client', '0.53.0' -gem 'googleauth', '>= 0.5' -gem 'google-apis-dfareporting_v4', '~> 0.1.0' diff --git a/ruby/v4/Gemfile.lock b/ruby/v4/Gemfile.lock deleted file mode 100644 index ff8aab8..0000000 --- a/ruby/v4/Gemfile.lock +++ /dev/null @@ -1,86 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (7.0.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - concurrent-ruby (1.1.10) - declarative (0.0.20) - faraday (2.3.0) - faraday-net_http (~> 2.0) - ruby2_keywords (>= 0.0.4) - faraday-net_http (2.0.3) - gems (1.2.0) - google-api-client (0.53.0) - google-apis-core (~> 0.1) - google-apis-generator (~> 0.1) - google-apis-core (0.6.0) - addressable (~> 2.5, >= 2.5.1) - googleauth (>= 0.16.2, < 2.a) - httpclient (>= 2.8.1, < 3.a) - mini_mime (~> 1.0) - representable (~> 3.0) - retriable (>= 2.0, < 4.a) - rexml - webrick - google-apis-dfareporting_v4 (0.1.0) - google-apis-core (>= 0.5, < 2.a) - google-apis-discovery_v1 (0.9.0) - google-apis-core (>= 0.5, < 2.a) - google-apis-generator (0.6.0) - activesupport (>= 5.0) - gems (~> 1.2) - google-apis-core (>= 0.5, < 2.a) - google-apis-discovery_v1 (~> 0.5) - thor (>= 0.20, < 2.a) - googleauth (1.1.3) - faraday (>= 0.17.3, < 3.a) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (>= 0.16, < 2.a) - httpclient (2.8.3) - i18n (1.10.0) - concurrent-ruby (~> 1.0) - jwt (2.4.1) - memoist (0.16.2) - mini_mime (1.1.2) - minitest (5.16.0) - multi_json (1.15.0) - os (1.1.4) - public_suffix (4.0.7) - representable (3.2.0) - declarative (< 0.1.0) - trailblazer-option (>= 0.1.1, < 0.2.0) - uber (< 0.2.0) - retriable (3.1.2) - rexml (3.2.5) - ruby2_keywords (0.0.5) - signet (0.16.1) - addressable (~> 2.8) - faraday (>= 0.17.5, < 3.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - thor (1.2.1) - trailblazer-option (0.1.2) - tzinfo (2.0.4) - concurrent-ruby (~> 1.0) - uber (0.1.0) - webrick (1.7.0) - -PLATFORMS - universal-darwin-20 - x86_64-linux - -DEPENDENCIES - google-api-client (= 0.53.0) - google-apis-dfareporting_v4 (~> 0.1.0) - googleauth (>= 0.5) - -BUNDLED WITH - 2.2.18 diff --git a/ruby/v4/README.md b/ruby/v4/README.md deleted file mode 100644 index 58b8c58..0000000 --- a/ruby/v4/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# DCM/DFA Reporting and Trafficking API Ruby Samples - -This is a collection of samples written in Ruby which provide a starting place -for your experimentation into the DCM/DFA Reporting and Trafficking API. - -## Prerequisites - -Please make sure that you're running Ruby 1.9+ and you've run -`bundle install` on the example directory to install all prerequisites. - -## Setup Authentication - -This API uses OAuth 2.0. Learn more about Google APIs and OAuth 2.0 here: -https://developers.google.com/accounts/docs/OAuth2 - -Or, if you'd like to dive right in, follow these steps. - - Visit https://console.developers.google.com to register your application. - - From the API Manager -> Google APIs screen, activate access to "DCM/DFA Reporting and Trafficking API". - - Click on "Credentials" in the left navigation menu - - Click the button labeled "Create credentials" and select "OAuth Client ID" - - Select "Other" as the "Application type", then "Create" - - From the Credentials page, click "Download JSON" next to the client ID you just created and save the file as `client_secrets.json` in the samples project directory - -## Running the Examples - -I'm assuming you've checked out the code and are reading this from a local -directory. If not check out the code to a local directory. - -1. Start up a sample, e.g. - - $ bundle exec ruby create_report.rb - -2. Complete the authorization steps on your browser - -3. Examine your shell output, be inspired and start hacking an amazing new app! diff --git a/ruby/v4/ads/create_rotation_group.rb b/ruby/v4/ads/create_rotation_group.rb deleted file mode 100755 index dda13a5..0000000 --- a/ruby/v4/ads/create_rotation_group.rb +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a rotation group ad in a given campaign. - -require_relative '../dfareporting_utils' - -def create_rotation_group(profile_id, campaign_id, placement_id, creative_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Retrieve the campaign (to get end date). - campaign = service.get_campaign(profile_id, campaign_id) - - # Construct creative assignment. - creative_assignment = - DfareportingUtils::API_NAMESPACE::CreativeAssignment.new( - active: true, - creative_id: creative_id, - click_through_url: DfareportingUtils::API_NAMESPACE::ClickThroughUrl.new( - default_landing_page: true - ) - ) - - # Construct placement assignment. - placement_assignment = - DfareportingUtils::API_NAMESPACE::PlacementAssignment.new( - active: true, - placement_id: placement_id - ) - - # Construct creative rotation. - creative_rotation = DfareportingUtils::API_NAMESPACE::CreativeRotation.new( - creative_assignments: [creative_assignment], - type: 'CREATIVE_ROTATION_TYPE_RANDOM', - weight_calculation_strategy: 'WEIGHT_STRATEGY_OPTIMIZED' - ) - - # Construct delivery schedule. - delivery_schedule = DfareportingUtils::API_NAMESPACE::DeliverySchedule.new( - impression_ratio: 1, - priority: 'AD_PRIORITY_01' - ) - - # Construct and save ad. - ad = DfareportingUtils::API_NAMESPACE::Ad.new( - active: true, - campaign_id: campaign_id, - creative_rotation: creative_rotation, - delivery_schedule: delivery_schedule, - end_time: format('%sT00:00:00Z', campaign.end_date), - name: 'Example Rotation Group', - placement_assignments: [placement_assignment], - start_time: format('%sT23:59:59Z', Time.now.strftime('%Y-%m-%d')), - type: 'AD_SERVING_STANDARD_AD' - ) - - result = service.insert_ad(profile_id, ad) - - puts format('Created rotation group with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id, - :placement_id, :creative_id) - - create_rotation_group(args[:profile_id], args[:campaign_id], - args[:placement_id], args[:creative_id]) -end diff --git a/ruby/v4/ads/get_ads.rb b/ruby/v4/ads/get_ads.rb deleted file mode 100755 index 642d565..0000000 --- a/ruby/v4/ads/get_ads.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all active ads your DCM user profile can see. -# -# Only name and ID are returned. - -require_relative '../dfareporting_utils' - -def get_ads(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_ads(profile_id, - page_token: token, - fields: 'nextPageToken,ads(id,name)') - - # Display results. - if result.ads.any? - result.ads.each do |ad| - puts format('Found ad with ID %d and name "%s".', ad.id, ad.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_ads(args[:profile_id]) -end diff --git a/ruby/v4/advertisers/assign_advertiser_to_advertiser_group.rb b/ruby/v4/advertisers/assign_advertiser_to_advertiser_group.rb deleted file mode 100755 index f6543c5..0000000 --- a/ruby/v4/advertisers/assign_advertiser_to_advertiser_group.rb +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example assigns an advertiser to an advertiser group. -# -# CAUTION: An advertiser that has campaigns associated with it cannot be -# removed from an advertiser group once assigned. - -require_relative '../dfareporting_utils' - -def assign_advertiser_to_advertiser_group(profile_id, advertiser_id, - advertiser_group_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a the advertiser group association to patch. - advertiser = DfareportingUtils::API_NAMESPACE::Advertiser.new( - advertiser_group_id: advertiser_group_id - ) - - # Patch the advertiser group association. - result = service.patch_advertiser(profile_id, advertiser_id, advertiser) - - # Display results - puts format('Assigned advertiser with ID %d to advertiser group with ID %d.', - result.id, result.advertiser_group_id) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :advertiser_group_id) - - assign_advertiser_to_advertiser_group(args[:profile_id], - args[:advertiser_id], args[:advertiser_group_id]) -end diff --git a/ruby/v4/advertisers/create_advertiser.rb b/ruby/v4/advertisers/create_advertiser.rb deleted file mode 100755 index 0e1eb29..0000000 --- a/ruby/v4/advertisers/create_advertiser.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an advertiser in a given DCM account. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_advertiser(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new advertiser resource to insert. - advertiser = DfareportingUtils::API_NAMESPACE::Advertiser.new( - name: format('Example Advertiser #%s', SecureRandom.hex(3)), - status: 'APPROVED' - ) - - # Insert the advertiser. - result = service.insert_advertiser(profile_id, advertiser) - - # Display results. - puts format('Created advertiser with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - create_advertiser(args[:profile_id]) -end diff --git a/ruby/v4/advertisers/create_advertiser_group.rb b/ruby/v4/advertisers/create_advertiser_group.rb deleted file mode 100755 index a74ea38..0000000 --- a/ruby/v4/advertisers/create_advertiser_group.rb +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an advertiser group. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_advertiser_group(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new advertiser group resource to insert. - advertiser_group = DfareportingUtils::API_NAMESPACE::AdvertiserGroup.new( - name: format('Example Advertiser Group #%s', SecureRandom.hex(3)) - ) - - # Insert the advertiser group. - result = service.insert_advertiser_group(profile_id, advertiser_group) - - # Display results. - puts format('Created advertiser group with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - create_advertiser_group(args[:profile_id]) -end diff --git a/ruby/v4/advertisers/create_advertiser_landing_page.rb b/ruby/v4/advertisers/create_advertiser_landing_page.rb deleted file mode 100755 index 809eda5..0000000 --- a/ruby/v4/advertisers/create_advertiser_landing_page.rb +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an advertiser landing page. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_advertiser_landing_page(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new landing page resource to insert. - landing_page = DfareportingUtils::API_NAMESPACE::LandingPage.new( - advertiser_id: advertiser_id, - archived: false, - name: format('Example Advertiser Landing Page #%s', SecureRandom.hex(3)), - url: 'https://www.google.com' - ) - - # Insert the advertiser landing page. - result = service.insert_advertiser_landing_page(profile_id, landing_page) - - # Display results. - puts format('Created advertiser landing page with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_advertiser_landing_page(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/advertisers/get_advertiser_groups.rb b/ruby/v4/advertisers/get_advertiser_groups.rb deleted file mode 100755 index a4fe958..0000000 --- a/ruby/v4/advertisers/get_advertiser_groups.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all advertiser groups for the specified user profile. - -require_relative '../dfareporting_utils' - -def get_advertiser_groups(profile_id) - # Authenticate and initialize API service - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_advertiser_groups(profile_id, - page_token: token, - fields: 'nextPageToken,advertiserGroups(id,name)') - - # Display results. - if result.advertiser_groups.any? - result.advertiser_groups.each do |group| - puts format('Found advertiser group with ID %d and name "%s".', - group.id, group.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_advertiser_groups(args[:profile_id]) -end diff --git a/ruby/v4/advertisers/get_advertiser_landing_pages.rb b/ruby/v4/advertisers/get_advertiser_landing_pages.rb deleted file mode 100755 index 2db2713..0000000 --- a/ruby/v4/advertisers/get_advertiser_landing_pages.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all advertiser landing pages for the specified user -# profile. - -require_relative '../dfareporting_utils' - -def get_advertiser_landing_pages(profile_id, advertiser_id) - # Authenticate and initialize API service - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_advertiser_landing_pages(profile_id, - advertiser_ids: [advertiser_id], - page_token: token, - fields: 'nextPageToken,landingPages(id,name)') - - # Display results. - if result.landing_pages.any? - result.landing_pages.each do |landing_page| - puts format('Found advertiser landing page with ID %d and name "%s".', - landing_page.id, landing_page.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_advertiser_landing_pages(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/advertisers/get_advertisers.rb b/ruby/v4/advertisers/get_advertisers.rb deleted file mode 100755 index 9f97fb8..0000000 --- a/ruby/v4/advertisers/get_advertisers.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all advertisers. - -require_relative '../dfareporting_utils' - -def get_advertisers(profile_id) - # Authenticate and initialize API service - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_advertisers(profile_id, - page_token: token, - fields: 'nextPageToken,advertisers(id,name)') - - # Display results. - if result.advertisers.any? - result.advertisers.each do |advertiser| - puts format('Found advertiser with ID %d and name "%s".', - advertiser.id, advertiser.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_advertisers(args[:profile_id]) -end diff --git a/ruby/v4/auth/authenticate_using_service_account.rb b/ruby/v4/auth/authenticate_using_service_account.rb deleted file mode 100755 index c261515..0000000 --- a/ruby/v4/auth/authenticate_using_service_account.rb +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example demonstrates how to authenticate using a service account. -# -# An optional Google account email to impersonate may be specified as follows: -# authenticate_using_service_account.rb --i -# -# This optional flag only applies to service accounts which have domain-wide -# delegation enabled and wish to make API requests on behalf of an account -# within that domain. Using this flag will not allow you to impersonate a -# user from a domain you don't own (e.g., gmail.com). - -require 'google/apis/dfareporting_v4' -require 'googleauth' -require 'optparse' - -API_NAMESPACE = Google::Apis::DfareportingV4 - -def authenticate_using_service_account(path_to_json_file, impersonation_email) - # Create a Dfareporting service object. - # - # Note: application name should be replaced with a value that identifies - # your application. Suggested format is "MyCompany-ProductName". - service = API_NAMESPACE::DfareportingService.new - service.client_options.application_name = 'Ruby service account sample' - service.client_options.application_version = '1.0.0' - - # Generate an authorization object from the specified JSON file. - File.open(path_to_json_file, 'r+') do |json| - service.authorization = - Google::Auth::ServiceAccountCredentials.make_creds( - json_key_io: json, - scope: [API_NAMESPACE::AUTH_DFAREPORTING] - ) - end - - # Configure impersonation (if applicable). - service.authorization.sub = impersonation_email unless - impersonation_email.nil? - - service -end - -def get_userprofiles(service) - # Get all user profiles. - result = service.list_user_profiles - - # Display results. - result.items.each do |profile| - puts format( - 'User profile with ID %d and name "%s" was found for account %d.', - profile.profile_id, profile.user_name, profile.account_id - ) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - impersonation_email = nil - optparse = OptionParser.new do |opts| - opts.banner = format('Usage: %s path_to_json_file [options]', $PROGRAM_NAME) - opts.on_tail('-i', '--impersonate EMAIL', - 'Google account email to impersonate') do |email| - impersonation_email = email - end - end - optparse.parse! - - if ARGV.empty? - puts optparse - exit(-1) - end - - # Authenticate and initialize API service using service account. - service = authenticate_using_service_account(ARGV.shift, impersonation_email) - - get_userprofiles(service) -end diff --git a/ruby/v4/auth/authenticate_using_user_account.rb b/ruby/v4/auth/authenticate_using_user_account.rb deleted file mode 100755 index af5fbce..0000000 --- a/ruby/v4/auth/authenticate_using_user_account.rb +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example demonstrates how to authenticate using a user account, via the -# OAuth 2.0 installed application flow. - -require 'google/apis/dfareporting_v4' -require 'googleauth' -require 'googleauth/stores/file_token_store' - -API_NAMESPACE = Google::Apis::DfareportingV4 - -# This redirect URI allows you to copy the token from the success screen. -OAUTH_REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze - -# Location where authorization credentials will be cached. -TOKEN_STORE_DIR = File.join(File.dirname(__FILE__), 'auth-sample.yaml') - -def authenticate_using_user_account(path_to_json_file, token_store) - # Load client ID from the specified file. - client_id = Google::Auth::ClientId.from_file(path_to_json_file) - - # Set up the user authorizer. - # - # Note: providing a token store allows auth credentials to be cached, so they - # survive multiple runs of the application. This avoids prompting the user for - # authorization every time the access token expires, by remembering the - # refresh token. - authorizer = Google::Auth::UserAuthorizer.new( - client_id, [API_NAMESPACE::AUTH_DFAREPORTING], token_store - ) - - # Authorize and persist credentials to the data store. - # - # Note: the 'user' value below is used to identify a specific set of - # credentials in the token store. You may provide different values here to - # persist credentials for multiple users to the same token store. - authorization = authorizer.get_credentials('user') - if authorization.nil? - puts format( - "Open this URL in your browser and authorize the application.\n\n%s" \ - "\n\nEnter the authorization code:", - authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI) - ) - code = STDIN.gets.chomp - authorization = authorizer.get_and_store_credentials_from_code( - base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'user' - ) - end - - authorization -end - -def create_dfareporting_service_instance(authorization) - # Create a Dfareporting service object. - # - # Note: application name should be replaced with a value that identifies - # your application. Suggested format is "MyCompany-ProductName". - service = API_NAMESPACE::DfareportingService.new - service.authorization = authorization - service.client_options.application_name = 'Ruby installed app sample' - service.client_options.application_version = '1.0.0' - - service -end - -def get_userprofiles(service) - # Get all user profiles. - result = service.list_user_profiles - - # Display results. - result.items.each do |profile| - puts format( - 'User profile with ID %d and name "%s" was found for account %d.', - profile.profile_id, profile.user_name, profile.account_id - ) - end -end - -if $PROGRAM_NAME == __FILE__ - if ARGV.empty? - puts format('Usage: %s path_to_json_file', $PROGRAM_NAME) - exit(-1) - end - - # Authenticate using user account. - authorization = authenticate_using_user_account( - ARGV.shift, - Google::Auth::Stores::FileTokenStore.new(file: TOKEN_STORE_DIR) - ) - - # Initialize API service, - service = create_dfareporting_service_instance(authorization) - - get_userprofiles(service) -end diff --git a/ruby/v4/campaigns/create_campaign.rb b/ruby/v4/campaigns/create_campaign.rb deleted file mode 100755 index 4feceb4..0000000 --- a/ruby/v4/campaigns/create_campaign.rb +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a campaign in a given advertiser. -# -# To create an advertiser, run create_advertiser.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_campaign(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Locate an advertiser landing page to use as a default. - default_landing_page = get_advertiser_landing_page(service, profile_id, - advertiser_id) - - # Create a new campaign resource to insert. - campaign = DfareportingUtils::API_NAMESPACE::Campaign.new( - advertiser_id: advertiser_id, - archived: false, - default_landing_page_id: default_landing_page.id, - name: format('Example Campaign #%s', SecureRandom.hex(3)), - start_date: '2014-01-01', - end_date: '2020-01-01' - ) - - # Insert the campaign. - result = service.insert_campaign(profile_id, campaign) - - # Display results. - puts format('Created campaign with ID %d and name "%s".', result.id, - result.name) -end - -def get_advertiser_landing_page(service, profile_id, advertiser_id) - # Retrieve a sigle landing page from the specified advertiser. - result = service.list_advertiser_landing_pages(profile_id, - advertiser_ids: [advertiser_id], - max_results: 1) - - if result.landing_pages.none? - abort format('No landing pages for for advertiser with ID %d', - advertiser_id) - end - - result.landing_pages[0] -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_campaign(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/campaigns/create_campaign_event_tag.rb b/ruby/v4/campaigns/create_campaign_event_tag.rb deleted file mode 100755 index 18d221e..0000000 --- a/ruby/v4/campaigns/create_campaign_event_tag.rb +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a creative field associated with a given advertiser. -# -# To get an advertiser ID, run get_advertisers.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_campaign_event_tag(profile_id, campaign_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new event tag resource to insert. - event_tag = DfareportingUtils::API_NAMESPACE::EventTag.new( - campaign_id: campaign_id, - name: format('Example Campaign Event Tag #%s', SecureRandom.hex(3)), - status: 'ENABLED', - type: 'CLICK_THROUGH_EVENT_TAG', - url: 'https://www.google.com' - ) - - # Insert the event tag. - result = service.insert_event_tag(profile_id, event_tag) - - # Display results. - puts format('Created campaign event tag with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id) - - create_campaign_event_tag(args[:profile_id], args[:campaign_id]) -end diff --git a/ruby/v4/campaigns/get_campaigns.rb b/ruby/v4/campaigns/get_campaigns.rb deleted file mode 100755 index 81fa930..0000000 --- a/ruby/v4/campaigns/get_campaigns.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all existing campaigns for the specified user profile. - -require_relative '../dfareporting_utils' - -def get_campaigns(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_campaigns(profile_id, - page_token: token, - fields: 'nextPageToken,campaigns(id,name)') - - # Display results. - if result.campaigns.any? - result.campaigns.each do |campaign| - puts format('Found campaign with ID %d and name "%s".', campaign.id, - campaign.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_campaigns(args[:profile_id]) -end diff --git a/ruby/v4/conversions/insert_offline_mobile_conversion.rb b/ruby/v4/conversions/insert_offline_mobile_conversion.rb deleted file mode 100755 index 5cbafdb..0000000 --- a/ruby/v4/conversions/insert_offline_mobile_conversion.rb +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example inserts an offline conversion attributed to a mobile device ID. - -require_relative '../dfareporting_utils' -require 'date' - -def insert_offline_mobile_conversion(profile_id, mobile_device_id, - floodlight_activity_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.get_floodlight_activity(profile_id, - floodlight_activity_id) - floodlight_config_id = floodlight_activity.floodlight_configuration_id - - current_time_in_micros = DateTime.now.strftime('%Q').to_i * 1000 - - # Construct the conversion. - conversion = DfareportingUtils::API_NAMESPACE::Conversion.new( - floodlight_activity_id: floodlight_activity_id, - floodlight_configuration_id: floodlight_config_id, - ordinal: current_time_in_micros, - mobile_device_id: mobile_device_id, - timestamp_micros: current_time_in_micros - ) - - # Construct the batch insert request. - batch_insert_request = - DfareportingUtils::API_NAMESPACE::ConversionsBatchInsertRequest.new( - conversions: [conversion] - ) - - # Insert the conversion. - result = service.batchinsert_conversion(profile_id, batch_insert_request) - - process_response(result) -end - -def process_response(result) - if result.has_failures - puts format('Error(s) inserting conversion for mobile device ID %s.', - mobile_device_id) - - status = result.status[0] - status.errors.each do |error| - puts format("\t[%s]: %s", error.code, error.message) - end - else - puts format('Successfully inserted conversion for mobile device ID %s.', - mobile_device_id) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :mobile_device_id, - :floodlight_activity_id) - - insert_offline_mobile_conversion(args[:profile_id], args[:mobile_device_id], - args[:floodlight_activity_id]) -end diff --git a/ruby/v4/conversions/insert_offline_user_conversion.rb b/ruby/v4/conversions/insert_offline_user_conversion.rb deleted file mode 100755 index 7f03ea9..0000000 --- a/ruby/v4/conversions/insert_offline_user_conversion.rb +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example inserts an offline conversion attributed to an encrypted user -# ID. - -require_relative '../dfareporting_utils' -require 'date' - -# Inserts an offline user conversions with the specified values. -# -# @param profile_id [Number] The ID of the DCM user issuing this request. -# @param encrypted_user_id [String] The encrypted user ID to which the -# conversion should be attributed. -# @param floodlight_activity_id [Number] The Floodlight activity ID to which -# the conversion should be attributed. -# @param encryption [Object] A hash containing the values used to encrypt the -# specified user ID. The expected format is: -# { -# source: , -# entity_id: , -# entity_type: -# } -def insert_offline_user_conversion(profile_id, encrypted_user_id, - floodlight_activity_id, encryption = {}) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.get_floodlight_activity(profile_id, - floodlight_activity_id) - floodlight_config_id = floodlight_activity.floodlight_configuration_id - - current_time_in_micros = DateTime.now.strftime('%Q').to_i * 1000 - - # Construct the conversion. - conversion = DfareportingUtils::API_NAMESPACE::Conversion.new( - encrypted_user_id: encrypted_user_id, - floodlight_activity_id: floodlight_activity_id, - floodlight_configuration_id: floodlight_config_id, - ordinal: current_time_in_micros, - timestamp_micros: current_time_in_micros - ) - - # Construct the encryption info. - encryption_info = DfareportingUtils::API_NAMESPACE::EncryptionInfo.new( - encryption_entity_id: encryption[:entity_id], - encryption_entity_type: encryption[:entity_type], - encryption_source: encryption[:source] - ) - - # Construct the batch insert request. - batch_insert_request = - DfareportingUtils::API_NAMESPACE::ConversionsBatchInsertRequest.new( - conversions: [conversion], - encryption_info: encryption_info - ) - - # Insert the conversion. - result = service.batchinsert_conversion(profile_id, batch_insert_request) - - process_response(result) -end - -def process_response(result) - if result.has_failures - puts format('Error(s) inserting conversion for encrypted user ID %s.', - encrypted_user_id) - - status = result.status[0] - status.errors.each do |error| - puts format("\t[%s]: %s", error.code, error.message) - end - else - puts format('Successfully inserted conversion for encrypted user ID %s.', - encrypted_user_id) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, - :encrypted_user_id, :encryption_source, :encryption_entity_id, - :encryption_entity_type, :floodlight_activity_id) - - insert_offline_user_conversion(args[:profile_id], args[:encrypted_user_id], - args[:floodlight_activity_id], - source: args[:encryption_source], - entity_id: args[:encryption_entity_id], - entity_type: args[:encryption_entity_type]) -end diff --git a/ruby/v4/conversions/update_offline_mobile_conversion.rb b/ruby/v4/conversions/update_offline_mobile_conversion.rb deleted file mode 100755 index 6e1cb75..0000000 --- a/ruby/v4/conversions/update_offline_mobile_conversion.rb +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example updates an offline conversion attributed to a mobile device ID. -# -# To create a conversion attributed to a mobile device ID, run -# insert_offline_mobile_conversion.rb. - -require_relative '../dfareporting_utils' - -# Updates an offline mobile conversion with the specified values. -# -# @param profile_id [Number] The ID of the DCM user issuing this request. -# @param new_quantity [Number] The new quantity value to assign to the -# specified conversion. -# @param new_value [Number] The new value to assign to the specified -# conversion. -# @param existing_conversion [Object] A hash containing values that identify -# an existing offline mobile conversion. The expected format is: -# { -# mobile_device_id: , -# floodlight_activity_id: , -# ordinal: , -# timestamp: -# } -def update_offline_mobile_conversion(profile_id, new_quantity, new_value, - existing_conversion = {}) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.get_floodlight_activity(profile_id, - existing_conversion[:floodlight_activity_id]) - floodlight_config_id = floodlight_activity.floodlight_configuration_id - - # Construct the conversion with values that identify the conversion to - # update - conversion = DfareportingUtils::API_NAMESPACE::Conversion.new( - floodlight_activity_id: existing_conversion[:floodlight_activity_id], - floodlight_configuration_id: floodlight_config_id, - ordinal: existing_conversion[:ordinal], - mobile_device_id: existing_conversion[:mobile_device_id], - timestamp_micros: existing_conversion[:timestamp] - ) - - # Set the fields to be updated. These fields are required; to preserve a - # value from the existing conversion, it must be copied over manually. - conversion.quantity = new_quantity - conversion.value = new_value - - # Construct the batch update request. - batch_update_request = - DfareportingUtils::API_NAMESPACE::ConversionsBatchUpdateRequest.new( - conversions: [conversion] - ) - - # Update the conversion. - result = service.batchupdate_conversion(profile_id, batch_update_request) - - process_response(result) -end - -def process_response(result) - if result.has_failures - puts format('Error(s) updating conversion for mobile device ID %s.', - existing_conversion[:mobile_device_id]) - - status = result.status[0] - status.errors.each do |error| - puts format("\t[%s]: %s", error.code, error.message) - end - else - puts format('Successfully updated conversion for mobile device ID %s.', - existing_conversion[:mobile_device_id]) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :mobile_device_id, - :floodlight_activity_id, :ordinal, :timestamp, :new_quantity, :new_value) - - update_offline_mobile_conversion( - args[:profile_id], args[:new_quantity], args[:new_value], - mobile_device_id: args[:mobile_device_id], - floodlight_activity_id: args[:floodlight_activity_id], - ordinal: args[:ordinal], - timestamp: args[:timestamp] - ) -end diff --git a/ruby/v4/conversions/update_offline_user_conversion.rb b/ruby/v4/conversions/update_offline_user_conversion.rb deleted file mode 100755 index c851938..0000000 --- a/ruby/v4/conversions/update_offline_user_conversion.rb +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example updates an offline conversion attributed to an encrypted user -# ID. -# -# To create a conversion attributed to an encrypted user ID, run -# insert_offline_user_conversion.rb. - -require_relative '../dfareporting_utils' - -# Updates an offline user conversion with the specified values. -# -# @param profile_id [Number] The ID of the DCM user issuing this request. -# @param new_quantity [Number] The new quantity value to assign to the -# specified conversion. -# @param new_value [Number] The new value to assign to the specified -# conversion. -# @param existing_conversion [Object] A hash containing values that identify -# an existing offline user conversion. The expected format is: -# { -# encrypted_user_id: , -# floodlight_activity_id: , -# ordinal: , -# timestamp: -# } -# @param encryption [Object] A hash containing the values used to encrypt the -# existing user conversion. The expected format is: -# { -# source: , -# entity_id: , -# entity_type: -# } -def update_offline_user_conversion(profile_id, new_quantity, new_value, - existing_conversion = {}, encryption = {}) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.get_floodlight_activity(profile_id, - existing_conversion[:floodlight_activity_id]) - floodlight_config_id = floodlight_activity.floodlight_configuration_id - - # Construct the conversion with values that identify the conversion to - # update. - conversion = DfareportingUtils::API_NAMESPACE::Conversion.new( - encrypted_user_id: existing_conversion[:encrypted_user_id], - floodlight_activity_id: existing_conversion[:floodlight_activity_id], - floodlight_configuration_id: floodlight_config_id, - ordinal: existing_conversion[:ordinal], - timestamp_micros: existing_conversion[:timestamp] - ) - - # Set the fields to be updated. These fields are required; to preserve a - # value from the existing conversion, it must be copied over manually. - conversion.quantity = new_quantity - conversion.value = new_value - - # Construct the encryption info. - encryption_info = DfareportingUtils::API_NAMESPACE::EncryptionInfo.new( - encryption_entity_id: encryption[:entity_id], - encryption_entity_type: encryption[:entity_type], - encryption_source: encryption[:source] - ) - - # Construct the batch update request. - batch_update_request = - DfareportingUtils::API_NAMESPACE::ConversionsBatchUpdateRequest.new( - conversions: [conversion], - encryption_info: encryption_info - ) - - # Update the conversion. - result = service.batchupdate_conversion(profile_id, batch_update_request) - - process_response(result) -end - -def process_response(result) - if result.has_failures - puts format('Error(s) updating conversion for encrypted user ID %s.', - existing_conversion[:encrypted_user_id]) - - status = result.status[0] - status.errors.each do |error| - puts format("\t[%s]: %s", error.code, error.message) - end - else - puts format('Successfully updated conversion for encrypted user ID %s.', - existing_conversion[:encrypted_user_id]) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, - :encrypted_user_id, :encryption_source, :encryption_entity_id, - :encryption_entity_type, :floodlight_activity_id, :ordinal, :timestamp, - :new_quantity, :new_value) - - update_offline_user_conversion( - args[:profile_id], args[:new_quantity], args[:new_value], - { - encrypted_user_id: args[:encrypted_user_id], - floodlight_activity_id: args[:floodlight_activity_id], - ordinal: args[:ordinal], - timestamp: args[:timestamp] - }, - source: args[:encryption_source], - entity_id: args[:encryption_entity_id], - entity_type: args[:encryption_entity_type] - ) -end diff --git a/ruby/v4/creative_asset_utils.rb b/ruby/v4/creative_asset_utils.rb deleted file mode 100755 index d4d112a..0000000 --- a/ruby/v4/creative_asset_utils.rb +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Utility class for handling common tasks related to working with creative -# assets. - -require_relative 'dfareporting_utils' - -# Creative asset utilities used by DFA Reporting and Trafficking API creative -# examples. -class CreativeAssetUtils - # Creates a new instance of CreativeAssetUtils. - def initialize(service, profile_id) - @service = service - @profile_id = profile_id - end - - # Uploads a creative asset and returns the creative asset metadata. - def upload_asset(advertiser_id, path_to_asset_file, asset_type) - asset_name = File.basename(path_to_asset_file) - - # Construct the creative asset metadata - creative_asset = DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: DfareportingUtils::API_NAMESPACE::CreativeAssetId.new( - name: asset_name, - type: asset_type - ) - ) - - # Upload the asset. - mime_type = determine_mime_type(path_to_asset_file, asset_type) - - result = @service.insert_creative_asset( - @profile_id, - advertiser_id, - creative_asset, - content_type: mime_type, - upload_source: path_to_asset_file - ) - - puts format('Creative asset was saved with name "%s".', - result.asset_identifier.name) - - result - end - - # Performs a naive mime-type lookup based on file name and asset type. - def determine_mime_type(path_to_asset_file, asset_type) - case asset_type - when 'IMAGE', 'HTML_IMAGE' - return format('image/%s', File.extname(path_to_asset_file)) - when 'VIDEO' - format('video/%s', File.extname(path_to_asset_file)) - else - 'application/octet-stream' - end - end -end diff --git a/ruby/v4/creatives/assign_creative_to_campaign.rb b/ruby/v4/creatives/assign_creative_to_campaign.rb deleted file mode 100755 index 142ad79..0000000 --- a/ruby/v4/creatives/assign_creative_to_campaign.rb +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example assigns a given creative to a given campaign. -# -# Note that both the creative and campaign must be associated with the same -# advertiser. - -require_relative '../dfareporting_utils' - -def assign_creative_to_campaign(profile_id, campaign_id, creative_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative-campaign association to insert - association = - DfareportingUtils::API_NAMESPACE::CampaignCreativeAssociation.new( - creative_id: creative_id - ) - - # Insert the advertiser group. - result = service.insert_campaign_creative_association(profile_id, campaign_id, - association) - - # Display results. - puts format('Creative with ID %d is now associated with campaign %d.', - result.creative_id, campaign_id) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id, - :creative_id) - - assign_creative_to_campaign(args[:profile_id], args[:campaign_id], - args[:creative_id]) -end diff --git a/ruby/v4/creatives/create_creative_field.rb b/ruby/v4/creatives/create_creative_field.rb deleted file mode 100755 index dd1e7d9..0000000 --- a/ruby/v4/creatives/create_creative_field.rb +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a creative field associated with a given advertiser. -# -# To get an advertiser ID, run get_advertisers.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_creative_field(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative field resource to insert, - creative_field = DfareportingUtils::API_NAMESPACE::CreativeField.new( - advertiser_id: advertiser_id, - name: format('Example Creative Field #%s', SecureRandom.hex(3)) - ) - - # Insert the creative field, - result = service.insert_creative_field(profile_id, creative_field) - - # Display results, - puts format('Created creative field with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments, - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_creative_field(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/creatives/create_creative_field_value.rb b/ruby/v4/creatives/create_creative_field_value.rb deleted file mode 100755 index 8daf06a..0000000 --- a/ruby/v4/creatives/create_creative_field_value.rb +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a creative field value for a given creative field. -# -# To get the creative field ID, run get_creative_fields.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_creative_field_value(profile_id, field_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative field value resource to insert. - field_value = DfareportingUtils::API_NAMESPACE::CreativeFieldValue.new( - value: format('Example Creative Field Value #%s', SecureRandom.hex(3)) - ) - - # Insert the creative field value. - result = service.insert_creative_field_value(profile_id, field_id, - field_value) - - # Display results. - puts format('Created creative field value with ID %d and value "%s".', - result.id, result.value) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :field_id) - - create_creative_field_value(args[:profile_id], args[:field_id]) -end diff --git a/ruby/v4/creatives/create_creative_group.rb b/ruby/v4/creatives/create_creative_group.rb deleted file mode 100755 index 41f3054..0000000 --- a/ruby/v4/creatives/create_creative_group.rb +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a creative group associated with a given advertiser. -# -# To get an advertiser ID, run get_advertisers.rb. Valid group numbers are -# limited to 1 or 2. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_creative_group(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative group resource to insert. - creative_group = DfareportingUtils::API_NAMESPACE::CreativeGroup.new( - advertiser_id: advertiser_id, - group_number: 1, - name: format('Example Creative Group #%s', SecureRandom.hex(3)) - ) - - # Insert the creative group. - result = service.insert_creative_group(profile_id, creative_group) - - # Display results. - puts format('Created creative group with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_creative_group(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/creatives/create_display_image_gallery_creative.rb b/ruby/v4/creatives/create_display_image_gallery_creative.rb deleted file mode 100755 index 720d37f..0000000 --- a/ruby/v4/creatives/create_display_image_gallery_creative.rb +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a display image gallery creative. -# -# Requires two image assets and an advertiser ID as input. To get an advertiser -# ID, run get_advertisers.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def create_enhanced_image_creative(profile_id, advertiser_id, size_id, - path_to_image1_file, path_to_image2_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - util = CreativeAssetUtils.new(service, profile_id) - - # Upload the first image asset. - image1_asset_id = util.upload_asset(advertiser_id, path_to_image1_file, - 'HTML_IMAGE').asset_identifier - - # Upload the second image asset. - image2_asset_id = util.upload_asset(advertiser_id, path_to_image2_file, - 'HTML_IMAGE').asset_identifier - - # Construct the creative structure. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - auto_advance_images: true, - click_tags: [ - DfareportingUtils::API_NAMESPACE::ClickTag.new( - event_name: image1_asset_id.name, - name: image1_asset_id.name - ), - DfareportingUtils::API_NAMESPACE::ClickTag.new( - event_name: image2_asset_id.name, - name: image2_asset_id.name - ) - ], - creative_assets: [ - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: image1_asset_id, - role: 'PRIMARY' - ), - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: image2_asset_id, - role: 'PRIMARY' - ) - ], - name: 'Example display image gallery creative', - size: DfareportingUtils::API_NAMESPACE::Size.new(id: size_id), - type: 'DISPLAY_IMAGE_GALLERY' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - puts format( - 'Created display image gallery creative with ID %d and name "%s".', - result.id, result.name - ) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :size_id, :path_to_image1_file, :path_to_image2_file) - - create_enhanced_image_creative(args[:profile_id], args[:advertiser_id], - args[:size_id], args[:path_to_image1_file], args[:path_to_image2_file]) -end diff --git a/ruby/v4/creatives/create_display_redirect_creative.rb b/ruby/v4/creatives/create_display_redirect_creative.rb deleted file mode 100755 index 68ed09d..0000000 --- a/ruby/v4/creatives/create_display_redirect_creative.rb +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a display redirect creative associated with a given -# advertiser. -# -# To get a size ID, run get_size.rb. - -require_relative '../dfareporting_utils' - -def create_tracking_creative(profile_id, advertiser_id, image_url, size_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative resource to insert. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - name: 'Example display redirect creative', - redirect_url: image_url, - size: DfareportingUtils::API_NAMESPACE::Size.new(id: size_id), - type: 'DISPLAY_REDIRECT' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - # Display results. - puts format('Created display redirect creative with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :image_url, :size_id) - - create_tracking_creative(args[:profile_id], args[:advertiser_id], - args[:image_url], args[:size_id]) -end diff --git a/ruby/v4/creatives/create_html5_display_creative.rb b/ruby/v4/creatives/create_html5_display_creative.rb deleted file mode 100755 index 62abc6c..0000000 --- a/ruby/v4/creatives/create_html5_display_creative.rb +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an HTML5 display creative. -# -# Requires an HTML5 asset, backup image asset, and an advertiser ID as input. -# To get an advertiser ID, run get_advertisers.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def create_html5_banner_creative(profile_id, advertiser_id, size_id, - path_to_html5_asset_file, path_to_backup_image_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - util = CreativeAssetUtils.new(service, profile_id) - - # Locate an advertiser landing page to use as a default. - default_landing_page = get_advertiser_landing_page(service, profile_id, - advertiser_id) - - # Upload the HTML5 asset. - html5_asset_id = util.upload_asset(advertiser_id, path_to_html5_asset_file, - 'HTML').asset_identifier - - # Upload the backup image asset. - backup_image_asset_id = util.upload_asset(advertiser_id, - path_to_backup_image_file, 'HTML_IMAGE').asset_identifier - - # Construct the creative structure. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - backup_image_click_through_url: - DfareportingUtils::API_NAMESPACE::CreativeClickThroughUrl.new( - landing_page_id: default_landing_page.id - ), - backup_image_reporting_label: 'backup', - backup_image_target_window: - DfareportingUtils::API_NAMESPACE::TargetWindow.new( - target_window_option: 'NEW_WINDOW' - ), - click_tags: [ - DfareportingUtils::API_NAMESPACE::ClickTag.new( - event_name: 'exit', - name: 'click_tag', - click_through_url: - DfareportingUtils::API_NAMESPACE::CreativeClickThroughUrl.new( - landing_page_id: default_landing_page.id - ) - ) - ], - creative_assets: [ - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: html5_asset_id, - role: 'PRIMARY' - ), - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: backup_image_asset_id, - role: 'BACKUP_IMAGE' - ) - ], - name: 'Example HTML5 display creative', - size: DfareportingUtils::API_NAMESPACE::Size.new(id: size_id), - type: 'DISPLAY' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - puts format('Created HTML5 display creative with ID %d and name "%s".', - result.id, result.name) -end - -def get_advertiser_landing_page(service, profile_id, advertiser_id) - # Retrieve a sigle landing page from the specified advertiser. - result = service.list_advertiser_landing_pages(profile_id, - advertiser_ids: [advertiser_id], - max_results: 1) - - if result.landing_pages.none? - abort format('No landing pages for for advertiser with ID %d', - advertiser_id) - end - - result.landing_pages[0] -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :size_id, :path_to_html5_asset_file, :path_to_backup_image_file) - - create_html5_banner_creative(args[:profile_id], args[:advertiser_id], - args[:size_id], args[:path_to_html5_asset_file], - args[:path_to_backup_image_file]) -end diff --git a/ruby/v4/creatives/create_image_display_creative.rb b/ruby/v4/creatives/create_image_display_creative.rb deleted file mode 100755 index df81b14..0000000 --- a/ruby/v4/creatives/create_image_display_creative.rb +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an image display creative. -# -# Requires an image asset and advertiser ID as input. To get an advertiser ID, -# run get_advertisers.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def create_image_display_creative(profile_id, advertiser_id, size_id, - path_to_image_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Upload the creative asset. - util = CreativeAssetUtils.new(service, profile_id) - creative_asset_id = util.upload_asset(advertiser_id, path_to_image_file, - 'HTML_IMAGE').asset_identifier - - # Construct the creative structure. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - creative_assets: [ - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: creative_asset_id, - role: 'PRIMARY' - ) - ], - name: 'Example image display creative', - size: DfareportingUtils::API_NAMESPACE::Size.new(id: size_id), - type: 'DISPLAY' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - puts format('Created image display creative with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :size_id, :path_to_image_file) - - create_image_display_creative(args[:profile_id], args[:advertiser_id], - args[:size_id], args[:path_to_image_file]) -end diff --git a/ruby/v4/creatives/create_instream_audio_creative.rb b/ruby/v4/creatives/create_instream_audio_creative.rb deleted file mode 100755 index ac2234d..0000000 --- a/ruby/v4/creatives/create_instream_audio_creative.rb +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2018, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an in-stream audio creative. -# -# Requires an audio asset and advertiser ID as input. To get an advertiser ID, -# run get_advertisers.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def create_instream_audio_creative(profile_id, advertiser_id, - path_to_audio_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Upload the creative asset. - util = CreativeAssetUtils.new(service, profile_id) - creative_asset_id = util.upload_asset(advertiser_id, path_to_audio_file, - 'AUDIO').asset_identifier - - # Construct the creative structure. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - creative_assets: [ - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: creative_asset_id, - role: 'PARENT_AUDIO' - ) - ], - name: 'Example in-stream audio creative', - type: 'INSTREAM_AUDIO' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - puts format('Created in-stream audio creative with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :path_to_audio_file) - - create_instream_audio_creative(args[:profile_id], args[:advertiser_id], - args[:path_to_audio_file]) -end diff --git a/ruby/v4/creatives/create_instream_video_creative.rb b/ruby/v4/creatives/create_instream_video_creative.rb deleted file mode 100755 index 027d15c..0000000 --- a/ruby/v4/creatives/create_instream_video_creative.rb +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an in-stream video creative. -# -# Requires a video asset and advertiser ID as input. To get an advertiser ID, -# run get_advertisers.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def create_instream_video_creative(profile_id, advertiser_id, - path_to_video_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Upload the creative asset. - util = CreativeAssetUtils.new(service, profile_id) - creative_asset_id = util.upload_asset(advertiser_id, path_to_video_file, - 'VIDEO').asset_identifier - - # Construct the creative structure. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - creative_assets: [ - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: creative_asset_id, - role: 'PARENT_VIDEO' - ) - ], - name: 'Example in-stream video creative', - type: 'INSTREAM_VIDEO' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - puts format('Created in-stream video creative with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :path_to_video_file) - - create_instream_video_creative(args[:profile_id], args[:advertiser_id], - args[:path_to_video_file]) -end diff --git a/ruby/v4/creatives/create_tracking_creative.rb b/ruby/v4/creatives/create_tracking_creative.rb deleted file mode 100755 index 302cb94..0000000 --- a/ruby/v4/creatives/create_tracking_creative.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a tracking creative associated with a given advertiser. - -require_relative '../dfareporting_utils' - -def create_tracking_creative(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new creative resource to insert. - creative = DfareportingUtils::API_NAMESPACE::Creative.new( - advertiser_id: advertiser_id, - name: 'Example Tracking Creative', - type: 'TRACKING_TEXT' - ) - - # Insert the creative. - result = service.insert_creative(profile_id, creative) - - # Display results. - puts format('Created tracking creative with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_tracking_creative(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/creatives/get_creative_field_values.rb b/ruby/v4/creatives/get_creative_field_values.rb deleted file mode 100755 index 8703fbb..0000000 --- a/ruby/v4/creatives/get_creative_field_values.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all creative field values. - -require_relative '../dfareporting_utils' - -def get_creative_field_values(profile_id, field_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_creative_field_values(profile_id, field_id, - page_token: token, - fields: 'nextPageToken,creativeFieldValues(id,value)') - - # Display results. - if result.creative_field_values.any? - result.creative_field_values.each do |value| - puts format('Found creative field value with ID %d and value "%s".', - value.id, value.value) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :field_id) - - get_creative_field_values(args[:profile_id], args[:field_id]) -end diff --git a/ruby/v4/creatives/get_creative_fields.rb b/ruby/v4/creatives/get_creative_fields.rb deleted file mode 100755 index 04028cd..0000000 --- a/ruby/v4/creatives/get_creative_fields.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all creative fields. - -require_relative '../dfareporting_utils' - -def get_creative_fields(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_creative_fields(profile_id, - page_token: token, - fields: 'nextPageToken,creativeFields(id,name)') - - # Display results. - if result.creative_fields.any? - result.creative_fields.each do |field| - puts format('Found creative field with ID %d and name "%s".', field.id, - field.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_creative_fields(args[:profile_id]) -end diff --git a/ruby/v4/creatives/get_creative_groups.rb b/ruby/v4/creatives/get_creative_groups.rb deleted file mode 100755 index 518f8c5..0000000 --- a/ruby/v4/creatives/get_creative_groups.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all creative groups. - -require_relative '../dfareporting_utils' - -def get_creative_groups(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_creative_groups(profile_id, - page_token: token, - fields: 'nextPageToken,creativeGroups(id,name)') - - # Display results. - if result.creative_groups.any? - result.creative_groups.each do |group| - puts format('Found creative group with ID %d and name "%s".', group.id, - group.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_creative_groups(args[:profile_id]) -end diff --git a/ruby/v4/creatives/get_creatives.rb b/ruby/v4/creatives/get_creatives.rb deleted file mode 100755 index 1350a7f..0000000 --- a/ruby/v4/creatives/get_creatives.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example lists all existing active creatives for a given advertiser. -# -# To get an advertiser ID, run get_advertisers.rb. - -require_relative '../dfareporting_utils' - -def get_creatives(profile_id, _advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_creatives(profile_id, - page_token: token, - fields: 'nextPageToken,creatives(id,name,type)') - - # Display results. - if result.creatives.any? - result.creatives.each do |creative| - puts format('Found %s creative with ID %d and name "%s".', - creative.type, creative.id, creative.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_creatives(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/dfareporting_utils.rb b/ruby/v4/dfareporting_utils.rb deleted file mode 100755 index a3f7765..0000000 --- a/ruby/v4/dfareporting_utils.rb +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Handles common tasks across all DFA Reporting API samples. - -require 'google/apis/dfareporting_v4' -require 'googleauth' -require 'googleauth/stores/file_token_store' - -# Utility methods used by all DFA Reporting and Trafficking API samples. -module DfareportingUtils - API_NAME = 'dfareporting'.freeze - API_NAMESPACE = Google::Apis::DfareportingV4 - API_SCOPES = [ - API_NAMESPACE::AUTH_DDMCONVERSIONS, - API_NAMESPACE::AUTH_DFAREPORTING, - API_NAMESPACE::AUTH_DFATRAFFICKING - ].freeze - - CLIENT_SECRETS_FILE = 'client_secrets.json'.freeze - CREDENTIAL_STORE_FILE = "#{API_NAME}-oauth2.yaml".freeze - CREDENTIAL_STORE_PATH = File.dirname(__FILE__) - - # This redirect URI allows you to copy the token from the success screen. - OAUTH_REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze - - # Handles validating command line arguments and returning them as a Hash - def self.parse_arguments(argument_values, *argument_names) - validate_arguments(argument_values, *argument_names) - generate_argument_map(argument_values, *argument_names) - end - - # Validates the number of command line arguments matches what was expected - def self.validate_arguments(argument_values, *argument_names) - return if argument_values.length == argument_names.length - - # Format the arguments for display (ie, '') - formatted_arguments = argument_names.map { |a| '<' + a.to_s + '>' } - - # Display a message to the user and exit - puts format('Usage: %s %s', $PROGRAM_NAME, formatted_arguments.join(' ')) - exit - end - private_class_method :validate_arguments - - # Converts parallel arrays of argument names and values into a single map - def self.generate_argument_map(argument_values, *argument_names) - ret = {} - argument_names.each_with_index do |arg, index| - ret[arg] = argument_values[index] - end - ret - end - private_class_method :generate_argument_map - - # Handles authentication and loading of the API. - def self.initialize_service - # Uncomment the following lines to enable logging. - # log_file = File.open("#{$0}.log", 'a+') - # log_file.sync = true - # logger = Logger.new(log_file) - # logger.level = Logger::DEBUG - # Google::Apis.logger = logger # Logging is set globally - - # Create an API Service object. - service = create_service_object - - # Load application default credentials if they're available. - authorization = authorize_application_default_credentials - - # Otherwise, load credentials from the provided client secrets file. - authorization = authorize_installed_application if authorization.nil? - - # If no credentials could be loaded, return an error. - if authorization.nil? - puts 'Could not load credentials. Enter client ID and secret from ' \ - 'https://console.developers.google.com/ into client_secrets.json.' - exit - end - - service.authorization = authorization - service - end - - # Returns an instance of the Dfareporting service without authentication. - def self.create_service_object - service = API_NAMESPACE::DfareportingService.new - service.client_options.application_name = "Ruby #{API_NAME} samples" - service.client_options.application_version = '1.0.0' - - service - end - private_class_method :create_service_object - - # Attempts to load application default credentials and return an - # authorization object that can be used to make requests. - def self.authorize_application_default_credentials - Google::Auth.get_application_default(API_SCOPES) - rescue StandardError - # No application default credentials, continue to try other options. - nil - end - private_class_method :authorize_application_default_credentials - - # Handles authorizing a user via the OAuth installed application flow and - # returns an authorization object that can be used to make requests. - def self.authorize_installed_application - # Load the client secrets. - client_id = load_client_secrets - return nil if client_id.nil? - - # FileTokenStore stores auth credentials in a file, so they survive - # multiple runs of the application. This avoids prompting the user for - # authorization every time the access token expires, by remembering the - # refresh token. - # - # Note: FileTokenStore is not suitable for multi-user applications. - token_store = Google::Auth::Stores::FileTokenStore.new( - file: File.join(CREDENTIAL_STORE_PATH, CREDENTIAL_STORE_FILE) - ) - - authorizer = Google::Auth::UserAuthorizer.new(client_id, API_SCOPES, - token_store) - - authorization = authorizer.get_credentials('default') - if authorization.nil? - puts format( - "Open this URL in your browser and authorize the application.\n\n%s" \ - "\n\nEnter the authorization code:", - authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI) - ) - code = STDIN.gets.chomp - authorization = authorizer.get_and_store_credentials_from_code( - base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'default' - ) - end - - authorization - end - private_class_method :authorize_installed_application - - def self.load_client_secrets - # Load client ID from the specified file. - client_id = Google::Auth::ClientId.from_file( - File.join(CREDENTIAL_STORE_PATH, CLIENT_SECRETS_FILE) - ) - - if client_id.id.start_with?('[[INSERT') || - client_id.secret.start_with?('[[INSERT') - return nil - end - - client_id - rescue StandardError - # Unable to load client_secrets.json. - nil - end - private_class_method :load_client_secrets -end diff --git a/ruby/v4/floodlight/create_floodlight_activity.rb b/ruby/v4/floodlight/create_floodlight_activity.rb deleted file mode 100755 index 3c200b3..0000000 --- a/ruby/v4/floodlight/create_floodlight_activity.rb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a floodlight activity in a given activity group. -# -# To create an activity group, run create_floodlight_activity_group.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_floodlight_activity(profile_id, activity_group_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new floodlight activity resource to insert. - activity = DfareportingUtils::API_NAMESPACE::FloodlightActivity.new( - counting_method: 'STANDARD_COUNTING', - expected_url: 'http://www.google.com', - floodlight_activity_group_id: activity_group_id, - floodlight_tag_type: 'GLOBAL_SITE_TAG', - name: format('Example Floodlight Activity #%s', SecureRandom.hex(3)) - ) - - # Insert the floodlight activity. - result = service.insert_floodlight_activity(profile_id, activity) - - # Display results. - puts format('Created floodlight activity with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, - :activity_group_id) - - create_floodlight_activity(args[:profile_id], args[:activity_group_id]) -end diff --git a/ruby/v4/floodlight/create_floodlight_activity_group.rb b/ruby/v4/floodlight/create_floodlight_activity_group.rb deleted file mode 100755 index 33d1c81..0000000 --- a/ruby/v4/floodlight/create_floodlight_activity_group.rb +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a new activity group for a floodlight configuration. -# -# To get a floodlight configuration ID, run get_advertisers.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_floodlight_activity_group(profile_id, floodlight_config_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new floodlight activity group resource to insert. - activity_group = - DfareportingUtils::API_NAMESPACE::FloodlightActivityGroup.new( - floodlight_configuration_id: floodlight_config_id, - name: - format('Example Floodlight Activity Group #%s', SecureRandom.hex(3)), - type: 'COUNTER' - ) - - # Insert the floodlight activity group. - result = service.insert_floodlight_activity_group(profile_id, activity_group) - - # Display results. - puts format('Created floodlight activity group with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, - :floodlight_config_id) - - create_floodlight_activity_group(args[:profile_id], - args[:floodlight_config_id]) -end diff --git a/ruby/v4/floodlight/download_floodlight_tag.rb b/ruby/v4/floodlight/download_floodlight_tag.rb deleted file mode 100755 index 74df834..0000000 --- a/ruby/v4/floodlight/download_floodlight_tag.rb +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example downloads activity tags for a given floodlight activity. - -require_relative '../dfareporting_utils' - -def download_floodlight_tag(profile_id, activity_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Construct the request. - result = service.generatetag_floodlight_activity(profile_id, - floodlight_activity_id: activity_id) - - if result.global_site_tag_global_snippet.nil? - # This is an image or iframe tag. - puts format("Floodlight activity tag:\n\n%s", - result.floodlight_activity_tag) - else - # This is a global site tag, display both the global and event snippets. - puts format("Global site tag global snippet:\n\n%s", - result.global_site_tag_global_snippet) - puts format("\n\nGlobal site tag event snippet:\n\n%s", - result.floodlight_activity_tag) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :activity_id) - - download_floodlight_tag(args[:profile_id], args[:activity_id]) -end diff --git a/ruby/v4/floodlight/get_floodlight_activities.rb b/ruby/v4/floodlight/get_floodlight_activities.rb deleted file mode 100755 index c1dbfce..0000000 --- a/ruby/v4/floodlight/get_floodlight_activities.rb +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays floodlight activities for a given advertiser. -# -# To create an advertiser, run create_advertiser.rb. - -require_relative '../dfareporting_utils' - -def get_floodlight_activities(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_floodlight_activities(profile_id, - advertiser_id: advertiser_id, - page_token: token, - fields: 'nextPageToken,floodlightActivities(id,name)') - - # Display results. - if result.floodlight_activities.any? - result.floodlight_activities.each do |activity| - puts format('Found floodlight activity with ID %d and name "%s".', - activity.id, activity.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_floodlight_activities(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/floodlight/get_floodlight_activity_groups.rb b/ruby/v4/floodlight/get_floodlight_activity_groups.rb deleted file mode 100755 index 5015c48..0000000 --- a/ruby/v4/floodlight/get_floodlight_activity_groups.rb +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays floodlight activity groups for a given advertiser. -# -# To create an advertiser, run create_advertiser.rb. - -require_relative '../dfareporting_utils' - -def get_floodlight_activity_groups(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_floodlight_activity_groups(profile_id, - advertiser_id: advertiser_id, - page_token: token, - fields: 'nextPageToken,floodlightActivityGroups(id,name)') - - # Display results. - if result.floodlight_activity_groups.any? - result.floodlight_activity_groups.each do |group| - puts format( - 'Found floodlight activity group with ID %d and name "%s".', - group.id, group.name - ) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_floodlight_activity_groups(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/misc/get_change_logs_for_advertiser.rb b/ruby/v4/misc/get_change_logs_for_advertiser.rb deleted file mode 100755 index 81866ea..0000000 --- a/ruby/v4/misc/get_change_logs_for_advertiser.rb +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays the change logs of a specified advertiser object. -# -# A similar pattern can be applied to get change logs for many other object -# types. - -require_relative '../dfareporting_utils' - -def get_change_logs_for_advertiser(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_change_logs(profile_id, - object_ids: [advertiser_id], - object_type: 'OBJECT_ADVERTISER', - page_token: token, - fields: 'nextPageToken,changeLogs(action,fieldName,oldValue,newValue)') - - # Display results. - if result.change_logs.any? - result.change_logs.each do |log| - puts format('%s: Field "%s" from "%s" to "%s".', log.action, - log.field_name, log.old_value, log.new_value) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_change_logs_for_advertiser(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/misc/get_sites.rb b/ruby/v4/misc/get_sites.rb deleted file mode 100755 index 2dc8824..0000000 --- a/ruby/v4/misc/get_sites.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all existing sites for the current DCM account. - -require_relative '../dfareporting_utils' - -def get_subaccounts(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_sites(profile_id, - page_token: token, - fields: 'nextPageToken,sites(id,keyName)') - - # Display results. - if result.sites.any? - result.sites.each do |site| - puts format('Found site with ID %d and key name "%s".', - site.id, site.key_name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_subaccounts(args[:profile_id]) -end diff --git a/ruby/v4/misc/get_size.rb b/ruby/v4/misc/get_size.rb deleted file mode 100755 index f511d4a..0000000 --- a/ruby/v4/misc/get_size.rb +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all sizes for a given width and height. - -require_relative '../dfareporting_utils' - -def get_size(profile_id, width, height) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Construct and execute the size request. - result = service.list_sizes(profile_id, - height: height, - width: width) - - result.sizes.each do |size| - puts format('Found size with ID %d.', size.id) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :width, :height) - - get_size(args[:profile_id], args[:width], args[:height]) -end diff --git a/ruby/v4/placements/create_content_category.rb b/ruby/v4/placements/create_content_category.rb deleted file mode 100755 index ace2e2e..0000000 --- a/ruby/v4/placements/create_content_category.rb +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a content category with the given name and description. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_content_category(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new content category resource to insert. - content_category = DfareportingUtils::API_NAMESPACE::ContentCategory.new( - name: format('Example Content Category #%s', SecureRandom.hex(3)) - ) - - # Insert the content category. - result = service.insert_content_category(profile_id, content_category) - - # Display results. - puts format('Created content category with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - create_content_category(args[:profile_id]) -end diff --git a/ruby/v4/placements/create_placement.rb b/ruby/v4/placements/create_placement.rb deleted file mode 100755 index aedf5ac..0000000 --- a/ruby/v4/placements/create_placement.rb +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates an agency paid regular placement in a given campaign. -# -# Requires the DCM site ID and campaign ID in which the placement will be -# created. To create a campaign, run create_campaign.rb. To get DCM site ID, -# run get_site.rb. - -require_relative '../dfareporting_utils' - -def create_placement(profile_id, campaign_id, site_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the campaign. - campaign = service.get_campaign(profile_id, campaign_id) - - # Create a new placement resource to insert. - placement = DfareportingUtils::API_NAMESPACE::Placement.new( - campaign_id: campaign_id, - compatibility: 'DISPLAY', - name: 'Example Placement', - payment_source: 'PLACEMENT_AGENCY_PAID', - site_id: site_id, - size: DfareportingUtils::API_NAMESPACE::Size.new( - height: 1, - width: 1 - ), - tag_formats: ['PLACEMENT_TAG_STANDARD'] - ) - - # Set the pricing schedule for the placement. - placement.pricing_schedule = - DfareportingUtils::API_NAMESPACE::PricingSchedule.new( - end_date: campaign.end_date, - pricing_type: 'PRICING_TYPE_CPM', - start_date: campaign.start_date - ) - - # Insert the placement strategy. - result = service.insert_placement(profile_id, placement) - - # Display results. - puts format('Created placement with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id, - :site_id) - - create_placement(args[:profile_id], args[:campaign_id], args[:site_id]) -end diff --git a/ruby/v4/placements/create_placement_group.rb b/ruby/v4/placements/create_placement_group.rb deleted file mode 100755 index 43dc8aa..0000000 --- a/ruby/v4/placements/create_placement_group.rb +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a placement group in a given campaign. -# -# Requires the DCM site ID and campaign ID in which the placement group will be -# created. To create a campaign, run create_campaign.rb. To get DCM site ID, -# run get_site.rb. - -require_relative '../dfareporting_utils' - -def create_placement_group(profile_id, campaign_id, site_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Look up the campaign. - campaign = service.get_campaign(profile_id, campaign_id) - - # Create a new placement group resource to insert. - placement_group = DfareportingUtils::API_NAMESPACE::PlacementGroup.new( - campaign_id: campaign_id, - name: 'Example Placement Group', - placement_group_type: 'PLACEMENT_PACKAGE', - pricing_schedule: DfareportingUtils::API_NAMESPACE::PricingSchedule.new( - start_date: campaign.start_date, - end_date: campaign.end_date, - pricing_type: 'PRICING_TYPE_CPM' - ), - site_id: site_id - ) - - # Insert the placement strategy. - result = service.insert_placement_group(profile_id, placement_group) - - # Display results. - puts format('Created placement group with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id, - :site_id) - - create_placement_group(args[:profile_id], args[:campaign_id], args[:site_id]) -end diff --git a/ruby/v4/placements/create_placement_strategy.rb b/ruby/v4/placements/create_placement_strategy.rb deleted file mode 100755 index 78b54b9..0000000 --- a/ruby/v4/placements/create_placement_strategy.rb +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a placement strategy with the given name. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_placement_strategy(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new placement strategy resource to insert. - strategy = DfareportingUtils::API_NAMESPACE::PlacementStrategy.new( - name: format('Example Placement Strategy #%s', SecureRandom.hex(3)) - ) - - # Insert the placement strategy. - result = service.insert_placement_strategy(profile_id, strategy) - - # Display results. - puts format('Created placement strategy with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - create_placement_strategy(args[:profile_id]) -end diff --git a/ruby/v4/placements/download_placement_tags.rb b/ruby/v4/placements/download_placement_tags.rb deleted file mode 100755 index 3b42efe..0000000 --- a/ruby/v4/placements/download_placement_tags.rb +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example downloads HTML Tags for a given campaign and placement ID. -# -# To create campaigns, run create_campaign.rb. To create placements, run -# create_placement.rb. - -require_relative '../dfareporting_utils' - -def download_placement_tags(profile_id, campaign_id, placement_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Construct the request. - result = service.generate_placement_tags(profile_id, - campaign_id: campaign_id, - placement_ids: [placement_id]) - - result.placement_tags.each do |tag| - tag.tag_datas.each do |data| - puts format("%s - %s\n\n", tag.placement_id, data.format) - puts format("%s\n\n", data.impression_tag) unless data.impression_tag.nil? - puts format("%s\n\n", data.click_tag) unless data.click_tag.nil? - end - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :campaign_id, - :placement_id) - - download_placement_tags(args[:profile_id], args[:campaign_id], - args[:placement_id]) -end diff --git a/ruby/v4/placements/get_content_categories.rb b/ruby/v4/placements/get_content_categories.rb deleted file mode 100755 index 018fc91..0000000 --- a/ruby/v4/placements/get_content_categories.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all available content categories. - -require_relative '../dfareporting_utils' - -def get_content_categories(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_content_categories(profile_id, - page_token: token, - fields: 'nextPageToken,contentCategories(id,name)') - - # Display results. - if result.content_categories.any? - result.content_categories.each do |category| - puts format('Found content category with ID %d and name "%s".', - category.id, category.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_content_categories(args[:profile_id]) -end diff --git a/ruby/v4/placements/get_placement_strategies.rb b/ruby/v4/placements/get_placement_strategies.rb deleted file mode 100755 index 60670ba..0000000 --- a/ruby/v4/placements/get_placement_strategies.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all available placement strategies. - -require_relative '../dfareporting_utils' - -def get_placement_strategies(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_placement_strategies(profile_id, - page_token: token, - fields: 'nextPageToken,placementStrategies(id,name)') - - # Display results. - if result.placement_strategies.any? - result.placement_strategies.each do |strategy| - puts format('Found placement strategy with ID %d and name "%s".', - strategy.id, strategy.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_placement_strategies(args[:profile_id]) -end diff --git a/ruby/v4/placements/get_placements.rb b/ruby/v4/placements/get_placements.rb deleted file mode 100755 index dc9721f..0000000 --- a/ruby/v4/placements/get_placements.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all available placements. - -require_relative '../dfareporting_utils' - -def get_placements(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_placements(profile_id, - page_token: token, - fields: 'nextPageToken,placements(campaignId,id,name)') - - # Display results. - if result.placements.any? - result.placements.each do |placement| - puts format( - 'Found placement with ID %d and name "%s" for campaign %d.', - placement.id, placement.name, placement.campaign_id - ) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_placements(args[:profile_id]) -end diff --git a/ruby/v4/remarketing/create_remarketing_list.rb b/ruby/v4/remarketing/create_remarketing_list.rb deleted file mode 100755 index c52fff0..0000000 --- a/ruby/v4/remarketing/create_remarketing_list.rb +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a remarketing list for a given advertiser and floodight -# activity, using a custom rule. -# -# Note: this sample assumes that the floodlight activity specified has a U1 -# custom floodlight variable. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_remarketing_list(profile_id, advertiser_id, floodlight_activity_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a list population term. - # This term matches all visitors with a U1 value exactly matching - # "test_value" - term = DfareportingUtils::API_NAMESPACE::ListPopulationTerm.new( - operator: 'STRING_EQUALS', - type: 'CUSTOM_VARIABLE_TERM', - value: 'test_value', - variable_name: 'U1' - ) - - # Add the term to a clause and the clause to a population rule. - # This rule will target all visitors who trigger the specified floodlight - # activity and satisfy the custom rule defined in the list population term. - rule = DfareportingUtils::API_NAMESPACE::ListPopulationRule.new( - floodlight_activity_id: floodlight_activity_id, - list_population_clauses: [ - DfareportingUtils::API_NAMESPACE::ListPopulationClause.new( - terms: [term] - ) - ] - ) - - # Create the remarketing list. - list = DfareportingUtils::API_NAMESPACE::RemarketingList.new( - name: format('Test remarketing list #%s', SecureRandom.hex(3)), - active: true, - advertiser_id: advertiser_id, - life_span: 30, - list_population_rule: rule - ) - - # Insert the remarketing list. - list = service.insert_remarketing_list(profile_id, list) - - # Display results. - puts format('Remarketing list with ID %d and name "%s" was created.', - list.id, list.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :floodlight_activity_id) - - create_remarketing_list(args[:profile_id], args[:advertiser_id], - args[:floodlight_activity_id]) -end diff --git a/ruby/v4/remarketing/get_remarketing_lists.rb b/ruby/v4/remarketing/get_remarketing_lists.rb deleted file mode 100755 index 776837d..0000000 --- a/ruby/v4/remarketing/get_remarketing_lists.rb +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Displays all remarketing lists owned by the specified advertiser. -# -# Note: the RemarketingLists resource will only return lists owned by the -# specified advertiser. To see all lists that can be used for targeting ads -# (including those shared from other accounts or advertisers), use the -# TargetableRemarketingLists resource instead. - -require_relative '../dfareporting_utils' - -def get_remarketing_lists(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_remarketing_lists(profile_id, advertiser_id, - page_token: token, - fields: 'nextPageToken,remarketingLists(id,name)') - - # Display results. - if result.remarketing_lists.any? - result.remarketing_lists.each do |list| - puts format('Found remarketing list with ID %d and name "%s".', - list.id, list.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - get_remarketing_lists(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/remarketing/share_remarketing_list_to_advertiser.rb b/ruby/v4/remarketing/share_remarketing_list_to_advertiser.rb deleted file mode 100755 index 4b201bc..0000000 --- a/ruby/v4/remarketing/share_remarketing_list_to_advertiser.rb +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example shares an existing remarketing list with the specified -# advertiser. - -require_relative '../dfareporting_utils' - -def share_remarketing_list_to_advertiser(profile_id, advertiser_id, - remarketing_list_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Load the existing share info. - share = service.get_remarketing_list_share(profile_id, remarketing_list_id) - share.shared_advertiser_ids ||= [] - - if share.shared_advertiser_ids.include?(advertiser_id) - puts format('Remarketing list %d is already shared to advertiser %d.', - remarketing_list_id, advertiser_id) - else - share.shared_advertiser_ids <<= advertiser_id - - # Update the share info with the newly added advertiser ID. - share = service.update_remarketing_list_share(profile_id, share) - - puts format('Remarketing list %d is now shared to advertiser ID(s): %s', - remarketing_list_id, share.shared_advertiser_ids.join(', ')) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id, - :remarketing_list_id) - - share_remarketing_list_to_advertiser(args[:profile_id], args[:advertiser_id], - args[:remarketing_list_id]) -end diff --git a/ruby/v4/remarketing/target_ad_to_remarketing_list.rb b/ruby/v4/remarketing/target_ad_to_remarketing_list.rb deleted file mode 100755 index c7b8230..0000000 --- a/ruby/v4/remarketing/target_ad_to_remarketing_list.rb +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2017, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example targets an ad to a remarketing list. -# -# The first targetable remarketing list, either owned by or shared to the ad's -# advertiser, will be used. To create a remarketing list, see -# create_remarketing_list.rb. To share a remarketing list with the ad's -# advertiser, see share_remarketing_list_to_advertiser.rb. - -require_relative '../dfareporting_utils' - -def target_ad_to_remarketing_list(profile_id, ad_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Retrieve the ad. - ad = service.get_ad(profile_id, ad_id) - - # Retrieve a single targetable remarketing list for the ad. - lists = service.list_targetable_remarketing_lists(profile_id, - ad.advertiser_id, max_results: 1) - - if lists.targetable_remarketing_lists.any? - list = lists.targetable_remarketing_lists.first - - # Update the ad with a list targeting expression. - ad.remarketing_list_expression = - DfareportingUtils::API_NAMESPACE::ListTargetingExpression.new( - expression: list.id - ) - - ad = service.update_ad(profile_id, ad) - - puts format('Ad %d updated to use remarketing list expression: "%s".', - ad.id, ad.remarketing_list_expression.expression) - else - puts format('No targetable remarketing lists found for ad with ID %d.', - ad_id) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :ad_id) - - target_ad_to_remarketing_list(args[:profile_id], args[:ad_id]) -end diff --git a/ruby/v4/reports/create_report.rb b/ruby/v4/reports/create_report.rb deleted file mode 100755 index 02c51b1..0000000 --- a/ruby/v4/reports/create_report.rb +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# An end-to-end example of how to create and configure a standard report. - -require_relative '../dfareporting_utils' -require 'date' - -def create_report(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # 1. Create a report resource. - report = create_report_resource - - # 2. Define report criteria. - define_report_criteria(report) - - # 3. (optional) Look up compatible fields. - find_compatible_fields(service, profile_id, report) - - # 4. Add dimension filers to the report criteria. - add_dimension_filters(service, profile_id, report) - - # 5. Save the report resource. - insert_report_resource(service, profile_id, report) -end - -def create_report_resource - report = DfareportingUtils::API_NAMESPACE::Report.new( - # Set the required fields "name" and "type". - name: 'Example Standard Report', - type: 'STANDARD', - # Set optional fields. - file_name: 'example_report', - format: 'CSV' - ) - - puts format('Creating %s report resource with name "%s".', report.type, - report.name) - - report -end - -def define_report_criteria(report) - # Define a date range to report on. This example uses explicit start and end - # dates to mimic the "LAST_30_DAYS" relative date range. - start_date = DateTime.now.prev_day(30).strftime('%Y-%m-%d') - end_date = DateTime.now.strftime('%Y-%m-%d') - - # Create a report criteria - criteria = DfareportingUtils::API_NAMESPACE::Report::Criteria.new( - date_range: DfareportingUtils::API_NAMESPACE::DateRange.new( - start_date: start_date, - end_date: end_date - ), - dimensions: [ - DfareportingUtils::API_NAMESPACE::SortedDimension.new( - name: 'advertiser' - ) - ], - metric_names: ['clicks', 'impressions'] - ) - - # Add the criteria to the report resource. - report.criteria = criteria - - puts format("\nAdded report criteria:\n%s", criteria.to_json) -end - -def find_compatible_fields(service, profile_id, report) - fields = service.query_report_compatible_field(profile_id, report) - - report_fields = fields.report_compatible_fields - - if report_fields.dimensions.any? - # Add a compatible dimension to the report. - report.criteria.dimensions << - DfareportingUtils::API_NAMESPACE::SortedDimension.new( - name: report_fields.dimensions.first.name - ) - elsif report_fields.metrics.any? - # Add a compatible metric to the report. - report.criteria.metric_names << report_fields.metrics.first.name - end - - puts format("\nUpdated report criteria (with compatible fields):\n%s", - report.criteria.to_json) -end - -def add_dimension_filters(service, profile_id, report) - # Query advertiser dimension values for report run dates. - dimension = DfareportingUtils::API_NAMESPACE::DimensionValueRequest.new( - dimension_name: 'advertiser', - start_date: report.criteria.date_range.start_date, - end_date: report.criteria.date_range.end_date - ) - - values = service.query_dimension_value(profile_id, dimension) - - unless values.items.empty? - # Add a value as a filter to the report criteria. - report.criteria.dimension_filters = [values.items.first] - end - - puts format("\nUpdated report criteria (with valid dimension filters):\n%s", - report.criteria.to_json) -end - -def insert_report_resource(service, profile_id, report) - report = service.insert_report(profile_id, report) - - puts format("\nSuccessfully inserted new report with ID %s.", report.id) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - create_report(args[:profile_id]) -end diff --git a/ruby/v4/reports/delete_report.rb b/ruby/v4/reports/delete_report.rb deleted file mode 100755 index 1947df4..0000000 --- a/ruby/v4/reports/delete_report.rb +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to delete a report. - -require_relative '../dfareporting_utils' - -def delete_report(profile_id, report_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Delete the report. - service.delete_report(profile_id, report_id) - - puts format('Successfully deleted report with ID %d.', report_id) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :report_id) - - delete_report(args[:profile_id], args[:report_id]) -end diff --git a/ruby/v4/reports/download_file.rb b/ruby/v4/reports/download_file.rb deleted file mode 100755 index 671ce68..0000000 --- a/ruby/v4/reports/download_file.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to download a file - -require_relative '../dfareporting_utils' - -def download_file(report_id, file_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Retrieve the file metadata. - report_file = service.get_file(report_id, file_id) - return unless report_file.status == 'REPORT_AVAILABLE' - - # Prepare a local file to download the report contents to. - File.open(generate_file_name(report_file), 'w') do |out_file| - # Execute the download request. Providing a download destination - # retrieves the file contents rather than the file metadata. - service.get_file(report_id, file_id, download_dest: out_file) - - puts format('File %s downloaded to %s', file_id, - File.absolute_path(out_file.path)) - end -end - -def generate_file_name(report_file) - file_name = report_file.file_name - # If no filename is specified, use the file ID instead. - file_name = report_file.id.to_s if file_name.empty? - extension = report_file.format == 'CSV' ? '.csv' : '.xml' - file_name + extension -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :report_id, :file_id) - - download_file(args[:report_id], args[:file_id]) -end diff --git a/ruby/v4/reports/find_and_download_file.rb b/ruby/v4/reports/find_and_download_file.rb deleted file mode 100755 index a7f93a3..0000000 --- a/ruby/v4/reports/find_and_download_file.rb +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2018, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# An end-to-end example of how to find and download a report file. - -require_relative '../dfareporting_utils' - -def find_and_download_file(profile_id, report_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # 1. Find a file to download. - report_file = find_file(service, profile_id, report_id) - - if report_file - # 2. (optional) Generate a browser URL. - generate_browser_url(service, report_id, report_file.id) - - # 3. Directly download the file. - direct_download_file(service, report_id, report_file.id) - else - puts format('No file found for profile ID %d and report ID %d.', - profile_id, report_id) - end -end - -def find_file(service, profile_id, report_id) - page_token = nil - target = nil - - loop do - result = service.list_report_files(profile_id, report_id, - page_token: page_token) - - result.items.each do |file| - if target_file?(file) - target = file - break - end - end - - page_token = (result.next_page_token if target.nil? && result.items.any?) - break if page_token.to_s.empty? - end - - if target - puts format('Found file %s with filename "%s".', target.id, - target.file_name) - return target - end - - puts format('Unable to find file for profile ID %d and report ID %d.', - profile_id, report_id) - nil -end - -def target_file?(file) - # Provide custom validation logic here. - # For example purposes, any available file is considered valid. - file.status == 'REPORT_AVAILABLE' -end - -def generate_browser_url(service, report_id, file_id) - report_file = service.get_file(report_id, file_id) - browser_url = report_file.urls.browser_url - - puts format('File %s has browser URL: %s.', report_file.id, browser_url) -end - -def direct_download_file(service, report_id, file_id) - # Retrieve the file metadata. - report_file = service.get_file(report_id, file_id) - return unless report_file.status == 'REPORT_AVAILABLE' - - # Prepare a local file to download the report contents to. - File.open(generate_file_name(report_file), 'w') do |out_file| - # Execute the download request. Providing a download destination - # retrieves the file contents rather than the file metadata. - service.get_file(report_id, file_id, download_dest: out_file) - - puts format('File %s downloaded to %s', file_id, - File.absolute_path(out_file.path)) - end -end - -def generate_file_name(report_file) - file_name = report_file.file_name - # If no filename is specified, use the file ID instead. - file_name = report_file.id.to_s if file_name.empty? - extension = report_file.format == 'CSV' ? '.csv' : '.xml' - file_name + extension -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :report_id) - - find_and_download_file(args[:profile_id], args[:report_id]) -end diff --git a/ruby/v4/reports/find_and_run_report.rb b/ruby/v4/reports/find_and_run_report.rb deleted file mode 100755 index 439cb35..0000000 --- a/ruby/v4/reports/find_and_run_report.rb +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright (C) 2016 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# An end-to-end example of how to find and run a report. - -require_relative '../dfareporting_utils' - -# The following values control retry behavior while the report is processing. -# Minimum amount of time between polling requests. Defaults to 10 seconds. -MIN_RETRY_INTERVAL = 10 -# Maximum amount of time between polling requests. Defaults to 10 minutes. -MAX_RETRY_INTERVAL = 10 * 60 -# Maximum amount of time to spend polling. Defaults to 1 hour. -MAX_RETRY_ELAPSED_TIME = 60 * 60 - -def find_and_run_report(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # 1. Find a report to run. - report = find_report(service, profile_id) - - if report - # 2. Run the report. - report_file = run_report(service, profile_id, report.id) - - # 3. Wait for the report file to be ready. - wait_for_report_file(service, report.id, report_file.id) - else - puts format('No report found for profile ID %d.', profile_id) - end -end - -def find_report(service, profile_id) - page_token = nil - target = nil - - loop do - result = service.list_reports(profile_id, page_token: page_token) - - result.items.each do |report| - if target_report?(report) - target = report - break - end - end - - page_token = (result.next_page_token if target.nil? && result.items.any?) - break if page_token.to_s.empty? - end - - if target - puts format('Found report %s with filename "%s".', target.id, - target.file_name) - return target - end - - puts format('Unable to find report for profile ID %d.', profile_id) - nil -end - -def target_report?(report) - # Provide custom validation logic here. - # For example purposes, any report is considered valid. - !report.nil? -end - -def run_report(service, profile_id, report_id) - # Run the report. - report_file = service.run_report(profile_id, report_id) - - puts format('Running report %d, current file status is %s.', report_id, - report_file.status) - report_file -end - -def wait_for_report_file(service, report_id, file_id) - # Wait for the report file to finish processing. - # An exponential backoff strategy is used to conserve request quota. - interval = 0 - start_time = Time.now - loop do - report_file = service.get_file(report_id, file_id) - - status = report_file.status - if status == 'REPORT_AVAILABLE' - puts format('File status is %s, ready to download.', status) - break - elsif status != 'PROCESSING' - puts format('File status is %s, processing failed.', status) - break - elsif Time.now - start_time > MAX_RETRY_ELAPSED_TIME - puts 'File processing deadline exceeded.' - break - end - - interval = next_sleep_interval(interval) - puts format('File status is %s, sleeping for %d seconds.', status, - interval) - sleep(interval) - end -end - -def next_sleep_interval(previous_interval) - min_interval = [MIN_RETRY_INTERVAL, previous_interval].max - max_interval = [MIN_RETRY_INTERVAL, previous_interval * 3].max - [MAX_RETRY_INTERVAL, rand(min_interval..max_interval)].min -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - find_and_run_report(args[:profile_id]) -end diff --git a/ruby/v4/reports/get_compatible_fields.rb b/ruby/v4/reports/get_compatible_fields.rb deleted file mode 100755 index 548bace..0000000 --- a/ruby/v4/reports/get_compatible_fields.rb +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to get the compatible fields for a report. - -require_relative '../dfareporting_utils' - -def get_compatible_fields(profile_id, report_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Get the report. - report = service.get_report(profile_id, report_id) - - # Get the compatible fields. - result = service.query_report_compatible_field(profile_id, report) - - compatible_fields = result.report_compatible_fields - - # Display dimensions. - dimensions = compatible_fields.dimensions.map(&:name) - print_fields('Dimensions', dimensions) - - # Display metrics. - metrics = compatible_fields.metrics.map(&:name) - print_fields('Metrics', metrics) - - # Display dimension filters. - filters = compatible_fields.dimension_filters.map(&:name) - print_fields('Dimension Filers', filters) - - # Display pivoted activity metrics. - activities = compatible_fields.pivoted_activity_metrics.map(&:name) - print_fields('Pivoted Activity Metrics', activities) -end - -def print_fields(type, fields) - puts format('Compatible %s', type) - puts fields.join(', ') - puts -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :report_id) - - get_compatible_fields(args[:profile_id], args[:report_id]) -end diff --git a/ruby/v4/reports/get_dimension_values.rb b/ruby/v4/reports/get_dimension_values.rb deleted file mode 100755 index b2f9ed6..0000000 --- a/ruby/v4/reports/get_dimension_values.rb +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to list all values for a dimension - -require_relative '../dfareporting_utils' -require 'date' - -def get_dimension_values(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create the dimension to query. - dimension = DfareportingUtils::API_NAMESPACE::DimensionValueRequest.new( - dimension_name: 'advertiser', - start_date: DateTime.now.prev_year.strftime('%Y-%m-%d'), - end_date: DateTime.now.strftime('%Y-%m-%d') - ) - - token = nil - loop do - result = service.query_dimension_value( - profile_id, dimension, - page_token: token, - fields: 'nextPageToken,items(id,value)' - ) - - # Display results. - if result.items.any? - result.items.each do |dimension_value| - puts format('Dimension with ID %d and value "%s" was found.', - dimension_value.id, dimension_value.value) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_dimension_values(args[:profile_id]) -end diff --git a/ruby/v4/reports/get_files.rb b/ruby/v4/reports/get_files.rb deleted file mode 100755 index e2a444e..0000000 --- a/ruby/v4/reports/get_files.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to list all files for a profile - -require_relative '../dfareporting_utils' - -def get_files(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_files(profile_id, - page_token: token, - fields: 'nextPageToken,items(fileName,id,status)') - - # Display results. - if result.items.any? - result.items.each do |file| - puts format( - 'Report file with ID %d and file name "%s" has status "%s".', - file.id, file.file_name, file.status - ) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_files(args[:profile_id]) -end diff --git a/ruby/v4/reports/get_report_files.rb b/ruby/v4/reports/get_report_files.rb deleted file mode 100755 index 9a7e027..0000000 --- a/ruby/v4/reports/get_report_files.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to list all files for a report - -require_relative '../dfareporting_utils' - -def get_report_files(profile_id, report_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_report_files(profile_id, report_id, - page_token: token, - fields: 'nextPageToken,items(fileName,id,status)') - - # Display results. - if result.items.any? - result.items.each do |file| - puts format( - 'Report file with ID %d and file name "%s" has status "%s".', - file.id, file.file_name, file.status - ) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :report_id) - - get_report_files(args[:profile_id], args[:report_id]) -end diff --git a/ruby/v4/reports/get_reports.rb b/ruby/v4/reports/get_reports.rb deleted file mode 100755 index 9dd22f3..0000000 --- a/ruby/v4/reports/get_reports.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to list all reports for a profile - -require_relative '../dfareporting_utils' - -def get_reports(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_reports(profile_id, - page_token: token, - fields: 'nextPageToken,items(id,name,type)') - - # Display results. - if result.items.any? - result.items.each do |report| - puts format('%s report with ID %d and name "%s" was found.', - report.type, report.id, report.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_reports(args[:profile_id]) -end diff --git a/ruby/v4/reports/run_report.rb b/ruby/v4/reports/run_report.rb deleted file mode 100755 index fe771a1..0000000 --- a/ruby/v4/reports/run_report.rb +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright (C) 2016 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to run a report. - -require_relative '../dfareporting_utils' - -# The following values control retry behavior while the report is processing. -# Minimum amount of time between polling requests. Defaults to 10 seconds. -MIN_RETRY_INTERVAL = 10 -# Maximum amount of time between polling requests. Defaults to 10 minutes. -MAX_RETRY_INTERVAL = 10 * 60 -# Maximum amount of time to spend polling. Defaults to 1 hour. -MAX_RETRY_ELAPSED_TIME = 60 * 60 - -def run_report(profile_id, report_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Run the report. - report_file = service.run_report(profile_id, report_id) - puts format('File with ID %s has been created.', report_file.id) - - # Wait for the report to finish processing. - wait_for_report_file(service, report_id, report_file.id) -end - -def wait_for_report_file(service, report_id, file_id) - # An exponential backoff strategy is used to conserve request quota. - interval = 0 - start_time = Time.now - loop do - report_file = service.get_file(report_id, file_id) - - status = report_file.status - if status == 'REPORT_AVAILABLE' - puts format('File status is %s, ready to download.', status) - break - elsif status != 'PROCESSING' - puts format('File status is %s, processing failed.', status) - break - elsif Time.now - start_time > MAX_RETRY_ELAPSED_TIME - puts 'File processing deadline exceeded.' - break - end - - interval = next_sleep_interval(interval) - puts format('File status is %s, sleeping for %d seconds.', status, interval) - sleep(interval) - end -end - -def next_sleep_interval(previous_interval) - min_interval = [MIN_RETRY_INTERVAL, previous_interval].max - max_interval = [MIN_RETRY_INTERVAL, previous_interval * 3].max - [MAX_RETRY_INTERVAL, rand(min_interval..max_interval)].min -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :report_id) - - run_report(args[:profile_id], args[:report_id]) -end diff --git a/ruby/v4/subaccounts/create_subaccount.rb b/ruby/v4/subaccounts/create_subaccount.rb deleted file mode 100755 index 0516b31..0000000 --- a/ruby/v4/subaccounts/create_subaccount.rb +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a subaccount in a given DCM account. -# -# To get the account ID, run get_all_userprofiles.rb. To get the available -# permissions, run get_subaccount_permissions.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_subaccount(profile_id, account_id, permission_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new subaccount resource to insert. - subaccount = DfareportingUtils::API_NAMESPACE::Subaccount.new( - account_id: account_id, - available_permission_ids: [permission_id], - name: format('Example Subaccount #%s', SecureRandom.hex(3)) - ) - - # Insert the subaccount. - result = service.insert_subaccount(profile_id, subaccount) - - # Display results. - puts format('Created subaccount with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :account_id, - :permission_id) - - create_subaccount(args[:profile_id], args[:account_id], args[:permission_id]) -end diff --git a/ruby/v4/subaccounts/get_subaccount_permissions.rb b/ruby/v4/subaccounts/get_subaccount_permissions.rb deleted file mode 100755 index 23559ee..0000000 --- a/ruby/v4/subaccounts/get_subaccount_permissions.rb +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all of the available user role permissions for a given -# subaccount. -# -# To get a subaccount ID, run get_subaccounts.rb. - -require_relative '../dfareporting_utils' - -def get_subaccount_permissions(profile_id, subaccount_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Construct and execute the subaccount request. - subaccount = service.get_subaccount(profile_id, subaccount_id) - - # Construct the user role permissions request. - result = service.list_user_role_permissions(profile_id, - ids: subaccount.available_permission_ids) - - result.user_role_permissions.each do |permission| - puts format('Found user role permission with ID %d and name "%s".', - permission.id, permission.name) - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :subaccount_id) - - get_subaccount_permissions(args[:profile_id], args[:subaccount_id]) -end diff --git a/ruby/v4/subaccounts/get_subaccounts.rb b/ruby/v4/subaccounts/get_subaccounts.rb deleted file mode 100755 index a18a9b1..0000000 --- a/ruby/v4/subaccounts/get_subaccounts.rb +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all subaccounts. -# -# Note that the permissions assigned to a subaccount are not returned in a -# human-readable format with this example. Run get_available_permissions.rb to -# see what permissions are available on a subaccount. - -require_relative '../dfareporting_utils' - -def get_subaccounts(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_subaccounts(profile_id, - page_token: token, - fields: 'nextPageToken,subaccounts(id,name)') - - # Display results. - if result.subaccounts.any? - result.subaccounts.each do |subaccount| - puts format('Found subaccount with ID %d and name "%s".', subaccount.id, - subaccount.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_subaccounts(args[:profile_id]) -end diff --git a/ruby/v4/targeting/configure_dynamic_asset_selection.rb b/ruby/v4/targeting/configure_dynamic_asset_selection.rb deleted file mode 100755 index c2596c0..0000000 --- a/ruby/v4/targeting/configure_dynamic_asset_selection.rb +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example enables dynamic asset selection for an in-stream video creative. -# -# Requires an existing in-stream video creative, a new video asset, and a -# targeting template ID as input. To get an in-stream video creative, run -# create_instream_video_creative.rb. To get a targeting template, run -# create_targeting_template.rb. - -require_relative '../creative_asset_utils' -require_relative '../dfareporting_utils' - -def configure_dynamic_asset_selection(profile_id, creative_id, template_id, - path_to_video_file) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Retrieve the specified creative. - creative = service.get_creative(profile_id, creative_id) - - abort 'Invalid creative specified' if - creative.nil? || (creative.type != 'INSTREAM_VIDEO') - - # Enable dynamic asset selection for the creative if necessary. - enable_dynamic_asset_selection(creative) unless - creative.dynamic_asset_selection? - - # Upload the new video asset and add it to the creative. - video_asset = CreativeAssetUtils.new(service, profile_id).upload_asset( - creative.advertiser_id, path_to_video_file, 'VIDEO' - ) - - creative.creative_assets <<= - DfareportingUtils::API_NAMESPACE::CreativeAsset.new( - asset_identifier: video_asset.asset_identifier, - role: 'PARENT_VIDEO' - ) - - # Create a rule targeting the new video asset and add it to the creative. - creative.creative_asset_selection.rules <<= - DfareportingUtils::API_NAMESPACE::Rule.new( - asset_id: video_asset.id, - name: format('Test rule for asset %d', video_asset.id), - targeting_template_id: template_id - ) - - result = service.update_creative(profile_id, creative) - - puts format('Dynamic asset selection enabled for creative with ID %d.', - result.id) -end - -def enable_dynamic_asset_selection(creative) - # Locate an existing video asset to use as a default. - default_asset = creative.creative_assets.find do |asset| - asset.role == 'PARENT_VIDEO' - end - - abort 'Default video asset could not be found.' if default_asset.nil? - - # Enable dynamic asset selection for the creative. - creative.dynamic_asset_selection = true - - # Create a new selection using the existing asset as a default. - creative.creative_asset_selection = - DfareportingUtils::API_NAMESPACE::CreativeAssetSelection.new( - default_asset_id: default_asset.id, - rules: [] - ) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :creative_id, - :template_id, :path_to_video_file) - - configure_dynamic_asset_selection(args[:profile_id], args[:creative_id], - args[:template_id], args[:path_to_video_file]) -end diff --git a/ruby/v4/targeting/create_targeting_template.rb b/ruby/v4/targeting/create_targeting_template.rb deleted file mode 100755 index 1e1b603..0000000 --- a/ruby/v4/targeting/create_targeting_template.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a targeting template associated with a given advertiser. -# -# To get an advertiser ID, run get_advertisers.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_targeting_template(profile_id, advertiser_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new targeting template resource to insert. - # This template will be configured to serve ads on Monday, Wednesday, and - # Friday from 9-10am and 3-5pm. - # Note: targeting template names must be unique within an advetiser. - targeting_template = DfareportingUtils::API_NAMESPACE::TargetingTemplate.new( - advertiser_id: advertiser_id, - day_part_targeting: DfareportingUtils::API_NAMESPACE::DayPartTargeting.new( - days_of_week: %w[MONDAY WEDNESDAY FRIDAY], - hours_of_day: [9, 15, 16], - user_local_time: true - ), - name: format('Test Targeting Template #%s', SecureRandom.hex(3)) - ) - - # Insert the targeting template. - result = service.insert_targeting_template(profile_id, targeting_template) - - # Display results. - puts format('Created targeting template with ID %d and name "%s".', - result.id, result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :advertiser_id) - - create_targeting_template(args[:profile_id], args[:advertiser_id]) -end diff --git a/ruby/v4/targeting/get_targeting_templates.rb b/ruby/v4/targeting/get_targeting_templates.rb deleted file mode 100755 index fffa481..0000000 --- a/ruby/v4/targeting/get_targeting_templates.rb +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example retrieves all targeting templates for your DCM user profile. -# -# Displays name, ID, and advertiser ID for each targeting template found. - -require_relative '../dfareporting_utils' - -def get_targeting_templates(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_targeting_templates(profile_id, - page_token: token, - fields: 'nextPageToken,targetingTemplates(advertiserId,id,name)') - - # Display results. - if result.targeting_templates.any? - result.targeting_templates.each do |template| - puts format( - 'Found targeting template with ID %d and name "%s" associated with ' \ - 'advertiser ID %d.', template.id, template.name, - template.advertiser_id - ) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_targeting_templates(args[:profile_id]) -end diff --git a/ruby/v4/user_profiles/get_user_profiles.rb b/ruby/v4/user_profiles/get_user_profiles.rb deleted file mode 100755 index 6752b7b..0000000 --- a/ruby/v4/user_profiles/get_user_profiles.rb +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example illustrates how to list all user profiles - -require_relative '../dfareporting_utils' - -def get_user_profiles - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Get all user profiles. - result = service.list_user_profiles - - # Display results. - result.items.each do |profile| - puts format( - 'User profile with ID %d and name "%s" was found for account %d.', - profile.profile_id, profile.user_name, profile.account_id - ) - end -end - -get_user_profiles if $PROGRAM_NAME == __FILE__ diff --git a/ruby/v4/user_roles/create_user_role.rb b/ruby/v4/user_roles/create_user_role.rb deleted file mode 100755 index 2d3aecf..0000000 --- a/ruby/v4/user_roles/create_user_role.rb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example creates a user role in a given DCM account. -# -# To get the account ID, run get_all_userprofiles.rb. To get the parent user -# role ID, run get_user_roles.rb. - -require_relative '../dfareporting_utils' -require 'securerandom' - -def create_user_role(profile_id, account_id, parent_role_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - # Create a new user role resource to insert. - user_role = DfareportingUtils::API_NAMESPACE::UserRole.new( - account_id: account_id, - name: format('Example User Role #%s', SecureRandom.hex(3)), - parent_user_role_id: parent_role_id - ) - - # Insert the user role. - result = service.insert_user_role(profile_id, user_role) - - # Display results. - puts format('Created user role with ID %d and name "%s".', result.id, - result.name) -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id, :account_id, - :parent_role_id) - - create_user_role(args[:profile_id], args[:account_id], - args[:parent_role_id]) -end diff --git a/ruby/v4/user_roles/get_user_roles.rb b/ruby/v4/user_roles/get_user_roles.rb deleted file mode 100755 index 9faf8f2..0000000 --- a/ruby/v4/user_roles/get_user_roles.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby - -# -# Copyright:: Copyright 2016, Google Inc. All Rights Reserved. -# -# License:: Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This example displays all user roles. - -require_relative '../dfareporting_utils' - -def get_user_roles(profile_id) - # Authenticate and initialize API service. - service = DfareportingUtils.initialize_service - - token = nil - loop do - result = service.list_user_roles(profile_id, - page_token: token, - fields: 'nextPageToken,userRoles(id,name)') - - # Display results. - if result.user_roles.any? - result.user_roles.each do |role| - puts format('Found user role with ID %d and name "%s".', role.id, - role.name) - end - - token = result.next_page_token - else - # Stop paging if there are no more results. - token = nil - end - - break if token.to_s.empty? - end -end - -if $PROGRAM_NAME == __FILE__ - # Retrieve command line arguments. - args = DfareportingUtils.parse_arguments(ARGV, :profile_id) - - get_user_roles(args[:profile_id]) -end