Class: Epodder::Add

Inherits:
Verb show all
Defined in:
lib/verb/add.rb

Instance Method Summary collapse

Methods inherited from Verb

#add_command, #each_argument, #lookup_args, #verb_struct

Constructor Details

#initializeAdd

Returns a new instance of Add.



3
4
5
# File 'lib/verb/add.rb', line 3

def initialize
  @mechanize = Mechanize.new
end

Instance Method Details

#add(args) ⇒ Object



7
8
9
10
11
# File 'lib/verb/add.rb', line 7

def add args
  args.each do |url|
    lookup_podcast url
  end
end

#lookup_podcast(url) ⇒ Object



13
14
15
16
17
# File 'lib/verb/add.rb', line 13

def lookup_podcast url
  @mechanize.get(url) do |feed|
    save_podcast feed, url
  end
end

#save_podcast(feed, url) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/verb/add.rb', line 19

def save_podcast feed, url
  cast = FeedMe.parse feed.body
  cast.emulate_atom!
  podcast = Podcast.first_or_create(
    :title => cast.title,
    :uri => url
  )
  podcast.save

  podcast.errors.each do |error|
    @log.error error
  end
 puts "#{podcast.id} - #{podcast.title}"
end