浏览代码

update github scraper

tweak github scraper to work again after GitHub UI update which gives back JSON data
ClasherKasten 2 年之前
父节点
当前提交
8034fd960d
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      lib/docs/scrapers/github.rb

+ 15 - 0
lib/docs/scrapers/github.rb

@@ -4,5 +4,20 @@ module Docs
     self.type = 'github'
 
     html_filters.push 'github/clean_html'
+
+    def process_response?(response)
+      if super(response)
+        return true
+      end
+      JSON.parse(response.body)
+      true
+    rescue JSON::ParserError, TypeError => e
+      false
+    end
+
+    def parse(response)
+      parsed = JSON.parse(response.response_body)
+      [parsed['payload']['blob']['richText'], parsed['title']]
+    end
   end
 end