Class: Epodder::Add
Instance Method Summary
collapse
Methods inherited from Verb
#add_command, #each_argument, #lookup_args, #verb_struct
Constructor Details
#initialize ⇒ Add
Returns a new instance of Add.
3
4
|
# File 'lib/verb/add.rb', line 3
def initialize
end
|
Instance Method Details
#add(args) ⇒ Object
6
7
8
9
10
|
# File 'lib/verb/add.rb', line 6
def add(args)
args.each do |url|
lookup_podcast url
end
end
|
#lookup_podcast(url) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/verb/add.rb', line 12
def lookup_podcast(url)
feed = Feedzirra::Feed.fetch_and_parse(url)
unless feed.is_a?(Fixnum)
save_podcast feed, url
else
puts "Error #{url} returned #{feed}"
end
end
|
#save_podcast(feed, url) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/verb/add.rb', line 21
def save_podcast(feed, url)
podcast = Podcast.first_or_create(
title: feed.title,
uri: url
)
podcast.save
podcast.errors.each do |error|
@log.error error
end
puts "#{podcast.id} - #{podcast.title}"
end
|