<commit_before># encoding: utf-8
require 'prx_access'

class Distributions::PodcastDistribution < Distribution
  include PRXAccess
  include Rails.application.routes.url_helpers

  def distribute!
    super
    add_podcast_to_feeder
  end

  def story_distribution_class
    StoryDistributions::EpisodeDistribution
  end

  def add_podcast_to_feeder
    return unless url.blank?
    client = api(root: feeder_root, account: account.id)
    podcast = client.podcasts.first.post(podcast_attributes)
    podcast_url = URI.join(feeder_root, podcast.links['self'].href).to_s
    raise 'Failed to get podcast url on create' if podcast_url.blank?
    update_attributes!(url: podcast_url)
  end

  def get_podcast
    api(root: feeder_root, account: account.id).tap { |a| a.href = url }.get
  end

  def podcast_attributes
    attrs = {
      prx_uri: polymorphic_url(['api', owner], only_path: true),
      prx_account_uri: api_account_path(account),
      published_at: Time.now
    }

    if owner.is_a?(Series)
      attrs[:title] = owner.title
      attrs[:subtitle] = owner.short_description
      attrs[:description] = owner.description
      attrs[:summary] = owner.description
      if owner.images.profile
        attrs[:itunes_image] = { url: owner.images.profile.public_url(version: 'original') }
      end

      if owner.images.thumbnail
        attrs[:feed_image] = { url: owner.images.thumbnail.public_url(version: 'original') }
      end
    end

    attrs
  end
end<commit_msg>nicer helper method for getting image urls<commit_after># encoding: utf-8
require 'prx_access'

class Distributions::PodcastDistribution < Distribution
  include PRXAccess
  include Rails.application.routes.url_helpers

  def distribute!
    super
    add_podcast_to_feeder
  end

  def story_distribution_class
    StoryDistributions::EpisodeDistribution
  end

  def add_podcast_to_feeder
    return unless url.blank?
    client = api(root: feeder_root, account: account.id)
    podcast = client.podcasts.first.post(podcast_attributes)
    podcast_url = URI.join(feeder_root, podcast.links['self'].href).to_s
    raise 'Failed to get podcast url on create' if podcast_url.blank?
    update_attributes!(url: podcast_url)
  end

  def get_podcast
    api(root: feeder_root, account: account.id).tap { |a| a.href = url }.get
  end

  def podcast_attributes
    attrs = {
      prx_uri: polymorphic_url(['api', owner], only_path: true),
      prx_account_uri: api_account_path(account),
      published_at: Time.now
    }

    if owner.is_a?(Series)
      attrs[:title] = owner.title
      attrs[:subtitle] = owner.short_description
      attrs[:description] = owner.description
      attrs[:summary] = owner.description
      if owner.images.profile
        attrs[:itunes_image] = { url: image_url(:profile) }
      end

      if owner.images.thumbnail
        attrs[:feed_image] = { url: image_url(:thumbnail) }
      end
    end

    attrs
  end

  def image_url(purpose)
    owner.images.try(purpose).public_url(version: 'original')
  end
end
{'fraction_non_alphanumeric': 0.09567799406136589, 'fraction_numerical': 0.0006598482349059716, 'mean_word_length': 3.5253731343283583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3130953', 'n_tokens_mistral': 973, 'n_tokens_neox': 941, 'n_words': 208}