Skip to content

Commit

Permalink
Start episode publishing and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kookster committed Dec 3, 2024
1 parent 5fb3048 commit f562866
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
5 changes: 0 additions & 5 deletions app/models/apple/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ class Show < Integrations::Base::Show

attr_reader :api

def initialize(public_feed:, private_feed:)
@public_feed = public_feed
@private_feed = private_feed
end

def self.apple_shows_json(api)
api.get_paged_collection("shows")
end
Expand Down
16 changes: 16 additions & 0 deletions app/models/megaphone/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ def self.attributes_from_episode(e)
}
end

def synced_with_integration?
delivery_status&.delivered?
end

def integration_new?
false
end

def archived?
false
end

def delivery_status
feeder_episode&.episode_delivery_status(:megaphone)
end

def set_placement_attributes
placement = get_placement(feeder_episode.segment_count)
self.expected_adhash = adhash_for_placement(placement)
Expand Down
4 changes: 2 additions & 2 deletions app/models/megaphone/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show

def publish!
sync_podcast!
raise "Missing Megaphone Podcast!" unless megaphone_podcast&.id.present?
sync_episodes!

# success
SyncLog.log!(
Expand All @@ -26,7 +26,7 @@ def publish!
)
end

def deliver_and_publish!
def sync_episodes!
episodes = episodes_to_sync
puts "deliver_and_publish!: #{episodes.count}"
end
Expand Down
34 changes: 33 additions & 1 deletion test/models/megaphone/publisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,38 @@
end
end

describe "sync_episodes!" do
let(:episode) { create(:episode, podcast: podcast) }

before do
stub_request(:get, "https://cms.megaphone.fm/api/networks/this-is-a-network-id/podcasts/A1B2C4D5E6F7G8")
.to_return(status: 200, body: {id: "A1B2C4D5E6F7G8", updatedAt: (Time.now + 1.minute).utc.iso8601}.to_json, headers: {})

SyncLog.log!(
integration: :megaphone,
feeder_id: public_feed.id,
feeder_type: :feeds,
external_id: "A1B2C4D5E6F7G8",
api_response: {request: {}, items: {}}
)
end

it "should create new draft episodes" do
assert episode
puts episode.inspect
publisher.sync_episodes!
end

it "should update episodes" do
end

it "should update episodes with audio" do
end

it "should update episodes with incomplete audio" do
end
end

describe "#sync_podcast!" do
it "should create a new podcast" do
stub_request(:get, "https://cms.megaphone.fm/api/networks/this-is-a-network-id/podcasts?externalId=95ebfb22-0002-5f78-a7aa-5acb5ac7daa9")
Expand Down Expand Up @@ -47,7 +79,7 @@
assert_equal megaphone_podcast.id, "A1B2C4D5E6F7G8"
end

it "should find a podcast by guid" do
it "should find and update a podcast by guid" do
stub_request(:get, "https://cms.megaphone.fm/api/networks/this-is-a-network-id/podcasts?externalId=95ebfb22-0002-5f78-a7aa-5acb5ac7daa9")
.to_return(status: 200, body: [{id: "DEF67890", updatedAt: "2024-11-03T14:54:02.690Z"}].to_json, headers: {})

Expand Down

0 comments on commit f562866

Please sign in to comment.