|
3 | 3 | module SlackApi |
4 | 4 | # Scrapes Slack events |
5 | 5 | class EventsSpider < BaseSpider |
6 | | - handle 'https://api.slack.com/events', :process_list |
| 6 | + handle 'https://docs.slack.dev/reference/events/', :process_list |
| 7 | + |
| 8 | + def downloader |
| 9 | + @downloader ||= SlackApi::Docs::Downloader.new |
| 10 | + end |
7 | 11 |
|
8 | 12 | def process_list(page, _default_data = {}) |
9 | | - events_page = ensure!(page, '.apiEventsPage') |
10 | | - list = events_page.search('.apiEventPage__eventList') |
11 | | - ref = list.search('[data-automount-component=ApiDocsFilterableReferenceList]') |
12 | | - data = JSON.parse(ref.attribute('data-automount-props')) |
13 | | - raise(ElementNotFound, 'Could not parse events reference') unless data['items'].any? |
14 | | - |
15 | | - data['items'].each do |event| |
16 | | - next unless event['isPublic'] |
17 | | - next if event['isDeprecated'] |
18 | | - next unless event['groups'].include?('RTM') |
19 | | - |
20 | | - handle resolve_url(event['link'], page), |
| 13 | + events = JSON.load_file(downloader.events_path) |
| 14 | + |
| 15 | + events.each do |event| |
| 16 | + next unless event['APIs']&.include?('RTM') |
| 17 | + |
| 18 | + handle resolve_url(event['name'], page), |
21 | 19 | :process_event, |
22 | 20 | name: event['name'], |
23 | 21 | desc: event['description'], |
24 | 22 | required_scope: 'RTM' |
25 | 23 | end |
26 | 24 | end |
27 | 25 |
|
28 | | - def process_event(page, data = {}) |
29 | | - event_page = ensure!(page, '.apiEventPage', data[:name]) |
30 | | - descriptions = event_page.search('.apiDocsPage__markdownOutput p') |
31 | | - long_desc = descriptions.map(&:text).join(' ').gsub("\n", ' ').strip |
| 26 | + def process_event(_page, data = {}) |
| 27 | + # event_page = ensure!(page, '#__docusaurus') |
| 28 | + # descriptions = event_page.search('.apiDocsPage__markdownOutput p') |
| 29 | + # long_desc = descriptions.map(&:text).join(' ').gsub("\n", ' ').strip |
32 | 30 | # required_scopes = event_page.search('.apiReference__scope code').map(&:text).map(&:strip).join(', ') |
33 | 31 |
|
34 | 32 | json_hash = { |
35 | 33 | 'name' => data[:name], |
36 | | - 'desc' => "#{data[:desc]}.", |
37 | | - 'long_desc' => long_desc, |
38 | | - 'required_scope' => data[:required_scope] |
| 34 | + 'desc' => "#{data[:desc]}." |
| 35 | + # 'long_desc' => long_desc, |
| 36 | + # 'required_scope' => data[:required_scope] |
39 | 37 | } |
40 | 38 |
|
41 | | - example = begin |
42 | | - JSON.parse( |
43 | | - event_page.search('.apiDocsPage__markdownOutput pre:first code') |
44 | | - .text |
45 | | - .gsub('…', '') |
46 | | - .gsub('...', '') |
47 | | - .gsub("\n", ' ') |
48 | | - .gsub(/\s+/, ' ') |
49 | | - .gsub(', }', '}') |
50 | | - .gsub(', ]', ']') |
51 | | - ) |
52 | | - rescue StandardError |
53 | | - nil |
54 | | - end |
55 | | - |
56 | | - json_hash['example'] = example if example |
| 39 | + # example = begin |
| 40 | + # JSON.parse( |
| 41 | + # event_page.search('.apiDocsPage__markdownOutput pre:first code') |
| 42 | + # .text |
| 43 | + # .gsub('…', '') |
| 44 | + # .gsub('...', '') |
| 45 | + # .gsub("\n", ' ') |
| 46 | + # .gsub(/\s+/, ' ') |
| 47 | + # .gsub(', }', '}') |
| 48 | + # .gsub(', ]', ']') |
| 49 | + # ) |
| 50 | + # rescue StandardError |
| 51 | + # nil |
| 52 | + # end |
| 53 | + |
| 54 | + # json_hash['example'] = example if example |
57 | 55 |
|
58 | 56 | record(file_name: "events/#{data[:name]}.json", json: JSON.pretty_generate(json_hash)) |
59 | 57 | end |
|
0 commit comments