Class: TiktokBusinessApi::Resources::Ad

Inherits:
CrudResource show all
Defined in:
lib/tiktok_business_api/resources/ad.rb

Overview

Ad resource for the TikTok Business API

Constant Summary collapse

RESOURCE_NAME =
'ad'

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from CrudResource

#create_path, #delete_path, #id_param_name, #ids_param_name, #list_all, #list_path, #resource_name, #status_update_path, #update_path

Methods inherited from BaseResource

#_http_get, #_http_post, #api_version, #base_path, #initialize, #paginate, #resource_name

Constructor Details

This class inherits a constructor from TiktokBusinessApi::Resources::BaseResource

Instance Method Details

#create(advertiser_id:, adgroup_id:, creatives:) ⇒ Hash

Create a new ad

Parameters:

  • advertiser_id (String)

    Advertiser ID

  • adgroup_id (String)

    Ad group ID

  • creatives (Array<Hash>)

    Array of creative objects

Returns:

  • (Hash)

    New ad data with created ad IDs



19
20
21
22
23
24
25
26
27
28
# File 'lib/tiktok_business_api/resources/ad.rb', line 19

def create(advertiser_id:, adgroup_id:, creatives:)
  params = {
    advertiser_id: advertiser_id,
    adgroup_id: adgroup_id,
    creatives: creatives
  }

  response = _http_post(create_path, params)
  response['data']
end

#create_aco(advertiser_id:, adgroup_id:, creatives:) ⇒ Hash

Create Smart Creative ads

Parameters:

  • advertiser_id (String)

    Advertiser ID

  • adgroup_id (String)

    Ad group ID

  • creatives (Array<Hash>)

    Array of creative objects

Returns:

  • (Hash)

    New Smart Creative ad data



90
91
92
93
94
95
96
97
98
99
# File 'lib/tiktok_business_api/resources/ad.rb', line 90

def create_aco(advertiser_id:, adgroup_id:, creatives:)
  params = {
    advertiser_id: advertiser_id,
    adgroup_id: adgroup_id,
    creatives: creatives
  }

  response = _http_post('aco/create/', params)
  response['data']
end

#delete(advertiser_id:, ad_id:) ⇒ Hash

Delete an ad

Parameters:

  • advertiser_id (String)

    Advertiser ID

  • ad_id (String)

    Ad ID

Returns:

  • (Hash)

    Result



74
75
76
77
78
79
80
81
82
# File 'lib/tiktok_business_api/resources/ad.rb', line 74

def delete(advertiser_id:, ad_id:)
  params = {
    advertiser_id: advertiser_id,
    ad_ids: [ad_id]
  }

  response = _http_post(delete_path, params)
  response['data']
end

#get(advertiser_id:, ad_id:) ⇒ Object



9
10
11
# File 'lib/tiktok_business_api/resources/ad.rb', line 9

def get(advertiser_id:, ad_id:)
  list(advertiser_id: advertiser_id, filtering: {ad_ids: [ad_id]}).first
end

#list(advertiser_id:, campaign_id: nil, adgroup_id: nil, filtering: {}, page_size: nil, page: nil, **other_params, &block) ⇒ Object



30
31
32
33
34
# File 'lib/tiktok_business_api/resources/ad.rb', line 30

def list(advertiser_id:, campaign_id: nil, adgroup_id: nil, filtering: {}, page_size: nil, page: nil, **other_params, &block)
  filtering[:campaign_ids] = [campaign_id] if campaign_id
  filtering[:adgroup_ids] = [adgroup_id] if adgroup_id
  super(filtering: filtering, page_size: page_size, page: page, **other_params.merge(advertiser_id: advertiser_id), &block)
end

#update(advertiser_id:, ad_id:, **params) ⇒ Hash

Update an ad

Parameters:

  • advertiser_id (String)

    Advertiser ID

  • ad_id (String)

    Ad ID

  • params (Hash)

    Ad parameters to update

Returns:

  • (Hash)

    Updated ad data



42
43
44
45
46
47
48
49
50
# File 'lib/tiktok_business_api/resources/ad.rb', line 42

def update(advertiser_id:, ad_id:, **params)
  params = params.merge(
    advertiser_id: advertiser_id,
    ad_id: ad_id
  )

  response = _http_post(update_path, params)
  response['data']
end

#update_status(advertiser_id:, ad_id:, status:) ⇒ Hash

Update ad status (enable/disable)

Parameters:

  • advertiser_id (String)

    Advertiser ID

  • ad_id (String)

    Ad ID

  • status (String)

    New status (‘ENABLE’ or ‘DISABLE’)

Returns:

  • (Hash)

    Result



58
59
60
61
62
63
64
65
66
67
# File 'lib/tiktok_business_api/resources/ad.rb', line 58

def update_status(advertiser_id:, ad_id:, status:)
  params = {
    advertiser_id: advertiser_id,
    ad_ids: [ad_id],
    operation_status: status
  }

  response = _http_post('status/update/', params)
  response['data']
end