Class: Bnicovideo::Mylist
- Inherits:
-
Object
- Object
- Bnicovideo::Mylist
- Defined in:
- lib/bnicovideo/mylist.rb
Overview
Mylist class
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Mylist author.
-
#mylist_id ⇒ Object
readonly
Mylist ID.
-
#subtitle ⇒ Object
readonly
Mylist description.
-
#title ⇒ Object
readonly
Mylist title.
-
#videos ⇒ Object
readonly
Videos’ hash.
Instance Method Summary collapse
-
#initialize(user_session, mylist_id) ⇒ Mylist
constructor
- Init from user session and mylist ID user_session
- Bnicovideo::UserSession mylist_id
-
Mylist ID.
-
#read(refresh = false) ⇒ Object
- Read information refresh
-
If this is true, force read.
-
#read! ⇒ Object
Force read information.
Constructor Details
#initialize(user_session, mylist_id) ⇒ Mylist
Init from user session and mylist ID
- user_session
-
Bnicovideo::UserSession
- mylist_id
-
Mylist ID
25 26 27 28 29 |
# File 'lib/bnicovideo/mylist.rb', line 25 def initialize(user_session, mylist_id) @got = false @user_session = user_session @mylist_id = mylist_id end |
Instance Attribute Details
#author ⇒ Object (readonly)
Mylist author
21 22 23 |
# File 'lib/bnicovideo/mylist.rb', line 21 def @author end |
#mylist_id ⇒ Object (readonly)
Mylist ID
13 14 15 |
# File 'lib/bnicovideo/mylist.rb', line 13 def mylist_id @mylist_id end |
#subtitle ⇒ Object (readonly)
Mylist description
19 20 21 |
# File 'lib/bnicovideo/mylist.rb', line 19 def subtitle @subtitle end |
#title ⇒ Object (readonly)
Mylist title
17 18 19 |
# File 'lib/bnicovideo/mylist.rb', line 17 def title @title end |
#videos ⇒ Object (readonly)
Videos’ hash. Video key is Bnicovideo::Video class object, and Content key is mylist description.
15 16 17 |
# File 'lib/bnicovideo/mylist.rb', line 15 def videos @videos end |
Instance Method Details
#read(refresh = false) ⇒ Object
Read information
- refresh
-
If this is true, force read. Otherwise, read unless not read.
58 59 60 61 |
# File 'lib/bnicovideo/mylist.rb', line 58 def read(refresh = false) return if @got && !refresh read! end |
#read! ⇒ Object
Force read information
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bnicovideo/mylist.rb', line 31 def read! @videos = [] resp = nil Net::HTTP.start('www.nicovideo.jp') do |http| resp = http.get('/mylist/' + @mylist_id.to_s + '?rss=atom', {'Cookie' => 'user_session=' + @user_session.session_id}) end resp.value xml = REXML::Document.new(resp.body) root = xml.root @title = root.elements['title'].text @subtitle = root.elements['subtitle'].text @author = root.elements['author/name'].text root.elements.each('entry') do |entry| video_link = entry.elements['link'].attributes['href'] uri = URI.parse(video_link) next unless uri.scheme == 'http' && uri.host == 'www.nicovideo.jp' video_id = uri.path.split('/')[-1] @videos.push({ 'Video' => Bnicovideo::Video.new(@user_session, video_id), 'Content' => entry.elements['content'].text }) end @got = true end |