Class: BeginningOpenSource::GithubApi
- Inherits:
-
Object
- Object
- BeginningOpenSource::GithubApi
- Defined in:
- lib/beginning_open_source/github_api.rb
Constant Summary collapse
- @@array_of_issues =
i am passing around variables. might be better off using class variables.
[]
Class Method Summary collapse
-
.get_issues(input_string) ⇒ Object
still very long.
- .get_repository(user, repository, hash) ⇒ Object
-
.search_issues(input_string) ⇒ Object
end of method.
Class Method Details
.get_issues(input_string) ⇒ Object
still very long. refactor
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/beginning_open_source/github_api.rb', line 6 def self.get_issues(input_string) #still very long. refactor response = self.search_issues(input_string) puts "Total Issue count matching #{input_string}:".blue + " #{response["total_count"]}".red search_results = JSON.parse(response.body)["items"] loaded_repo_count = 1 search_results.each do |issue| hash_of_issue = {} issue_url_array = issue["html_url"].split("/") hash_of_issue[:repo_name] = issue_url_array[4] repo_string = "https://api.github.com/repos/#{issue_url_array[3]}/#{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] = repo_string if loaded_repo_count > 10 puts "loading #{loaded_repo_count}/30" end loaded_repo_count += 1 self.get_repository(issue_url_array[3], issue_url_array[4], hash_of_issue) @@array_of_issues << hash_of_issue end #end of each statement @@array_of_issues #there are pagination options. # right now it is only giving me 30 per page. can go up to 100 end |
.get_repository(user, repository, hash) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/beginning_open_source/github_api.rb', line 57 def self.get_repository(user, repository, hash) if self.token == 'PASTE_TOKEN_HERE_AS_STRING' repo_json = HTTParty.get("https://api.github.com/repos/#{user}/#{repository}") else repo_json = HTTParty.get( "https://api.github.com/repos/#{user}/#{repository}", :headers => { "Authorization" => "token #{self.token}", "User-Agent" => self.agent }) end repo_parsed = JSON.parse(repo_json.body) hash[:repo_description] = repo_parsed["description"] hash[:stars] = repo_parsed["stargazers_count"] hash end |
.search_issues(input_string) ⇒ Object
end of method
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/beginning_open_source/github_api.rb', line 44 def self.search_issues(input_string) if self.token == 'PASTE_TOKEN_HERE_AS_STRING' #doing this twice, but with a different url. if i take in the url or have it set as a variable, i might be able to combine these response = HTTParty.get("https://api.github.com/search/issues?q=label:\"#{input_string}\"+language:ruby+state:open&sort=created&order=desc") else response = HTTParty.get("https://api.github.com/search/issues?q=label:\"#{input_string}\"+language:ruby+state:open&sort=created&order=desc", :headers => { "Authorization" => "token #{self.token}", "User-Agent" => self.agent }) end response end |