|
1 | 1 | # frozen_string_literal: true |
2 | 2 | # Copyright (C) 2019 Twitter, Inc. |
3 | 3 |
|
| 4 | +require 'digest' |
4 | 5 | require 'twitter-ads' |
5 | 6 | include TwitterAds::Enum |
6 | 7 |
|
|
21 | 22 | # load up the account instance |
22 | 23 | account = client.accounts(ADS_ACCOUNT) |
23 | 24 |
|
24 | | -# create a new tailored audience |
| 25 | +# create a new placeholder tailored audience |
25 | 26 | audience = |
26 | | - TwitterAds::TailoredAudience.create(account, '/path/to/file', 'my list', TAListTypes::Email) |
27 | | - |
28 | | -# check the processing status |
29 | | -audience.status |
| 27 | + TwitterAds::TailoredAudience.create(account, 'Test TA') |
| 28 | + |
| 29 | +# sample user |
| 30 | +# all values musth be sha256 hashede except 'partner_user_id' |
| 31 | +email_hash = Digest::SHA256.hexdigest 'test-email@test.com' |
| 32 | + |
| 33 | +# create payload |
| 34 | +user = [{ |
| 35 | + operation_type: 'Update', |
| 36 | + params: { |
| 37 | + users: [{ |
| 38 | + email: [ |
| 39 | + email_hash |
| 40 | + ] |
| 41 | + }] |
| 42 | + } |
| 43 | +}] |
30 | 44 |
|
31 | 45 | # update the tailored audience |
32 | | -audience.update('/path/to/file', 'TWITTER_ID', TAOperations::REMOVE) |
33 | | -audience.update('/path/to/file', 'PHONE_NUMBER', TAOperations::ADD) |
34 | | - |
35 | | -# delete the tailored audience |
36 | | -audience.delete! |
37 | | - |
38 | | -# add users to the account's global opt-out list |
39 | | -TwitterAds::TailoredAudience.opt_out(account, '/path/to/file', TAListTypes::HANDLE) |
| 46 | +success_count, total_count = audience.users(user) |
| 47 | +print "Successfully added #{total_count} users" if success_count == total_count |
0 commit comments