Class: FDroid::IndexV1
- Inherits:
-
Object
- Object
- FDroid::IndexV1
- Defined in:
- lib/fdroid/IndexV1.rb
Constant Summary collapse
- @@downloaded_repos =
{}
Instance Attribute Summary collapse
-
#apps ⇒ Object
readonly
Returns the value of attribute apps.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Class Method Summary collapse
-
.download(repo, locale) ⇒ FDroid::IndexV1
Download and parse an index, returning a new instance of IndexV1.
-
.download_index(repo) ⇒ Hash
Make a network request, download the index-v1.jar file from the repo, unzip and get the contents of the index-v1.json file.
Instance Method Summary collapse
-
#initialize(index, locale) ⇒ IndexV1
constructor
A new instance of IndexV1.
Constructor Details
#initialize(index, locale) ⇒ IndexV1
Returns a new instance of IndexV1.
71 72 73 74 75 76 77 78 |
# 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 |
Instance Attribute Details
#apps ⇒ Object (readonly)
Returns the value of attribute apps.
28 29 30 |
# File 'lib/fdroid/IndexV1.rb', line 28 def apps @apps end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
28 29 30 |
# File 'lib/fdroid/IndexV1.rb', line 28 def repo @repo end |
Class Method Details
.download(repo, locale) ⇒ FDroid::IndexV1
Download and parse an index, returning a new instance of IndexV1.
36 37 38 39 40 |
# 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) ⇒ Hash
Make a network request, download the index-v1.jar file from the repo, unzip and get the contents of the index-v1.json file.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |