Class: OpdsMonster::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/opds_monster/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed_url, options = {}) ⇒ Feed

Returns a new instance of Feed.



8
9
10
11
12
13
# File 'lib/opds_monster/feed.rb', line 8

def initialize(feed_url, options = {})
  @feed_url = feed_url
  @feed_items = []
  @username = options[:username]
  self.password = options[:password]
end

Instance Attribute Details

#feed_itemsObject

Returns the value of attribute feed_items.



4
5
6
# File 'lib/opds_monster/feed.rb', line 4

def feed_items
  @feed_items
end

#feed_urlObject (readonly)

Returns the value of attribute feed_url.



3
4
5
# File 'lib/opds_monster/feed.rb', line 3

def feed_url
  @feed_url
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/opds_monster/feed.rb', line 6

def password
  @password
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/opds_monster/feed.rb', line 5

def username
  @username
end

Instance Method Details

#authentication_required?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/opds_monster/feed.rb', line 28

def authentication_required?
  username.nil?
end

#download_all_itemsObject



21
22
23
24
25
26
# File 'lib/opds_monster/feed.rb', line 21

def download_all_items
  items.each do |item|
    item.download(:username => username, :password => password)
    yield item, true
  end
end

#itemsObject



15
16
17
18
19
# File 'lib/opds_monster/feed.rb', line 15

def items
  return self.feed_items unless feed_items.empty?
  feed = Atom::Feed.load_feed(URI.parse(feed_url), :user => username, :pass => password)
  self.feed_items = feed.each_entry.collect { |entry| FeedItem.new(entry) }  
end