class FDroid::IndexV1

Attributes

apps[R]
repo[R]

Public Class Methods

download(repo, locale) click to toggle source

Download and parse an index, returning a new instance of IndexV1. @param [string] repo @param [string] locale @return [FDroid::IndexV1]

# File lib/fdroid/IndexV1.rb, line 36
def self.download(repo, locale)
  repo = URI.parse "#{repo}/index-v1.jar"
  index = download_index repo
  IndexV1.new(JSON.parse(index), locale)
end
download_index(repo) click to toggle source

Make a network request, download the index-v1.jar file from the repo, unzip and get the contents of the index-v1.json file. @param [string] repo @return [Hash]

# File lib/fdroid/IndexV1.rb, line 46
def self.download_index(repo)
  if @@downloaded_repos.has_key? repo
    return @@downloaded_repos[repo]
  end

  Dir.mktmpdir do |dir|
    jar = File.join dir, 'index-v1.jar'
    open(jar, 'wb') do |file|
      begin
        file.write(Net::HTTP.get(repo))
      rescue Net::OpenTimeout, Net::ReadTimeout => e
        puts "Timeout (#{e}), retrying in 1 second..."
        sleep(1)
        retry
      end
    end

    Zip::File.open(jar) do |zip_file|
      entry = zip_file.glob('index-v1.json').first
      @@downloaded_repos[repo] = entry.get_input_stream.read
      next @@downloaded_repos[repo]
    end
  end
end
new(index, locale) click to toggle source
# File lib/fdroid/IndexV1.rb, line 71
def initialize(index, locale)
  @apps = index['apps'].map do |app_json|
    packages_json = index['packages'][app_json['packageName']]
    App.new(app_json, packages_json, locale)
  end

  @repo = Repo.new(index['repo'])
end