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

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