Class: GitMulticast::RepositoryFetcher::Github

Inherits:
GitMulticast::RepositoryFetcher show all
Defined in:
lib/git_multicast/repository_fetcher/github.rb

Constant Summary collapse

REPOS_URI =
'https://api.github.com/users/%{username}/repos'

Constants inherited from GitMulticast::RepositoryFetcher

FETCHER_ADAPTER_ZIP

Class Method Summary collapse

Methods inherited from GitMulticast::RepositoryFetcher

adapter_by_url, fetcher_by_url, get_repo_parent, make_struct, zip_by_url

Class Method Details

.get_all_repos_from_user(username, uri_str = make_uri(username)) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/git_multicast/repository_fetcher/github.rb', line 9

def self.get_all_repos_from_user(username, uri_str = make_uri(username))
  uri = URI(uri_str)

  response = Net::HTTP.get_response(uri)
  repos = JSON.parse(response.body)

  built_repos = repos.map { |hash| make_struct(hash) }

  if response['Link'] =~ /rel=\"next\"/
    next_uri = response['Link'].match(/<(.*)>; rel=\"next\"/)[1]

    built_repos + get_all_repos_from_user(username, next_uri)
  else
    built_repos
  end
end

.get_repo(url) ⇒ Object



26
27
28
29
# File 'lib/git_multicast/repository_fetcher/github.rb', line 26

def self.get_repo(url)
  response = Net::HTTP.get_response(URI(url))
  make_struct(JSON.parse(response.body))
end

.make_uri(username) ⇒ Object



31
32
33
# File 'lib/git_multicast/repository_fetcher/github.rb', line 31

def self.make_uri(username)
  REPOS_URI % { username: username }
end