Module: Gpr::APIHelper

Defined in:
lib/gpr/api_helper.rb

Class Method Summary collapse

Class Method Details

.get_repository_urls(host, user) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gpr/api_helper.rb', line 7

def get_repository_urls(host, user)
  case host
  when 'github.com'
    uri = URI.parse("https://api.github.com/users/#{user}/repos?per_page=100")
    JSON.parse(request_https_get(uri).body).map do |repository|
      repository['clone_url']
    end

  when 'bitbucket.org'
    uri = URI.parse("https://api.bitbucket.org/1.0/users/#{user}")
    JSON.parse(request_https_get(uri).body)['repositories'].map do |repository|
      "https://#{repository['owner']}@bitbucket.org/#{repository['owner']}/#{repository['name']}.git"
    end

  else
    puts "#{host} is not supported"
    exit 0
  end
end

.request_https_get(uri) ⇒ Object



27
28
29
30
31
# File 'lib/gpr/api_helper.rb', line 27

def request_https_get(uri)
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  https.get(uri.request_uri)
end