github.rb 629 B

1234567891011121314151617181920212223242526272829
  1. module Docs
  2. class Github < UrlScraper
  3. self.abstract = true
  4. self.type = 'github'
  5. html_filters.push 'github/clean_html'
  6. def process_response?(response)
  7. if super(response)
  8. return true
  9. end
  10. JSON.parse(response.body)
  11. true
  12. rescue JSON::ParserError, TypeError => e
  13. false
  14. end
  15. def parse(response)
  16. embedded_json = response
  17. .response_body
  18. .match(/react-app\.embeddedData">(.+?)<\/script>/)
  19. &.captures
  20. &.first
  21. parsed = JSON.parse(embedded_json)
  22. [parsed['payload']['blob']['richText'], parsed['title']]
  23. end
  24. end
  25. end