class CrowdFundingParser::Parser::Kickstarter

Public Class Methods

new() click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 7
def initialize
  @platform_url = "https://www.kickstarter.com"
  @category_ids = [1, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26]
  @parse_method = :doc
end

Public Instance Methods

get_all_categories(status = "online") click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 13
def get_all_categories(status = "online")
  status_code = get_status_code(status)
  jsons = get_category_project_jsons(status_code)
  jsons.flatten.compact!
  categories = []
  Parallel.each(jsons, in_precesses: 2, in_threads: 5) do |json|
    category = { id: json["category"]["id"], name: json["category"]["name"], parent_id: json["category"]["parent_id"]}
    categories << category
  end
  categories.uniq
end
get_category_project_jsons(status_code = "live", category_id = 0) click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 41
def get_category_project_jsons(status_code = "live", category_id = 0)
  jsons = []

  Parallel.each(1..200, in_precesses: 2, in_threads: 5) do |i|
    begin
      api_url = get_projects_page_api(i, status_code, category_id)
      json = get_json_through_url(api_url)["projects"]
      jsons << json
    rescue Exception => e
      Parallel::Stop
    end
  end
  jsons
end

Private Instance Methods

get_project_page_api(project_url) click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 58
def get_project_page_api(project_url)
  project_url.split("?").first + ".json"
end
get_project_search_doc_api(name) click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 66
def get_project_search_doc_api(name)
  "https://www.kickstarter.com/projects/search.json?term=#{name}"
end
get_projects_page_api(page = 1, status_code = "live", category_id = 0) click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 62
def get_projects_page_api(page = 1, status_code = "live", category_id = 0)
  "https://www.kickstarter.com/projects/search.json?page=#{page}&state=#{status_code}&category_id=#{category_id}"
end
get_status_code(status) click to toggle source
# File lib/crowd_funding_parser/parser/kickstarter.rb, line 70
def get_status_code(status)
  case status
  when "online"
    "live"
  when "finished"
    "successful"
  else
    "live"
  end
end