From 1786413421bfb002ddc6729c03f0e9fd3929622e Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 2 Aug 2023 14:51:18 -0500 Subject: [PATCH 1/4] Don't alter data unless needed --- app/models/apple/show.rb | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/app/models/apple/show.rb b/app/models/apple/show.rb index 577f08673..cf96c174a 100644 --- a/app/models/apple/show.rb +++ b/app/models/apple/show.rb @@ -63,21 +63,32 @@ def category_data [{"type" => "categories", "id" => "1301"}] end - def show_data + def update_attributes + create_attributes.except(:releaseFrequency, :thirdPartyRights) + end + + def create_attributes { - data: { - type: "shows", - relationships: { - allowedCountriesAndRegions: {data: api.countries_and_regions} - }, - attributes: { - kind: "RSS", - rssUrl: feed_published_url, - releaseFrequency: "OPTOUT", - thirdPartyRights: "HAS_RIGHTS_TO_THIRD_PARTY_CONTENT" + kind: "RSS", + rssUrl: feed_published_url, + releaseFrequency: "WEEKLY", + thirdPartyRights: "HAS_RIGHTS_TO_THIRD_PARTY_CONTENT" + } + end + + def show_data(attributes, id: nil) + res = + { + data: { + type: "shows", + relationships: { + allowedCountriesAndRegions: {data: api.countries_and_regions} + }, + attributes: attributes } } - } + res[:data][:id] = id if id.present? + res end def apple_id @@ -106,7 +117,7 @@ def sync! end def create_show! - data = show_data + data = show_data(create_attributes) Rails.logger.info("Creating show", show_data: data) resp = api.post("shows", data) @@ -114,10 +125,9 @@ def create_show! end def update_show!(sync) - show_data_with_id = show_data - show_data_with_id[:data][:id] = sync.external_id - Rails.logger.info("Updating show", show_data: show_data_with_id) - resp = api.patch("shows/#{sync.external_id}", show_data_with_id) + data = show_data(update_attributes, id: apple_id) + Rails.logger.info("Updating show", show_data: data) + resp = api.patch("shows/#{sync.external_id}", data) api.response(resp) end From d646b73d037ef7a7093e5c3f3b4e9fa853faf43f Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 2 Aug 2023 15:14:44 -0500 Subject: [PATCH 2/4] Fixup test for show_data coverage --- test/models/apple/show_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/apple/show_test.rb b/test/models/apple/show_test.rb index 9064dfece..dd4a58cc3 100644 --- a/test/models/apple/show_test.rb +++ b/test/models/apple/show_test.rb @@ -161,7 +161,7 @@ describe "#show_data" do it "returns a hash" do - assert_equal apple_show.show_data.class, Hash + assert_equal apple_show.show_data({}).class, Hash end end From a4b710743c99030d0f44bf51480ca1d9d9a87b6b Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 2 Aug 2023 15:15:32 -0500 Subject: [PATCH 3/4] Need to specify third party rights --- app/models/apple/show.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/apple/show.rb b/app/models/apple/show.rb index cf96c174a..91d2acf72 100644 --- a/app/models/apple/show.rb +++ b/app/models/apple/show.rb @@ -64,7 +64,7 @@ def category_data end def update_attributes - create_attributes.except(:releaseFrequency, :thirdPartyRights) + create_attributes.except(:releaseFrequency) end def create_attributes From 5538391a86ca4e1b17d30783f9005d5435493627 Mon Sep 17 00:00:00 2001 From: Sam Vevang Date: Wed, 2 Aug 2023 15:32:56 -0500 Subject: [PATCH 4/4] Skip updates completely --- app/models/apple/show.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/apple/show.rb b/app/models/apple/show.rb index 91d2acf72..7ca100c64 100644 --- a/app/models/apple/show.rb +++ b/app/models/apple/show.rb @@ -125,11 +125,15 @@ def create_show! end def update_show!(sync) - data = show_data(update_attributes, id: apple_id) - Rails.logger.info("Updating show", show_data: data) - resp = api.patch("shows/#{sync.external_id}", data) - - api.response(resp) + Rails.logger.warn("Skipping update for existing show!") + nil + + # TODO, map out the cases where we'd actually need to update a show + # data = show_data(update_attributes, id: apple_id) + # Rails.logger.info("Updating show", show_data: data) + # resp = api.patch("shows/#{sync.external_id}", data) + # + # api.response(resp) end def create_or_update_show(sync)