class NicoUtil::Niconico

Public Class Methods

new(email, pass) click to toggle source
# File lib/nico_util.rb, line 15
def initialize email, pass
  @cookie = nil
  @email = email
  @pass = pass

  login
end

Public Instance Methods

blog(blog_id) click to toggle source
# File lib/nico_util/blog.rb, line 3
def blog blog_id
  Blog.new self, blog_id
end
book(book_id) click to toggle source
# File lib/nico_util/book.rb, line 3
def book book_id
  Book.new self, book_id
end
channel(channel_id) click to toggle source
# File lib/nico_util/channel.rb, line 3
def channel channel_id
  Channel.new self, channel_id
end
check_logged_in!() click to toggle source
# File lib/nico_util.rb, line 57
def check_logged_in!
  unless logged_in?
    raise AuthenticationError, "You are not authorized..."
  end
end
comic(live_id) click to toggle source
# File lib/nico_util/comic.rb, line 3
def comic live_id
  Comic.new self, live_id
end
illust(illust_id) click to toggle source
# File lib/nico_util/illust.rb, line 5
def illust illust_id
  Illust.new self, illust_id
end
live(live_id) click to toggle source
# File lib/nico_util/live.rb, line 3
def live live_id
  Live.new self, live_id
end
logged_in?() click to toggle source
# File lib/nico_util.rb, line 53
def logged_in?
  @cookie != nil
end
login() click to toggle source
# File lib/nico_util.rb, line 28
def login
  host = 'secure.nicovideo.jp'
  path = '/secure/login?site=niconico'
  body = "mail=#{@email}&password=#{@pass}"

  https = Net::HTTP.new host, 443
  https.use_ssl = true
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = https.start do |https|
    https.post path, body
  end

  @cookie = nil
  response['set-cookie'].split('; ').each do |st|
    if idx=st.index('user_session_')
      @cookie = "user_session=#{st[idx..-1]}"
      break
    end
  end

  unless @cookie
    puts 'Invalid email or password'
  end
end
news(news_id) click to toggle source
# File lib/nico_util/news.rb, line 3
def news news_id
  News.new self, news_id
end
video(video_id) click to toggle source
# File lib/nico_util/video.rb, line 3
def video video_id
  Video.new self, video_id
end