Skip to content

Commit

Permalink
Fix MediaLibrary class (#211)
Browse files Browse the repository at this point in the history
- duplicate save method and introduce add(POST) and update(PUT) methods
  • Loading branch information
smaeda-ks authored Nov 21, 2019
1 parent d7a99e3 commit f9b9713
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/twitter-ads/creative/media_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class MediaLibrary
property :description
property :file_name
property :name
property :poster_image_media_id
property :poster_media_key
property :title

Expand All @@ -46,15 +45,17 @@ def reload(account, opts = {})
end
end

def save
def add
params = to_params
if @media_key
resource = self.class::RESOURCE % { account_id: account.id, id: media_key }
response = Request.new(account.client, :put, resource, params: params).perform
else
resource = self.class::RESOURCE_COLLECTION % { account_id: account.id }
response = Request.new(account.client, :post, resource, params: params).perform
end
resource = self.class::RESOURCE_COLLECTION % { account_id: account.id }
response = Request.new(account.client, :post, resource, params: params).perform
from_response(response.body[:data])
end

def update
params = to_params
resource = self.class::RESOURCE % { account_id: account.id, id: media_key }
response = Request.new(account.client, :put, resource, params: params).perform
from_response(response.body[:data])
end

Expand Down

0 comments on commit f9b9713

Please sign in to comment.