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 "      insert or ignore into episodes\n      (title, release_date, podcast_id, duration, link, external_id)\n      values (\n        \"\#{escape_double_quotes(e.title)}\",\n        \"\#{escape_double_quotes(e.release_date)}\",\n        \#{podcast_id},\n        \"\#{escape_double_quotes(e.duration)}\",\n        \"\#{escape_double_quotes(e.link)}\",\n        \"\#{e.external_id}\"\n      );\n    SQL\n  end\n  build_success_response(details: :podcast_synchronized)\nend\n"