Class: GitHubApi

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

Overview

Defined Under Namespace

Classes: Owner, Repository

Class Method Summary collapse

Class Method Details

.prs(by:) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/chid/github_api.rb', line 29

def self.prs(by:)
  owner     = 'rachidcalazans'
  repo_name = 'chid'
  uri = URI("https://api.github.com/repos/#{owner}/#{repo_name}/pulls")
  request = ::HTTP.get(uri)

  JSON.parse request
end

.repositories(search_expression) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chid/github_api.rb', line 38

def self.repositories(search_expression)
    uri = URI("https://api.github.com/search/repositories?q=#{search_expression}&sort=stars&order=desc")
    request = ::HTTP.get(uri)
    json_repositories = JSON.parse request

    json_repositories['items'].collect do |item|
      updated_at = item['updated_at'].nil? ? nil : Date.parse(item['updated_at'])
      owner = Owner.new(item['owner']['login'])
      Repository.new(item['name'], owner, item['html_url'], item['clone_url'], item['language'],
                      item['stargazers_count'], updated_at)
    end
end