Class: Niconico::Live::Mypage
- Inherits:
-
Object
- Object
- Niconico::Live::Mypage
- Defined in:
- lib/niconico/live/mypage.rb
Defined Under Namespace
Classes: UnknownStatus
Constant Summary collapse
- URL =
'http://live.nicovideo.jp/my'.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #agent ⇒ Object
- #available_reservations ⇒ Object
-
#initialize(client) ⇒ Mypage
constructor
A new instance of Mypage.
- #page ⇒ Object
- #reservations ⇒ Object (also: #timeshift_list)
- #unaccepted_reservations ⇒ Object
Constructor Details
#initialize(client) ⇒ Mypage
Returns a new instance of Mypage.
15 16 17 |
# File 'lib/niconico/live/mypage.rb', line 15 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
19 20 21 |
# File 'lib/niconico/live/mypage.rb', line 19 def client @client end |
Instance Method Details
#agent ⇒ Object
21 22 23 |
# File 'lib/niconico/live/mypage.rb', line 21 def agent client.agent end |
#available_reservations ⇒ Object
58 59 60 |
# File 'lib/niconico/live/mypage.rb', line 58 def available_reservations reservations.select { |_| _.reservation_available? } end |
#page ⇒ Object
25 26 27 |
# File 'lib/niconico/live/mypage.rb', line 25 def page @page ||= agent.get(URL) end |
#reservations ⇒ Object Also known as: timeshift_list
29 30 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/niconico/live/mypage.rb', line 29 def reservations return @reservations if @reservations lists = page.search("form[name=timeshift_list] .liveItems") @reservations = lists.flat_map do |list| list.search('.column').map do |column| link = column.at('.name a') id = link[:href].sub(/\A.*\//,'').sub(/\?.*\z/,'') status = column.at('.status').inner_text = column.at('.timeshift_watch a') preload = {} preload[:title] = link[:title] preload[:reservation] = Live::API.(status) raise UnknownStatus, "BUG, there's unknown message for reservation status: #{status.inspect}" unless preload[:reservation] # (試聴する) [試聴期限未定] if && [:onclick] && [:onclick].include?('confirm_watch_my') preload[:reservation][:status] = :reserved preload[:reservation][:available] = true end Niconico::Live.new(client, id, preload) end end end |
#unaccepted_reservations ⇒ Object
62 63 64 |
# File 'lib/niconico/live/mypage.rb', line 62 def unaccepted_reservations reservations.select { |_| _.reservation_unaccepted? } end |