Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1fe963
commit f82da83
Showing
4 changed files
with
58 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class Feed::AppleSubscription < Feed | ||
DEFAULT_FEED_SLUG = "apple-delegated-delivery-subscriptions" | ||
DEFAULT_TITLE = "Apple Delegated Delivery Subscriptions" | ||
DEFAULT_AUDIO_FORMAT = {"f" => "flac", "b" => 16, "c" => 2, "s" => 44100}.freeze | ||
|
||
has_one :apple_config, class_name: "::Apple::Config", dependent: :destroy, autosave: true, validate: true | ||
has_one :apple_key, | ||
through: :apple_config, | ||
class_name: "Apple::Key", | ||
dependent: :destroy, | ||
foreign_key: :key_id | ||
|
||
accepts_nested_attributes_for :apple_config, allow_destroy: true, reject_if: :all_blank | ||
accepts_nested_attributes_for :apple_key, allow_destroy: true, reject_if: :all_blank | ||
|
||
def self.model_name | ||
Feed.model_name | ||
end | ||
|
||
def self.find_or_build_private_feed(podcast) | ||
if (existing = podcast.feeds.find_by(slug: DEFAULT_FEED_SLUG, title: DEFAULT_TITLE)) | ||
# TODO, handle partitions on apple models via the apple_config | ||
# Until then it's not safe to have multiple apple_configs for the same podcast | ||
Rails.logger.error("Found existing private feed for #{podcast.title}!") | ||
Rails.logger.error("Do you want to continue? (y/N)") | ||
raise "Stopping find_or_build_private_feed" if $stdin.gets.chomp.downcase != "y" | ||
|
||
return existing | ||
end | ||
default_feed = podcast.default_feed | ||
|
||
Feed.new( | ||
display_episodes_count: default_feed.display_episodes_count, | ||
slug: DEFAULT_FEED_SLUG, | ||
title: DEFAULT_TITLE, | ||
audio_format: DEFAULT_AUDIO_FORMAT, | ||
include_zones: ["billboard", "sonic_id"], | ||
tokens: [FeedToken.new(label: DEFAULT_TITLE)], | ||
podcast: podcast | ||
) | ||
end | ||
|
||
# TODO: this a helper for onboarding via console, retrofit when the UX catches up | ||
def self.build_apple_config(podcast, key) | ||
if podcast.apple_config | ||
Rails.logger.error("Found existing apple config for #{podcast.title}!") | ||
Rails.logger.error("Do you want to continue? (y/N)") | ||
raise "Stopping build_apple_config" if $stdin.gets.chomp.downcase != "y" | ||
end | ||
|
||
Apple::Config.new(feed: find_or_build_private_feed(podcast), key: key) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Feed::AppleSubscriptionPolicy < ApplicationPolicy | ||
def show? | ||
true | ||
end | ||
end |