2017-01-22 04:28:33 +01:00
|
|
|
require "hbc/system_command"
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class DSL
|
|
|
|
class Appcast
|
|
|
|
attr_reader :parameters, :checkpoint
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(uri, parameters = {})
|
|
|
|
@parameters = parameters
|
|
|
|
@uri = UnderscoreSupportingURI.parse(uri)
|
|
|
|
@checkpoint = @parameters[:checkpoint]
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-01-22 04:28:33 +01:00
|
|
|
def calculate_checkpoint
|
|
|
|
result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, @uri], print_stderr: false)
|
|
|
|
|
|
|
|
checkpoint = if result.success?
|
|
|
|
processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}, "")
|
|
|
|
|
|
|
|
# This step is necessary to replicate running `sed` from the command line
|
|
|
|
processed_appcast_text << "\n" unless processed_appcast_text.end_with?("\n")
|
|
|
|
|
|
|
|
Digest::SHA2.hexdigest(processed_appcast_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
checkpoint: checkpoint,
|
|
|
|
command_result: result,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_yaml
|
|
|
|
[@uri, @parameters].to_yaml
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
@uri.to_s
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|