class GhInspector::Sidekick

The Sidekick is the one who does all the real work. They take the query, get the GitHub API results, etc then pass them back to the inspector who gets the public API credit.

Attributes

inspector[RW]
repo_name[RW]
repo_owner[RW]
using_deprecated_method[RW]

Public Class Methods

new(inspector, repo_owner, repo_name) click to toggle source
# File lib/gh_inspector/sidekick.rb, line 13
def initialize(inspector, repo_owner, repo_name)
  self.inspector = inspector
  self.repo_owner = repo_owner
  self.repo_name = repo_name
  self.using_deprecated_method = false
end

Public Instance Methods

verbose() click to toggle source
# File lib/gh_inspector/sidekick.rb, line 57
def verbose
  self.inspector.verbose
end

Private Instance Methods

get_api_results(url) click to toggle source

Gets the search results

# File lib/gh_inspector/sidekick.rb, line 77
def get_api_results(url)
  uri = URI.parse(url)
  puts "URL: #{url}" if self.verbose
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)

  JSON.parse(response.body)
end
parse_results(query, results) click to toggle source

Converts a GitHub search JSON into a InspectionReport

# File lib/gh_inspector/sidekick.rb, line 90
def parse_results(query, results)
  report = InspectionReport.new
  report.url = "https://github.com/#{repo_owner}/#{repo_name}/search?q=#{ERB::Util.url_encode(query)}&type=Issues&utf8=✓"
  report.query = query
  report.total_results = results['total_count']
  report.issues = results['items'].map { |item| Issue.new(item) }
  report
end
url_for_request(query, sort_by: nil, order: nil) click to toggle source

Generates a URL for the request

# File lib/gh_inspector/sidekick.rb, line 66
def url_for_request(query, sort_by: nil, order: nil)
  url = "https://api.github.com/search/issues?q="
  url += ERB::Util.url_encode(query)
  url += "+repo:#{repo_owner}/#{repo_name}"
  url += "&sort=#{sort_by}" if sort_by
  url += "&order=#{order}" if order

  url
end
validate_delegate(delegate) click to toggle source
# File lib/gh_inspector/sidekick.rb, line 99
def validate_delegate(delegate)
  deprecated_delegate_methods = %i[
    inspector_successfully_recieved_report
    inspector_recieved_empty_report
  ]
  new_delegate_methods = %i[
    inspector_successfully_received_report
    inspector_received_empty_report
  ]

  deprecated_delegate_methods.each do |deprecated_delegate_method|
    self.using_deprecated_method = true if delegate.methods.include?(deprecated_delegate_method)
  end

  e = Evidence.new
  protocol = e.public_methods false
  protocol.each do |m|
    is_deprecated_method = deprecated_delegate_methods.include?(m)
    is_new_delegate_method = new_delegate_methods.include?(m)

    raise "#{delegate} does not handle #{m}" unless delegate.methods.include?(m) || is_deprecated_method || is_new_delegate_method
  end
end