Class: MarketplaceRepository
- Inherits:
-
VmRepository
- Object
- VmRepository
- MarketplaceRepository
- Defined in:
- lib/ovfparse/marketplace_repository.rb
Constant Summary
Constants inherited from VmRepository
VmRepository::ALLOWABLE_PKG_TYPES, VmRepository::ALLOWABLE_PROTOCOLS, VmRepository::STRICT_CHECKING, VmRepository::USE_CACHE
Instance Attribute Summary
Attributes inherited from VmRepository
Instance Method Summary collapse
Methods inherited from VmRepository
ESXParse, FTParse, HTTParse, LSParse, create, #get, #initialize, #simplePackageConstruction, #uri
Constructor Details
This class inherits a constructor from VmRepository
Instance Method Details
#fetch ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ovfparse/marketplace_repository.rb', line 26 def fetch #retrieve data from http server begin raw_html = open(uri) rescue if(uri.match(/\/$/) != nil) begin raw_html = open(uri[0..-2]) @url = @url[0..-2] rescue Exception => e #something useful raise "Tried getting rid of the trailing slash but still no dice: " + e. end else #something useful raise "No trailing slash so this is probably a dead URL" end end if (raw_html) #parse out package list from index html package_list = parse(raw_html) #construct package objects based on results return listPackages(package_list) end end |
#listPackages(package_list) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ovfparse/marketplace_repository.rb', line 54 def listPackages(package_list) packages = Array.new package_list.each { |pkg| fullpath = (pkg['basepath'] + pkg['filename']).to_s package = VmPackage.create(fullpath) package.base_path = pkg['basepath'] package.name = pkg['filename'] packages.push(package) } return packages end |
#parse(raw_html) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ovfparse/marketplace_repository.rb', line 6 def parse (raw_html) file_list = Array.new xml = Nokogiri::XML(raw_html) do |config| config.noblanks.strict.noent end entries = xml.root.children.select { |element| element.name == 'entry' } entries.each { |entry| repository = entry.children.detect { |element| element.name == 'repository' } basepath = repository.children.detect { |element| element.name == 'basepath' } filename = repository.children.detect { |element| element.name == 'filename' } file_list.push( {'basepath' => basepath.content, 'filename' => filename.content} ) } return file_list end |