Class: GhSearch::GithubClient
- Inherits:
-
Object
- Object
- GhSearch::GithubClient
- Defined in:
- lib/gh_search/github_client.rb
Constant Summary collapse
- GITHUB_URL =
"https://api.github.com"- ENDPOINT =
"/search/code"
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#org ⇒ Object
readonly
Returns the value of attribute org.
-
#pagenum ⇒ Object
Returns the value of attribute pagenum.
-
#search_text ⇒ Object
readonly
Returns the value of attribute search_text.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(search_text, options = {}) ⇒ GithubClient
constructor
A new instance of GithubClient.
Constructor Details
#initialize(search_text, options = {}) ⇒ GithubClient
Returns a new instance of GithubClient.
19 20 21 22 23 24 |
# File 'lib/gh_search/github_client.rb', line 19 def initialize(search_text, ={}) @search_text = search_text @org = [:org] @filename = [:file] @pagenum = 1 end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
15 16 17 |
# File 'lib/gh_search/github_client.rb', line 15 def filename @filename end |
#org ⇒ Object (readonly)
Returns the value of attribute org.
15 16 17 |
# File 'lib/gh_search/github_client.rb', line 15 def org @org end |
#pagenum ⇒ Object
Returns the value of attribute pagenum.
17 18 19 |
# File 'lib/gh_search/github_client.rb', line 17 def pagenum @pagenum end |
#search_text ⇒ Object (readonly)
Returns the value of attribute search_text.
15 16 17 |
# File 'lib/gh_search/github_client.rb', line 15 def search_text @search_text end |
Instance Method Details
#each ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gh_search/github_client.rb', line 26 def each has_results = true while has_results do json_response = make_request(uri)['items'] if has_results = json_response.any? json_response.each do |item| each_match(URI(item['url'])) do |match| result = match.merge({ repo_name: item['repository']['full_name'], html_url: item['html_url'], }) yield result end end end @pagenum += 1 end end |