Class: CurseVersionList
- Inherits:
-
BaseVersionList
- Object
- BaseVersionList
- CurseVersionList
- Defined in:
- lib/wonko_the_sane/versionlists/curse_version_list.rb
Instance Attribute Summary
Attributes inherited from BaseVersionList
#artifact, #lastError, #processed
Instance Method Summary collapse
- #get_version(id) ⇒ Object
- #get_versions ⇒ Object
-
#initialize(uid, curseId, fileRegex) ⇒ CurseVersionList
constructor
A new instance of CurseVersionList.
Methods inherited from BaseVersionList
#cache_file, #get_json, #get_json_cached, #invalidate, #last_modified, #logger, #refresh, #write_cache_file
Constructor Details
#initialize(uid, curseId, fileRegex) ⇒ CurseVersionList
Returns a new instance of CurseVersionList.
2 3 4 5 6 |
# File 'lib/wonko_the_sane/versionlists/curse_version_list.rb', line 2 def initialize(uid, curseId, fileRegex) super(uid) @curseId = curseId @fileRegex = fileRegex.gsub /\?P\</, '?<' end |
Instance Method Details
#get_version(id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wonko_the_sane/versionlists/curse_version_list.rb', line 32 def get_version(id) urlId = id[1][:url].match(/\/(\d*)$/)[1] dl = FileDownload.new dl.internalUrl = "http://addons-origin.cursecdn.com/files/#{urlId[0...4]}/#{urlId[4...7]}/#{id[1][:fileId]}" dl.url = "http://curse.com" + id[1][:url] dl.destination = "mods/#{@artifact}-#{id.first}.jar" file = WonkoVersion.new file.uid = @artifact file.version = id.first file.type = id[1][:type] file.time = id[1][:timestamp] file.requires << Referenced.new('net.minecraft', id[1][:mcVersion]) file.common.downloads << dl return BaseSanitizer.sanitize file end |
#get_versions ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wonko_the_sane/versionlists/curse_version_list.rb', line 8 def get_versions result = Oga.parse_html HTTPCache.file('http://curse.com/project/' + @curseId, ctxt: @artifact, key: 'curse/' + @curseId + '.html', check_stale: false) # start by getting rid of some elements that standard xml parsers have issues with result.each_node do |node| node.remove if node.is_a? Oga::XML::Element and ['script', 'like'].include? node.name end rows = result.xpath("html/body/#{'div/' * 14}table/tbody/tr") return rows.map do |row| match = row.xpath('td/a/text()').first.text.match @fileRegex next if not match version = match[:version] [ version, { url: row.xpath('td/a/@href').first.value, fileId: row.xpath('td/a/text()').first.text, type: row.xpath('td[2]/text()').first.text, mcVersion: row.xpath('td[3]/text()').first.text, timestamp: row.xpath('td[5]/@data-sort-value').first.value.to_i / 1000, version: version } ] end end |