@@ -20,6 +20,7 @@ class TailoredAudience
2020 property :audience_size , read_only : true
2121 property :audience_type , read_only : true
2222 property :metadata , read_only : true
23+ property :owner_account_id , read_only : true
2324 property :partner_source , read_only : true
2425 property :reasons_not_targetable , read_only : true
2526 property :targetable , type : :bool , read_only : true
@@ -91,7 +92,7 @@ def delete!
9192 from_response ( response . body [ :data ] )
9293 end
9394
94- # This is a private API and requires whitelisting from Twitter.
95+ # This is a private API and requires allowlisting from Twitter.
9596 #
9697 # This endpoint will allow partners to add, update and remove users from a given
9798 # tailored_audience_id.
@@ -137,6 +138,60 @@ def users(params)
137138 [ success_count , total_count ]
138139 end
139140
141+ # Retrieves the entites targeting the current tailored audience instance.
142+ #
143+ # @example
144+ # audience.targeted(with_active=true)
145+ #
146+ # @param with_active [bool] Include active/inactive
147+ #
148+ # @since 8.0.0
149+ #
150+ # @return [self] Returns a Cursor instance of the targeted entities.
151+ def targeted ( opts = { } )
152+ validate_loaded
153+ params = { } . merge! ( opts )
154+ TargetedTailoredAudience . load ( account , id , params )
155+ end
156+
157+ def validate_loaded
158+ raise ArgumentError . new (
159+ "Error! #{ self . class } object not yet initialized, " \
160+ "call #{ self . class } .load first" ) if id . nil?
161+ end
162+ end
163+
164+ class TargetedTailoredAudience
165+
166+ include TwitterAds ::DSL
167+ include TwitterAds ::Resource
168+
169+ attr_reader :account
170+
171+ # read-only
172+ property :campaign_id , read_only : true
173+ property :campaign_name , read_only : true
174+ property :line_items , read_only : true
175+
176+ RESOURCE_TARGETED = "/#{ TwitterAds ::API_VERSION } /" \
177+ 'accounts/%{account_id}/tailored_audiences/%{id}/targeted' # @api private
178+
179+ def initialize ( account )
180+ @account = account
181+ self
182+ end
183+
184+ class << self
185+
186+ def load ( account , tailored_audience_id , params )
187+ resource = RESOURCE_TARGETED % { account_id : account . id , id : tailored_audience_id }
188+ request = TwitterAds ::Request . new ( account . client ,
189+ :get ,
190+ resource ,
191+ params : params )
192+ Cursor . new ( self , request , init_with : [ account ] )
193+ end
194+ end
140195 end
141196
142197 class TailoredAudiencePermission
0 commit comments