Skip to content

Commit

Permalink
Fix update episode
Browse files Browse the repository at this point in the history
  • Loading branch information
kookster committed Dec 13, 2024
1 parent 94ae8ac commit e81280a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/placements_preview_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions app/models/megaphone/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e81280a

Please sign in to comment.