Class: GithubSearch::Searcher

Inherits:
Object
  • Object
show all
Defined in:
lib/github-search/searcher.rb

Direct Known Subclasses

Issue, Repository, User

Instance Method Summary collapse

Instance Method Details

#issuesObject



16
17
18
19
20
# File 'lib/github-search/searcher.rb', line 16

def issues
  @path = "issues"
  @model = Issue
  self
end

#reposObject



22
23
24
25
26
# File 'lib/github-search/searcher.rb', line 22

def repos
  @path = "repositories"
  @model = Repository
  self
end

#search(*args, opts) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/github-search/searcher.rb', line 7

def search(*args, opts)
  search_string_builder = SearchStringBuilder.new
  search_string = search_string_builder.build_search_string(args, opts, @model)

  response = Faraday.get("#{API_URL}/#{@path}#{search_string}")
  items = JSON.parse(response.body)["items"]
  items.map { |attributes| @model.new(attributes) }
end

#usersObject



28
29
30
31
32
# File 'lib/github-search/searcher.rb', line 28

def users
  @path = "users"
  @model = User
  self
end