class BilibiliSunday::RequestHandler

Public Class Methods

new(downloader) click to toggle source
# File lib/bilibili_sunday/server.rb, line 11
def initialize(downloader)
        @downloader = downloader
end

Public Instance Methods

handle_active_videos() click to toggle source
# File lib/bilibili_sunday/server.rb, line 65
def handle_active_videos
        return 200, {result: @downloader.active_videos}
end
handle_all_videos() click to toggle source
# File lib/bilibili_sunday/server.rb, line 61
def handle_all_videos
        return 200, {result: @downloader.all_videos}
end
handle_cid_for_video_url(url) click to toggle source
# File lib/bilibili_sunday/server.rb, line 45
def handle_cid_for_video_url(url)
        return 200, {result: @downloader.cid_for_video_url(url)}
end
handle_error(error_code, error_message) click to toggle source
# File lib/bilibili_sunday/server.rb, line 73
def handle_error(error_code, error_message)
        return 500, {error: {code: error_code, message: error_message}}
end
handle_query_status(cid) click to toggle source
# File lib/bilibili_sunday/server.rb, line 57
def handle_query_status(cid)
        return 200, {result: @downloader.query_status(cid)}
end
handle_remove_cache(cid) click to toggle source
# File lib/bilibili_sunday/server.rb, line 69
def handle_remove_cache(cid)
        return 200, {result: @downloader.remove_cache(cid)}
end
handle_request(method, params) click to toggle source
# File lib/bilibili_sunday/server.rb, line 15
def handle_request(method, params)
        begin
                result = /^bilibili_sunday.(.*?)$/.match(method)

                return handle_error(1, 'No matching method. ') unless result

                method = result[1]

                if method == 'cid_for_video_url'
                        handle_cid_for_video_url(params[0])
                elsif method == 'title_for_video_url'
                        handle_title_for_video_url(params[0])
                elsif method == 'request_cache'
                        handle_request_cache(params[0].to_i)
                elsif method == 'query_status'
                        handle_query_status(params[0].to_i)
                elsif method == 'all_videos'
                        handle_all_videos
                elsif method == 'active_videos'
                        handle_active_videos
                elsif method == 'remove_cache'
                        handle_remove_cache(params[0].to_i)
                else
                        handle_error(1, 'No matching method. ')
                end
        rescue
                return handle_error(2, 'Internal server error. ')
        end
end
handle_request_cache(cid) click to toggle source
# File lib/bilibili_sunday/server.rb, line 53
def handle_request_cache(cid)
        return 200, {result: @downloader.request_cache(cid)}
end
handle_title_for_video_url(url) click to toggle source
# File lib/bilibili_sunday/server.rb, line 49
def handle_title_for_video_url(url)
        return 200, {result: @downloader.title_for_video_url(url)}
end