Class: Posthubify::AdsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/posthubify/resources/ads.rb

Overview

Ads lifecycle (Node sdk .ads): accounts, campaigns, audiences, lead-gen, conversions (CAPI), targeting, ad-set/ad hierarchy, comments, catalogs.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ AdsResource

Returns a new instance of AdsResource.



7
8
9
# File 'lib/posthubify/resources/ads.rb', line 7

def initialize(http)
  @http = http
end

Instance Method Details

#accountsObject

Connected ad accounts.



12
13
14
# File 'lib/posthubify/resources/ads.rb', line 12

def accounts
  @http.data('GET', '/ads/accounts')
end

#ad_comments(id, ad_id) ⇒ Object

An ad’s comments.



195
196
197
# File 'lib/posthubify/resources/ads.rb', line 195

def ad_comments(id, ad_id)
  @http.data('GET', "/ads/accounts/#{id}/ads/#{ad_id}/comments")
end

#ad_sets(id, campaign_id) ⇒ Object

A campaign’s ad sets.



158
159
160
# File 'lib/posthubify/resources/ads.rb', line 158

def ad_sets(id, campaign_id)
  @http.data('GET', "/ads/accounts/#{id}/campaigns/#{campaign_id}/adsets")
end

#ads(id, ad_set_id) ⇒ Object

An ad set’s ads.



168
169
170
# File 'lib/posthubify/resources/ads.rb', line 168

def ads(id, ad_set_id)
  @http.data('GET', "/ads/accounts/#{id}/adsets/#{ad_set_id}/ads")
end

#audiences(id) ⇒ Object

Custom audiences.



101
102
103
# File 'lib/posthubify/resources/ads.rb', line 101

def audiences(id)
  @http.data('GET', "/ads/accounts/#{id}/audiences")
end

#bulk_campaign_status(id, campaign_ids, status) ⇒ Object

Bulk status (≤50 campaigns) — returns a per-campaign ok/error result.



63
64
65
# File 'lib/posthubify/resources/ads.rb', line 63

def bulk_campaign_status(id, campaign_ids, status)
  @http.data('POST', "/ads/accounts/#{id}/campaigns/bulk-status", body: { 'campaignIds' => campaign_ids, 'status' => status })
end

#campaign_timeline(id, campaign_id, since: nil, until_: nil) ⇒ Object

Campaign’s daily performance timeline (from report rows).



79
80
81
# File 'lib/posthubify/resources/ads.rb', line 79

def campaign_timeline(id, campaign_id, since: nil, until_: nil)
  @http.data('GET', "/ads/accounts/#{id}/campaigns/#{campaign_id}/timeline", query: { 'since' => since, 'until' => until_ })
end

#campaign_tree(id, campaign_id) ⇒ Object

Campaign → ad sets → ads hierarchy (single call).



163
164
165
# File 'lib/posthubify/resources/ads.rb', line 163

def campaign_tree(id, campaign_id)
  @http.data('GET', "/ads/accounts/#{id}/campaigns/#{campaign_id}/tree")
end

#campaigns(id, status: nil) ⇒ Object

List campaigns (optional status filter).



48
49
50
# File 'lib/posthubify/resources/ads.rb', line 48

def campaigns(id, status: nil)
  @http.data('GET', "/ads/accounts/#{id}/campaigns", query: { 'status' => status })
end

#capabilities(id) ⇒ Object

This ad account’s platform capabilities (pre-discovery instead of trial-and-error).



28
29
30
# File 'lib/posthubify/resources/ads.rb', line 28

def capabilities(id)
  @http.data('GET', "/ads/accounts/#{id}/capabilities")
end

#catalogs(id) ⇒ Object

Product catalogs.



217
218
219
# File 'lib/posthubify/resources/ads.rb', line 217

def catalogs(id)
  @http.data('GET', "/ads/accounts/#{id}/catalogs")
end

#connect_oauth_start(platform, profile_id: nil, label: nil) ⇒ Object

── Headless ADS OAuth connect (D8 cp4) — tempToken start/status. ──Start headless ADS OAuth → authUrl: open authUrl in a browser, then poll status.



18
19
20
# File 'lib/posthubify/resources/ads.rb', line 18

def connect_oauth_start(platform, profile_id: nil, label: nil)
  @http.data('POST', '/ads/connect/oauth/start', body: { 'platform' => platform, 'profileId' => profile_id, 'label' => label })
end

#connect_oauth_status(temp_token) ⇒ Object

Headless ADS OAuth status (poll): pending | connected (+account) | error.



23
24
25
# File 'lib/posthubify/resources/ads.rb', line 23

def connect_oauth_status(temp_token)
  @http.data('GET', '/ads/connect/oauth/status', query: { 'tempToken' => temp_token })
end

#create_audience(id, input) ⇒ Object

Create an audience (name/description).



106
107
108
# File 'lib/posthubify/resources/ads.rb', line 106

def create_audience(id, input)
  @http.data('POST', "/ads/accounts/#{id}/audiences", body: input)
end

#create_campaign(id, input, idempotency_key: nil) ⇒ Object

Create a campaign. input is a camelCase-keyed Hash (name/budget/budgetType/objective/status).



53
54
55
# File 'lib/posthubify/resources/ads.rb', line 53

def create_campaign(id, input, idempotency_key: nil)
  @http.data('POST', "/ads/accounts/#{id}/campaigns", body: input, idempotency_key: idempotency_key)
end

#creative_targets(id) ⇒ Object

Creative targets (pages/boards).



89
90
91
# File 'lib/posthubify/resources/ads.rb', line 89

def creative_targets(id)
  @http.data('GET', "/ads/accounts/#{id}/creative-targets")
end

#customers(id) ⇒ Object

Platform-side ad accounts (one login → multiple accounts; for select).



33
34
35
# File 'lib/posthubify/resources/ads.rb', line 33

def customers(id)
  @http.data('GET', "/ads/accounts/#{id}/customers")
end

#delete_ad(id, ad_id) ⇒ Object

Delete an ad.



188
189
190
# File 'lib/posthubify/resources/ads.rb', line 188

def delete_ad(id, ad_id)
  @http.data('DELETE', "/ads/accounts/#{id}/ads/#{ad_id}")
end

#delete_ad_comment(id, comment_id) ⇒ Object

Delete an ad comment.



210
211
212
# File 'lib/posthubify/resources/ads.rb', line 210

def delete_ad_comment(id, comment_id)
  @http.data('DELETE', "/ads/accounts/#{id}/comments/#{comment_id}")
end

#delete_ad_set(id, ad_set_id) ⇒ Object

Delete an ad set.



178
179
180
# File 'lib/posthubify/resources/ads.rb', line 178

def delete_ad_set(id, ad_set_id)
  @http.data('DELETE', "/ads/accounts/#{id}/adsets/#{ad_set_id}")
end

#delete_audience(id, audience_id) ⇒ Object

Delete an audience.



111
112
113
# File 'lib/posthubify/resources/ads.rb', line 111

def delete_audience(id, audience_id)
  @http.data('DELETE', "/ads/accounts/#{id}/audiences/#{audience_id}")
end

#delete_campaign(id, campaign_id) ⇒ Object

Delete a campaign.



74
75
76
# File 'lib/posthubify/resources/ads.rb', line 74

def delete_campaign(id, campaign_id)
  @http.data('DELETE', "/ads/accounts/#{id}/campaigns/#{campaign_id}")
end

#duplicate_campaign(id, campaign_id, name = nil) ⇒ Object

Duplicate a campaign — the copy starts PAUSED (to avoid accidental spend).



68
69
70
71
# File 'lib/posthubify/resources/ads.rb', line 68

def duplicate_campaign(id, campaign_id, name = nil)
  body = name ? { 'name' => name } : {}
  @http.data('POST', "/ads/accounts/#{id}/campaigns/#{campaign_id}/duplicate", body: body)
end

#hide_ad_comment(id, comment_id, hidden = true) ⇒ Object

Hide/show an ad comment (default hide).



205
206
207
# File 'lib/posthubify/resources/ads.rb', line 205

def hide_ad_comment(id, comment_id, hidden = true)
  @http.data('POST', "/ads/accounts/#{id}/comments/#{comment_id}/hide", body: { 'hidden' => hidden })
end

#lead_forms(id) ⇒ Object

Lead-gen forms.



121
122
123
# File 'lib/posthubify/resources/ads.rb', line 121

def lead_forms(id)
  @http.data('GET', "/ads/accounts/#{id}/lead-forms")
end

#leads(id, form_id, limit: nil) ⇒ Object

A form’s lead records (optional limit).



126
127
128
# File 'lib/posthubify/resources/ads.rb', line 126

def leads(id, form_id, limit: nil)
  @http.data('GET', "/ads/accounts/#{id}/lead-forms/#{form_id}/leads", query: { 'limit' => limit })
end

#pixels(id) ⇒ Object

Conversion pixels.



131
132
133
# File 'lib/posthubify/resources/ads.rb', line 131

def pixels(id)
  @http.data('GET', "/ads/accounts/#{id}/pixels")
end

#product_sets(id, catalog_id) ⇒ Object

A catalog’s product sets.



222
223
224
# File 'lib/posthubify/resources/ads.rb', line 222

def product_sets(id, catalog_id)
  @http.data('GET', "/ads/accounts/#{id}/catalogs/#{catalog_id}/product-sets")
end

#promote(id, input, idempotency_key: nil) ⇒ Object

Create an ad with a creative. mediaUrl may only come from your own media store (SSRF protection).



94
95
96
# File 'lib/posthubify/resources/ads.rb', line 94

def promote(id, input, idempotency_key: nil)
  @http.data('POST', "/ads/accounts/#{id}/promote", body: input, idempotency_key: idempotency_key)
end

#reach_estimate(id, targeting) ⇒ Object

Reach estimate (targeting is a camelCase-keyed Hash).



146
147
148
# File 'lib/posthubify/resources/ads.rb', line 146

def reach_estimate(id, targeting)
  @http.data('POST', "/ads/accounts/#{id}/reach-estimate", body: targeting)
end

#readiness(id) ⇒ Object

Billing/publishing readiness — check before promote.



43
44
45
# File 'lib/posthubify/resources/ads.rb', line 43

def readiness(id)
  @http.data('GET', "/ads/accounts/#{id}/readiness")
end

#reply_ad_comment(id, comment_id, message) ⇒ Object

Reply to an ad comment.



200
201
202
# File 'lib/posthubify/resources/ads.rb', line 200

def reply_ad_comment(id, comment_id, message)
  @http.data('POST', "/ads/accounts/#{id}/comments/#{comment_id}/reply", body: { 'message' => message })
end

#report(id, since: nil, until_: nil) ⇒ Object

Account report rows (optional date range).



84
85
86
# File 'lib/posthubify/resources/ads.rb', line 84

def report(id, since: nil, until_: nil)
  @http.data('GET', "/ads/accounts/#{id}/report", query: { 'since' => since, 'until' => until_ })
end

#search_interests(id, q) ⇒ Object

Interest targeting search.



141
142
143
# File 'lib/posthubify/resources/ads.rb', line 141

def search_interests(id, q)
  @http.data('GET', "/ads/accounts/#{id}/targeting/interests", query: { 'q' => q })
end

#select(id, ad_account_id) ⇒ Object

Select the active ad account for this login.



38
39
40
# File 'lib/posthubify/resources/ads.rb', line 38

def select(id, )
  @http.data('POST', "/ads/accounts/#{id}/select", body: { 'adAccountId' =>  })
end

#send_conversions(id, input) ⇒ Object

CAPI relay (≤1000 events) — raw email/phone is hashed on the server; use testEventCode for a safe trial.



136
137
138
# File 'lib/posthubify/resources/ads.rb', line 136

def send_conversions(id, input)
  @http.data('POST', "/ads/accounts/#{id}/conversions", body: input)
end

#set_ad_set_status(id, ad_set_id, status) ⇒ Object

Ad set status (enabled/paused).



173
174
175
# File 'lib/posthubify/resources/ads.rb', line 173

def set_ad_set_status(id, ad_set_id, status)
  @http.data('POST', "/ads/accounts/#{id}/adsets/#{ad_set_id}/status", body: { 'status' => status })
end

#set_ad_status(id, ad_id, status) ⇒ Object

Ad status (enabled/paused).



183
184
185
# File 'lib/posthubify/resources/ads.rb', line 183

def set_ad_status(id, ad_id, status)
  @http.data('POST', "/ads/accounts/#{id}/ads/#{ad_id}/status", body: { 'status' => status })
end

#set_campaign_status(id, campaign_id, status) ⇒ Object

Single campaign status (enabled/paused).



58
59
60
# File 'lib/posthubify/resources/ads.rb', line 58

def set_campaign_status(id, campaign_id, status)
  @http.data('POST', "/ads/accounts/#{id}/campaigns/#{campaign_id}/status", body: { 'status' => status })
end

#update_campaign(id, campaign_id, patch) ⇒ Object

Update a campaign (patch: name/budget/budgetType/bidAmount/status).



153
154
155
# File 'lib/posthubify/resources/ads.rb', line 153

def update_campaign(id, campaign_id, patch)
  @http.data('PATCH', "/ads/accounts/#{id}/campaigns/#{campaign_id}", body: patch)
end

#upload_audience_users(id, audience_id, input) ⇒ Object

Upload members to an audience (≤10k/request). Raw emails/phones → server SHA-256; if pre-hashed, use the hashed* fields.



116
117
118
# File 'lib/posthubify/resources/ads.rb', line 116

def upload_audience_users(id, audience_id, input)
  @http.data('POST', "/ads/accounts/#{id}/audiences/#{audience_id}/users", body: input)
end