Sha256: 8bdd61f9f0156fb38d314b356664b32d07932ae828f2041de307cc8c56b76cad

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

module VagrantCloud
  class Provider
    attr_accessor :version
    attr_accessor :name
    attr_accessor :data

    # @param [Version] version
    # @param [String] name
    # @param [Hash] data
    def initialize(version, name, data = nil)
      @version = version
      @name = name
      @data = data
    end

    # @return [String]
    def url
      data['original_url'].to_s
    end

    # @return [String]
    def download_url
      data['download_url'].to_s
    end

    # @return [Hash]
    def data
      @data ||= account.request('get', provider_path)
    end

    # @param [String] url
    def update(url)
      params = { url: url }
      @data = account.request('put', provider_path, provider: params)
    end

    def delete
      account.request('delete', provider_path)
    end

    # @return [String]
    def upload_url
      account.request('get', "#{provider_path}/upload")['upload_path']
    end

    # @param [String] file_path
    def upload_file(file_path)
      url = upload_url
      payload = File.open(file_path, 'r')
      RestClient::Request.execute(
        method: :put,
        url: url,
        payload: payload,
        ssl_version: 'TLSv1'
      )
    end

    private

    # @return [Box]
    def box
      version.box
    end

    # @return [Account]
    def account
      box.account
    end

    def provider_path
      "/box/#{account.username}/#{box.name}/version/#{version.number}/provider/#{name}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant_cloud-1.1.0 lib/vagrant_cloud/provider.rb