Sha256: 50d855879bfc7817319a6dbf3cab8316ed3669ad669153d329fdf3c9f3a09533
Contents?: true
Size: 1.66 KB
Versions: 4
Compression:
Stored size: 1.66 KB
Contents
require 'acquia/cloud/entity' require 'net/http' require 'uri' module Acquia class Cloud class DatabaseBackup < Entity include Operations::Delete def initialize(cloud, site, environment, database, backup) @cloud = cloud @site = site @environment = environment @database = database @data = backup @url = "/sites/#{@site}/envs/#{@environment}/dbs/#{@database}/backups/#{data['id']}" end def id data['id'] end def checksum data['checksum'] end def deleted? data['deleted'] != '0' end def name data['name'] end def path data['path'] end def started Time.at(data['started'].to_i) end def completed Time.at(data['completed'].to_i) end def completed? !data['completed'].to_i.zero? end def type data['type'].to_sym end def link data['link'] end def download_to(path, &block) uri = URI.parse(link) File.open(path, 'wb') do |io| https = uri.scheme == 'https' Net::HTTP.start(uri.host, uri.port, use_ssl: https) do |http| request = Net::HTTP::Get.new uri request.basic_auth *@cloud.api.credentials http.request request do |response| response.read_body do |chunk| io.write chunk block.call(response, chunk) if block_given? end end end end end def download(&block) download_to(File.basename(path), &block) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems