Class: BooticCli::Themes::APIAsset
- Inherits:
-
ItemWithTime
- Object
- SimpleDelegator
- ItemWithTime
- BooticCli::Themes::APIAsset
- Defined in:
- lib/bootic_cli/themes/api_theme.rb
Constant Summary collapse
- REQUEST_OPTS =
{ open_timeout: 5, read_timeout: 5 }
Instance Method Summary collapse
Methods inherited from ItemWithTime
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 26 def ==(other) return super if digest.to_s == '' || other.digest.to_s == '' self.file_size == other.file_size && self.digest == other.digest end |
#fetch_data(attempt = 1) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 31 def fetch_data(attempt = 1) uri = URI.parse(rels[:file].href) opts = REQUEST_OPTS.merge({ # verify_mode: OpenSSL::SSL::VERIFY_PEER # OpenSSL::SSL::VERIFY_NONE use_ssl: uri.port == 443 }) Net::HTTP.start(uri.host, uri.port, opts) do |http| resp = http.get(uri.path) raise "Invalid response: #{resp.code}" unless resp.code.to_i == 200 resp.body end rescue Net::OpenTimeout, Net::ReadTimeout => e raise if attempt > 3 # max attempts # puts "#{e.class} for #{File.basename(uri.path)}! Retrying request..." fetch_data(attempt + 1) end |
#file ⇒ Object
22 23 24 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 22 def file @file ||= StringIO.new(fetch_data) end |