Class: CrowdFundingParser::Parser::Kickstarter

Inherits:
General
  • Object
show all
Defined in:
lib/crowd_funding_parser/parser/kickstarter.rb

Instance Method Summary collapse

Methods inherited from General

#get_doc_through_url, #get_id, #get_json_through_url, #get_project, #get_result, #parse_content_data, #parse_tracking_data

Constructor Details

#initializeKickstarter

Returns a new instance of Kickstarter.



7
8
9
10
11
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CrowdFundingParser::Parser::General

Instance Method Details

#get_all_categories(status = "online") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# 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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/crowd_funding_parser/parser/kickstarter.rb', line 25

def get_project_links(status = "online")
  status_code = get_status_code(status)

  jsons = @category_ids.map do |category_id|
    category_jsons = get_category_project_jsons(status_code, category_id)
  end.flatten.compact

  Parallel.map(jsons, in_precesses: 2, in_threads: 5) do |json|
    unless json["state"] != "live" && json["pledged"].to_i == 0
      if json["state"] == status_code
        project_url = json["urls"]["web"]["project"]
      end
    end
  end
end