Class: Andy::Api::Fetch

Inherits:
Object
  • Object
show all
Defined in:
lib/andy/api/fetch_api.rb

Instance Method Summary collapse

Instance Method Details

#build_pint_catalogObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/andy/api/fetch_api.rb', line 9

def build_pint_catalog
  response = open('https://api.github.com/orgs/andy-pint-repository/repos')
  repo_list = JSON.parse(response.read) 
  actual_repos = {}
  repo_list.each do |repo|
    repo_name = repo['name']
    pint_fetch_url = "https://github.com/andy-pint-repository/#{repo_name}/archive/master.zip"
    actual_repos[repo_name] = { :name => repo_name, :url => pint_fetch_url }
  end
  actual_repos
end

#download_pint(pint_fetch_url, destination) ⇒ Object



21
22
# File 'lib/andy/api/fetch_api.rb', line 21

def download_pint(pint_fetch_url, destination)
end

#fetch_listObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/andy/api/fetch_api.rb', line 24

def fetch_list
  			uri = URI.parse('https://api.github.com/orgs/andy-pint-repository/repos')
  			http = Net::HTTP.new(uri.host, uri.port)
 http.use_ssl = true
 http.verify_mode = OpenSSL::SSL::VERIFY_NONE

 request = Net::HTTP::Get.new(uri.request_uri)

 response = http.request(request)
 repo_list = JSON.parse response.body
 actual_repos = {}
 repo_list.each do |repo|
   puts "NAME #{repo['name']}"
   repo_name = repo['name']
   pint_fetch_url = "https://github.com/andy-pint-repository/#{repo_name}/archive/master.zip"
   actual_repos[repo_name] = { :name => repo_name, :url => pint_fetch_url }
 end

 uri = actual_repos['basic-web'][:url]
 resp = open(uri)
 File.open("./data.zip", "wb") do |f|
   f.write(resp.string)
 end
end