class Vcsmap::Provider::GitHub
Public Class Methods
new()
click to toggle source
# File lib/vcsmap/providers/github.rb, line 4 def initialize @cookie = get_cookie end
Public Instance Methods
search(plugin, total_pages)
click to toggle source
# File lib/vcsmap/providers/github.rb, line 8 def search(plugin, total_pages) result_urls = [] @query = plugin.search_string (1..total_pages).each do |page| result_urls += get_results_from_page(page) end result_urls end
Private Instance Methods
get_raw(url)
click to toggle source
# File lib/vcsmap/providers/github.rb, line 41 def get_raw(url) url.gsub('blob', 'raw') end
get_results_from_page(page)
click to toggle source
# File lib/vcsmap/providers/github.rb, line 26 def get_results_from_page(page) url = "https://github.com/search?p=#{page}&o=desc&q=#{@query}&s=indexed&type=Code" html = HTTP.cookies(user_session: @cookie).get(url) parse_response(html.body.to_s) end
parse_response(body)
click to toggle source
# File lib/vcsmap/providers/github.rb, line 32 def parse_response(body) doc = Nokogiri::HTML(body) hits = doc.css('p.title a:last') # TODO: use this when there are no file boxes. # hits = doc.css('.code-list-item .full-path a') urls = hits.map { |hit| 'https://github.com' + hit.attr('href') } urls.map { |url| get_raw(url) } end