class CrowdFundingParser::Parser::Taobao
Public Class Methods
new()
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 7 def initialize @parse_method = :json @url = "http://hi.taobao.com/market/hi/detail2014.php?id=" end
Public Instance Methods
get_project_links(status = "online")
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 12 def get_project_links(status = "online") status_code = get_status_code(status) jsons = get_total_jsons(status_code) links = [] Parallel.each(jsons, in_precesses: 2, in_threads: 5) do |json| project_id = json["id"].to_s project_url = @url + project_id links << project_url end links end
get_status_code(status)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 25 def get_status_code(status) case status when "online" 1 when "preparing" 3 when "finished" 2 else 1 end end
get_total_json_apis(status = 1)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 49 def get_total_json_apis(status = 1) page_count = get_total_page(status) total_urls = [] page_count.to_i.times do |i| total_urls << get_projects_page_api(i + 1, status) end total_urls end
get_total_jsons(status = 1)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 38 def get_total_jsons(status = 1) urls = get_total_json_apis(status) jsons = [] urls.each do |url| page_json = get_json_through_url(url) json = page_json["data"] jsons += json end jsons end
get_total_page(status = 1)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 58 def get_total_page(status = 1) url = "http://hstar-hi.alicdn.com/dream/ajax/getProjectList.htm?page=1&pageSize=20&projectType=&type=6&status=#{status}" json = get_json_through_url(url) page_count = json["pageTotal"] end
Private Instance Methods
get_id(project_url)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 74 def get_id(project_url) project_url.split("id=").last end
get_project_api(project_id)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 66 def get_project_api(project_id) "http://hstar-hi.alicdn.com/dream/ajax/getProjectForDetail.htm?id=#{project_id}" end
get_projects_page_api(page = 1, status = 1)
click to toggle source
# File lib/crowd_funding_parser/parser/taobao.rb, line 70 def get_projects_page_api(page = 1, status = 1) "http://hstar-hi.alicdn.com/dream/ajax/getProjectList.htm?page=#{page}&pageSize=20&projectType=&type=6&status=#{status}" end