@@ -138,4 +138,99 @@ def users(params)
138138 end
139139
140140 end
141+
142+ class TailoredAudiencePermission
143+
144+ include TwitterAds ::DSL
145+ include TwitterAds ::Resource
146+
147+ attr_reader :account
148+
149+ # read-only
150+ property :created_at , type : :time , read_only : true
151+ property :updated_at , type : :time , read_only : true
152+ property :deleted , type : :bool , read_only : true
153+
154+ property :id
155+ property :tailored_audience_id
156+ property :granted_account_id
157+ property :permission_level
158+
159+ RESOURCE_COLLECTION = "/#{ TwitterAds ::API_VERSION } /" \
160+ 'accounts/%{account_id}/tailored_audiences/' \
161+ '%{tailored_audience_id}/permissions' # @api private
162+ RESOURCE = "/#{ TwitterAds ::API_VERSION } /" \
163+ 'accounts/%{account_id}/tailored_audiences/' \
164+ '%{tailored_audience_id}/permissions/%{id}' # @api private
165+
166+ def initialize ( account )
167+ @account = account
168+ self
169+ end
170+
171+ class << self
172+
173+ # Retrieve details for some or
174+ # all permissions associated with the specified tailored audience.
175+ #
176+ # @exapmle
177+ # permissions = TailoredAudiencePermission.all(account, '36n4f')
178+ #
179+ # @param account [Account] The account object instance.
180+ # @param tailored_audience_id [String] The tailored audience id.
181+ #
182+ # @since 5.2.0
183+ #
184+ # @return [TailoredAudiencePermission] The tailored audience permission instance.
185+ def all ( account , tailored_audience_id , opts = { } )
186+ params = { } . merge! ( opts )
187+ resource = RESOURCE_COLLECTION % {
188+ account_id : account . id ,
189+ tailored_audience_id : tailored_audience_id
190+ }
191+ request = Request . new ( account . client , :get , resource , params : params )
192+ Cursor . new ( self , request , init_with : [ account ] )
193+ end
194+
195+ end
196+
197+ # Saves or updates the current object instance
198+ # depending on the presence of `object.tailored_audience_id`.
199+ #
200+ # @exapmle
201+ # object.save
202+ #
203+ # @since 5.2.0
204+ #
205+ # @return [self] Returns the instance refreshed from the API.
206+ def save
207+ resource = RESOURCE_COLLECTION % {
208+ account_id : account . id ,
209+ tailored_audience_id : tailored_audience_id
210+ }
211+ params = to_params
212+ response = Request . new ( account . client , :post , resource , params : params ) . perform
213+ from_response ( response . body [ :data ] )
214+ end
215+
216+ # Deletes the current or specified tailored audience permission.
217+ #
218+ # @example
219+ # object.delete!
220+ #
221+ # Note: calls to this method are destructive and irreverisble.
222+ #
223+ # @since 5.2.0
224+ #
225+ # @return [self] Returns the instance refreshed from the API.
226+ def delete!
227+ resource = RESOURCE % {
228+ account_id : account . id ,
229+ tailored_audience_id : tailored_audience_id ,
230+ id : @id
231+ }
232+ response = Request . new ( account . client , :delete , resource ) . perform
233+ from_response ( response . body [ :data ] )
234+ end
235+ end
141236end
0 commit comments