Class: SnapchatApi::Resources::Creative

Inherits:
Base
  • Object
show all
Defined in:
lib/snapchat_api/resources/creative.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SnapchatApi::Resources::Base

Instance Method Details

#create(ad_account_id:, params: {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/snapchat_api/resources/creative.rb', line 25

def create(ad_account_id:, params: {})
  creatives_data = {
    creatives: [**params]
  }

  response = client.request(:post, "adaccounts/#{}/creatives", creatives_data)
  response.body["creatives"].first["creative"]
end

#get(creative_id:) ⇒ Object



20
21
22
23
# File 'lib/snapchat_api/resources/creative.rb', line 20

def get(creative_id:)
  response = client.request(:get, "creatives/#{creative_id}")
  response.body["creatives"].first["creative"]
end

#list_all(ad_account_id:, params: {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/snapchat_api/resources/creative.rb', line 4

def list_all(ad_account_id:, params: {})
  params[:limit] ||= 50

  creatives = []
  next_link = "adaccounts/#{}/creatives?limit=#{params[:limit]}"

  loop do
    response = client.request(:get, next_link)
    next_link = response.body["paging"]["next_link"]
    creatives.concat(response.body["creatives"].map { |el| el["creative"] })
    break if next_link.nil?
  end

  creatives
end

#update(ad_account_id:, creative_id:, params: {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/snapchat_api/resources/creative.rb', line 34

def update(ad_account_id:, creative_id:, params: {})
  creatives_data = {
    creatives: [**params.merge(id: creative_id, ad_account_id:)]
  }

  response = client.request(:put, "adaccounts/#{}/creatives", creatives_data)
  response.body["creatives"].first["creative"]
end