Class: SnapchatApi::Resources::Ad
- Inherits:
-
Base
- Object
- Base
- SnapchatApi::Resources::Ad
show all
- Defined in:
- lib/snapchat_api/resources/ad.rb
Instance Attribute Summary
Attributes inherited from Base
#client
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#create(ad_squad_id:, params:) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/snapchat_api/resources/ad.rb', line 4
def create(ad_squad_id:, params:)
ads_data = {ads: [**params]}
response = client.request(:post, "adsquads/#{ad_squad_id}/ads", ads_data)
response.body["ads"].first["ad"]
end
|
#delete(ad_id:) ⇒ Object
42
43
44
45
|
# File 'lib/snapchat_api/resources/ad.rb', line 42
def delete(ad_id:)
response = client.request(:delete, "ads/#{ad_id}")
response.success?
end
|
#get(ad_id:) ⇒ Object
37
38
39
40
|
# File 'lib/snapchat_api/resources/ad.rb', line 37
def get(ad_id:)
response = client.request(:get, "ads/#{ad_id}")
response.body["ads"].first["ad"]
end
|
#get_stats(ad_id:, params: {}) ⇒ Object
56
57
58
59
|
# File 'lib/snapchat_api/resources/ad.rb', line 56
def get_stats(ad_id:, params: {})
response = client.request(:get, "ads/#{ad_id}/stats", params)
response.body
end
|
#list_all_by(entity_id:, entity: :ad_squad, params: {}) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/snapchat_api/resources/ad.rb', line 11
def list_all_by(entity_id:, entity: :ad_squad, params: {})
params[:limit] ||= 50
ads = []
next_link = case entity
when :ad_squad
"adsquads/#{entity_id}/ads?limit=#{params[:limit]}"
when :ad_account
"adaccounts/#{entity_id}/ads?limit=#{params[:limit]}"
when :campaign
"campaigns/#{entity_id}/ads?limit=#{params[:limit]}"
else
raise ArgumentError, "Invalid entity type: #{entity}. Must be :ad_squad, :ad_account, or :campaign."
end
loop do
response = client.request(:get, next_link)
next_link = response.body["paging"]["next_link"]
ads.concat(response.body["ads"].map { |el| el["ad"] })
break if next_link.nil?
end
ads
end
|
#update(ad_squad_id:, params:) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/snapchat_api/resources/ad.rb', line 47
def update(ad_squad_id:, params:)
ad_data = {
ads: [**params.merge(ad_squad_id: ad_squad_id)]
}
response = client.request(:put, "adsquads/#{ad_squad_id}/ads", ad_data)
response.body["ads"].first["ad"]
end
|