#!/usr/bin/perl -w
use
lib
"$Bin/../../lib"
;
use
Google::Ads::GoogleAds::V19::Services::CustomerAssetService::CustomerAssetOperation;
my
$customer_id
=
"INSERT_CUSTOMER_ID_HERE"
;
my
$language_code
=
"INSERT_LANGUAGE_CODE_HERE"
;
sub
add_hotel_callout {
my
(
$api_client
,
$customer_id
,
$language_code
) =
@_
;
my
$hotel_callout_asset_resource_names
=
add_hotel_callout_assets(
$api_client
,
$customer_id
,
$language_code
);
link_assets_to_account(
$api_client
,
$customer_id
,
$hotel_callout_asset_resource_names
);
return
1;
}
sub
add_hotel_callout_assets {
my
(
$api_client
,
$customer_id
,
$language_code
) =
@_
;
my
$hotel_callout_assets
= [];
push
@$hotel_callout_assets
,
Google::Ads::GoogleAds::V19::Common::HotelCalloutAsset->new({
text
=>
"Activities"
,
languageCode
=>
$language_code
});
push
@$hotel_callout_assets
,
Google::Ads::GoogleAds::V19::Common::HotelCalloutAsset->new({
text
=>
"Facilities"
,
languageCode
=>
$language_code
});
my
$operations
= [];
foreach
my
$hotel_callout_asset
(
@$hotel_callout_assets
) {
push
@$operations
,
Google::Ads::GoogleAds::V19::Services::AssetService::AssetOperation->new({
create
=> Google::Ads::GoogleAds::V19::Resources::Asset->new({
hotelCalloutAsset
=>
$hotel_callout_asset
})});
}
my
$response
=
$api_client
->AssetService()->mutate({
customerId
=>
$customer_id
,
operations
=>
$operations
});
my
$resource_names
= [];
foreach
my
$result
(@{
$response
->{results}}) {
push
@$resource_names
,
$result
->{resourceName};
printf
"Created hotel callout asset with resource name '%s'.\n"
,
$result
->{resourceName};
}
return
$resource_names
;
}
sub
link_assets_to_account {
my
(
$api_client
,
$customer_id
,
$hotel_callout_asset_resource_names
) =
@_
;
my
$operations
= [];
foreach
my
$hotel_callout_asset_resource_name
(
@$hotel_callout_asset_resource_names
)
{
push
@$operations
,
Google::Ads::GoogleAds::V19::Services::CustomerAssetService::CustomerAssetOperation
->new({
create
=> Google::Ads::GoogleAds::V19::Resources::CustomerAsset->new({
asset
=>
$hotel_callout_asset_resource_name
,
fieldType
=> HOTEL_CALLOUT
})});
}
my
$response
=
$api_client
->CustomerAssetService()->mutate({
customerId
=>
$customer_id
,
operations
=>
$operations
});
foreach
my
$result
(@{
$response
->{results}}) {
printf
"Added a account asset with resource name '%s'.\n"
,
$result
->{resourceName};
}
}
if
(abs_path($0) ne abs_path(__FILE__)) {
return
1;
}
my
$api_client
= Google::Ads::GoogleAds::Client->new();
$api_client
->set_die_on_faults(1);
GetOptions(
"customer_id=s"
=> \
$customer_id
,
"language_code=s"
=> \
$language_code
);
pod2usage(2)
if
not check_params(
$customer_id
,
$language_code
);
add_hotel_callout(
$api_client
,
$customer_id
=~ s/-//gr,
$language_code
);