Class: Podrb::Commands::Sync::Runner

Inherits:
BaseRunner show all
Defined in:
lib/podrb/commands/sync/runner.rb

Instance Method Summary collapse

Methods inherited from BaseRunner

call

Instance Method Details

#call(podcast_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/podrb/commands/sync/runner.rb', line 9

def call(podcast_id)
  db = Infrastructure::Storage::SQL.new(db: podrb_db_dir)
  podcast = db.query("select feed from podcasts where id = #{podcast_id}").first
  return build_failure_response(details: :not_found) if podcast.nil?

  parsed_feed = Infrastructure::FeedParser.call(podcast.feed)
  parsed_feed.episodes.each do |e|
    db.execute <<-SQL
      insert or ignore into episodes
      (title, release_date, podcast_id, duration, link, external_id)
      values (
        "#{escape_double_quotes(e.title)}",
        "#{escape_double_quotes(e.release_date)}",
        #{podcast_id},
        "#{escape_double_quotes(e.duration)}",
        "#{escape_double_quotes(e.link)}",
        "#{e.external_id}"
      );
    SQL
  end
  build_success_response(details: :podcast_synchronized)
end