From f9b9713a89fca0742c89bcf41f2a7c3d3eeaa2b1 Mon Sep 17 00:00:00 2001 From: Shohei Maeda Date: Thu, 21 Nov 2019 20:22:42 +0900 Subject: [PATCH] Fix MediaLibrary class (#211) - duplicate save method and introduce add(POST) and update(PUT) methods --- lib/twitter-ads/creative/media_library.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/twitter-ads/creative/media_library.rb b/lib/twitter-ads/creative/media_library.rb index f980219d..1aa4b4cd 100644 --- a/lib/twitter-ads/creative/media_library.rb +++ b/lib/twitter-ads/creative/media_library.rb @@ -29,7 +29,6 @@ class MediaLibrary property :description property :file_name property :name - property :poster_image_media_id property :poster_media_key property :title @@ -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