class Ec2spec::OfferIndexFile

Constants

REGION_INDEX_FILE_URL

Public Instance Methods

offer_file_url(region) click to toggle source
# File lib/ec2spec/offer_index_file.rb, line 9
def offer_file_url(region)
  offer_index_file_json

  file_path = @offer_index_file_json['regions'][region]['currentVersionUrl']
  parsed_url = URI.parse(REGION_INDEX_FILE_URL)
  parsed_url.path = file_path
  parsed_url.to_s
end

Private Instance Methods

download_region_index_file() click to toggle source
# File lib/ec2spec/offer_index_file.rb, line 43
def download_region_index_file
  http_conn = Faraday.new do |builder|
    builder.adapter Faraday.default_adapter
  end
  response = http_conn.get(REGION_INDEX_FILE_URL)
  File.open(offer_index_file_path, 'wb') { |fp| fp.write(response.body) }
end
offer_index_file_json() click to toggle source
# File lib/ec2spec/offer_index_file.rb, line 29
def offer_index_file_json
  if File.exist?(offer_index_file_path)
    Ec2spec.logger.debug('Read from cached offer index file')
  else
    Ec2spec.logger.info('Downloading: offer index file')
    download_region_index_file
    Ec2spec.logger
           .info("Downloaded: offer index file (#{offer_index_file_path})")
  end

  @offer_index_file_json ||=
    JSON.parse(File.open(offer_index_file_path).read)
end
offer_index_file_path() click to toggle source
# File lib/ec2spec/offer_index_file.rb, line 24
def offer_index_file_path
  file_name = File.basename(REGION_INDEX_FILE_URL)
  File.join(Ec2spec.project_dir, file_name)
end
region_index_file_path() click to toggle source
# File lib/ec2spec/offer_index_file.rb, line 20
def region_index_file_path
  File.join(Ec2spec.project_dir, REGION_INDEX_FILE_URL)
end