module TheTradeDeskAds # https://developers.facebook.com/docs/marketing-api/reference/custom-audience class AdAudience < Base FIELDS = %w[AdvertiserId AudienceId AudienceName Description IncludedDataGroupIds ExcludedDataGroupIds IsAutoGenerated].freeze SORTING_FIELDS = {"Name": "Name", "Description": "Description"} class << self # facets = TheTradeDeskAds::AdAudience.facets def facets(query = {}) get('audience/query/facets', query: query, objectify: false) end def all(query = {}) get('/me/adaccounts', query: query, objectify: true) end def find_by(conditions) all.detect do |object| conditions.all? do |key, value| object.send(key) == value end end end end # belongs_to advertiser def ad_advertiser @ad_advertiser ||= AdAdvertiser.find(AdvertiserId) end # actions def share(account_id) query = { share_with_object_id: account_id, share_with_object_type: 'Account' } result = AdAccount.post("/#{id}/share_with_objects", query: query) # result['success'] result # No idea what this response looks like. end end end