Class: BeginningOpenSource::GithubApi

Inherits:
Object
  • Object
show all
Defined in:
lib/secrets.rb,
lib/beginning_open_source/github_api.rb

Overview

should probably change to a module or just ask user for input

Class Method Summary collapse

Class Method Details

.agentObject



6
7
8
# File 'lib/secrets.rb', line 6

def self.agent
	'c1505'
end

.get_issues(input_string) ⇒ Object

still very long. refactor



3
4
5
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
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# 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

.tokenObject



2
3
4
# File 'lib/secrets.rb', line 2

def self.token
  'PASTE_TOKEN_HERE_AS_STRING'
end

.token?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/secrets.rb', line 10

def self.token?
	if self.token == 'PASTE_TOKEN_HERE_AS_STRING'
		false
	else
		true
	end
end