From e81280ae20ab9d1ff43d3c3fd0e7c158f132660d Mon Sep 17 00:00:00 2001 From: Andrew Kuklewicz Date: Fri, 13 Dec 2024 00:54:18 -0500 Subject: [PATCH] Fix update episode --- app/controllers/placements_preview_controller.rb | 2 +- app/models/megaphone/episode.rb | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/placements_preview_controller.rb b/app/controllers/placements_preview_controller.rb index 364303186..3356141f8 100644 --- a/app/controllers/placements_preview_controller.rb +++ b/app/controllers/placements_preview_controller.rb @@ -5,8 +5,8 @@ class PlacementsPreviewController < ApplicationController # GET /podcasts/1/placements_preview/2 def show - @fetch_error = cached_placements.nil? @zones = get_zones(params[:id].to_i) + @fetch_error = @zones.nil? end private diff --git a/app/models/megaphone/episode.rb b/app/models/megaphone/episode.rb index 1b7c15b79..5cab9e362 100644 --- a/app/models/megaphone/episode.rb +++ b/app/models/megaphone/episode.rb @@ -19,6 +19,8 @@ class Episode < Integrations::Base::Episode insertion_points guid pre_offset post_offset expected_adhash original_filename original_url episode_number season_number retain_ad_locations advertising_tags ad_free] + UPDATE_ATTRIBUTES = CREATE_ATTRIBUTES + # All other attributes we might expect back from the Megaphone API # (some documented, others not so much) OTHER_ATTRIBUTES = %i[id podcast_id created_at updated_at status @@ -69,7 +71,7 @@ def self.attributes_from_episode(e) external_id: e.guid, guid: e.item_guid, pubdate: e.published_at, - pubdate_timezone: e.published_at.zone, + pubdate_timezone: e.published_at, author: e.author_name, link: e.url, explicit: e.explicit, @@ -106,9 +108,11 @@ def create! self end - def update!(feed = nil) - if feed - self.attributes = self.class.attributes_from_feed(feed) + def update!(episode = nil) + if episode + self.attributes = self.class.attributes_from_episode(episode) + set_placement_attributes + set_audio_attributes end validate!(:update) body = as_json(only: UPDATE_ATTRIBUTES.map(&:to_s)) @@ -240,7 +244,7 @@ def set_placement_attributes def adhash_for_placement(zones) zones - .filter { |z| z[:type] == "ad" } + .filter { |z| ["ad", "sonic_id", "house"].include?(z[:type]) } .map { |z| ADHASH_VALUES[z[:section]] } .join("") end