class BeginningOpenSource::GithubApi

Public Class Methods

agent() click to toggle source
# File lib/secrets.rb, line 6
def self.agent
      'c1505'
end
get_issues(input_string) click to toggle source
# File lib/beginning_open_source/github_api.rb, line 3
def self.get_issues(input_string) #still very long.  refactor
  response = self.get_json("https://api.github.com/search/issues?q=label:\"#{input_string}\"+language:ruby+state:open&sort=created&order=desc")

  puts "Total Issue count matching #{input_string}:".blue + " #{response["total_count"]}".red

  response["items"].each_with_index.map do |issue, index| 
      hash_of_issue = {}

      issue_url_array = issue["html_url"].split("/")

      hash_of_issue[:repo_name] = issue_url_array[4]
      hash_of_issue[:title] = issue["title"]
      hash_of_issue[:labels] = (issue["labels"].map {|issue| issue["name"]})
      hash_of_issue[:body] = issue["body"]
      hash_of_issue[:html_url] = issue["html_url"]
      hash_of_issue[:created_at] = issue["created_at"]
      hash_of_issue[:repo_url] = "https://github.com/#{issue_url_array[3]}/#{issue_url_array[4]}"
      
      repo_json = self.get_json("https://api.github.com/repos/#{issue_url_array[3]}/#{issue_url_array[4]}")

      hash_of_issue[:repo_description] = repo_json["description"]
      hash_of_issue[:stars] = repo_json["stargazers_count"]

      if index > 10 
        puts "loading #{index + 1}/30" 
      end
      hash_of_issue
  end
end
get_json(url) click to toggle source
# File lib/beginning_open_source/github_api.rb, line 33
def self.get_json(url)
    unless self.token?
      HTTParty.get(url) 
    else
      HTTParty.get(
        url, 
        :headers => {
            "Authorization" => "token #{self.token}",   
            "User-Agent" => self.agent
            })
    end
end
token() click to toggle source
# File lib/secrets.rb, line 2
def self.token
  'PASTE_TOKEN_HERE_AS_STRING'
end
token?() click to toggle source
# File lib/secrets.rb, line 10
def self.token?
      if self.token == 'PASTE_TOKEN_HERE_AS_STRING'
              false
      else
              true
      end
end