Class: GithubGrep

Inherits:
Object
  • Object
show all
Defined in:
lib/github_grep.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ GithubGrep

Returns a new instance of GithubGrep.



9
10
11
# File 'lib/github_grep.rb', line 9

def initialize(token)
  @token = token
end

Instance Method Details

#render_search(q, type) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/github_grep.rb', line 13

def render_search(q, type)
  search(q, type) do |items|
    if type == :issues
      yield issue_items_to_lines(items)
    else
      yield code_items_to_lines(items)
    end
  end
end

#search(q, type, &block) ⇒ Object



23
24
25
26
27
# File 'lib/github_grep.rb', line 23

def search(q, type, &block)
  headers = ["-H", "Accept: application/vnd.github.v3.text-match+json"]
  url = "https://api.github.com/search/#{type}?q=#{CGI.escape(q)}"
  all_pages(url, per_page: 100, argv: headers, &block)
end