Module: FacebookAds::Test::Fixtures
- Included in:
- Base
- Defined in:
- lib/facebook_ads/test/fixtures.rb
Instance Method Summary collapse
- #ad_account ⇒ Object
- #create_ad(params = {}) ⇒ Object
- #create_ad_set(campaign = nil, params = {}) ⇒ Object
- #create_adlabel ⇒ Object
- #create_campaign(params = {}) ⇒ Object
- #create_creative(image = nil, params = {}) ⇒ Object
- #create_image ⇒ Object
- #randomize(string) ⇒ Object
Instance Method Details
#ad_account ⇒ Object
24 25 26 |
# File 'lib/facebook_ads/test/fixtures.rb', line 24 def ad_account FacebookAds::AdAccount.get(config.account_id) end |
#create_ad(params = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/facebook_ads/test/fixtures.rb', line 34 def create_ad(params = {}) ad_set ||= create_ad_set.tap { |c| yield c if block_given? } creative ||= create_creative.tap { |c| yield c if block_given? } params = { name: 'My Ad', adset_id: ad_set.id, creative: { creative_id: creative.id, }, status: 'PAUSED', } ad = ad_account.ads.create(params) end |
#create_ad_set(campaign = nil, params = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/facebook_ads/test/fixtures.rb', line 68 def create_ad_set(campaign = nil, params = {}) # yield generated object to add them to cleanup queue campaign ||= create_campaign.tap { |c| yield c if block_given? } ad_account.adsets.create({ campaign_id: campaign.id, name: randomize('Test AdSet'), targeting: { geo_locations: { countries: ['US'] } }, optimization_goal: 'IMPRESSIONS', billing_event: 'IMPRESSIONS', bid_amount: 100, daily_budget: 1000, }) end |
#create_adlabel ⇒ Object
28 29 30 31 32 |
# File 'lib/facebook_ads/test/fixtures.rb', line 28 def create_adlabel ad_account.adlabels.create({ name: randomize('My ad label') }) end |
#create_campaign(params = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/facebook_ads/test/fixtures.rb', line 57 def create_campaign(params = {}) params = { name: randomize('Testing Campaign'), buying_type: 'AUCTION', objective: 'LINK_CLICKS', status: 'PAUSED', }.merge(params) ad_account.campaigns.create(params) end |
#create_creative(image = nil, params = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/facebook_ads/test/fixtures.rb', line 85 def create_creative(image = nil, params = {}) image ||= create_image ad_account.adcreatives.create({ name: randomize('Test Creative'), object_story_spec: { page_id: config.page_id, link_data: { message: 'try it out', link: config.app_url, caption: 'www.example.com', image_hash: image.hash, } } }) end |
#create_image ⇒ Object
50 51 52 53 54 55 |
# File 'lib/facebook_ads/test/fixtures.rb', line 50 def create_image images = ad_account.adimages.create({ filename: config.image_path }) images[0] end |
#randomize(string) ⇒ Object
102 103 104 |
# File 'lib/facebook_ads/test/fixtures.rb', line 102 def randomize(string) "#{string} #{SecureRandom.hex}" end |