Class: Fog::Storage::Nirvanix::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/nirvanix/storage.rb,
lib/fog/nirvanix/requests/storage/get_object.rb,
lib/fog/nirvanix/requests/storage/list_folder.rb,
lib/fog/nirvanix/requests/storage/upload_file.rb,
lib/fog/nirvanix/requests/storage/create_folder.rb,
lib/fog/nirvanix/requests/storage/delete_folder.rb,
lib/fog/nirvanix/requests/storage/get_optimal_url.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/nirvanix/storage.rb', line 32

def initialize(options={})
  require 'mime/types'
  @nirvanix_app_key       = options[:nirvanix_app_key]
  @nirvanix_app_name      = options[:nirvanix_app_name]
  @nirvanix_username      = options[:nirvanix_username]
  @nirvanix_url           = options[:nirvanix_url]
  @connection_options     = options[:connection_options] || {}
  @nirvanix_session_token = Fog::Nirvanix.authenticate(options, @connection_options)

  uri = URI.parse(@nirvanix_url)
  @host       = uri.host
  @persistent = options[:persistent] || false
  @port       = uri.port
  @scheme     = uri.scheme
  Excon.defaults[:ssl_verify_peer] = false
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Method Details

#create_folder(folder_path) ⇒ Object

The CreateFolders method is used to create one or more folders at the specified location.

Parameters

  • folderPath<~String> - The path to the folder to be created. More than one

folder may be specified using multiple instances of this parameter. The path cannot be set to . or ..



14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/nirvanix/requests/storage/create_folder.rb', line 14

def create_folder(folder_path)
  request(
    :expects => [200, 201],
    :method  => 'POST',
    :path    => '/ws/IMFS/CreateFolders.ashx',
    :query   => {
      :folderPath => folder_path,
    }
    )
end

#delete_folder(folder_path) ⇒ Object

The DeleteFolders method is used to remove one or more folders. Folders will be deleted even if they contain files.

Parameters

  • folderPath<~String> - The path to the folder to be deleted. One or

more folders may be specified using multiple instances of this parameter.



13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/nirvanix/requests/storage/delete_folder.rb', line 13

def delete_folder(folder_path)
  request(
    :expects => [200, 201],
    :method  => 'POST',
    :path    => '/ws/IMFS/DeleteFolders.ashx',
    :query   => {
      :folderPath => folder_path,
    }
    )
end

#get_download_node(file_path) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/nirvanix/requests/storage/get_object.rb', line 28

def get_download_node(file_path)
  response = request(
    :expects => [200, 201],
    :method  => 'GET',
    :path    => '/ws/IMFS/GetDownloadNodes.ashx',
    :query   => {
      :filePath => file_path
    }
    )
  response.body[:DownloadNode]
end

#get_object(container, object, &block) ⇒ Object

Get details for object

Parameters

  • container<~String> - Name of container to look in

  • object<~String> - Name of object to look for



12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/nirvanix/requests/storage/get_object.rb', line 12

def get_object(container, object, &block)
  params = {}
  if block_given?
    params[:response_block] = Proc.new
  end
  full_path = ::File.join(container, object)

  url = get_private_url(full_path)
  Excon.get(url, params)
end

#get_optimal_url(file_path, expiration = 600) ⇒ Object

The GetOptimalUrls method is used to obtain the current optimum download links for one or more files. These links can be used by anyone to download the associated files within a limited time window.

Parameters

  • file path<~String> - The path to the file to download. More than one may be specified using multiple instances of this parameter.

  • expiration<~Integer> - Time to expiration in seconds.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/nirvanix/requests/storage/get_optimal_url.rb', line 15

def get_optimal_url(file_path, expiration=600)
  response = request(
    :expects => [200, 201],
    :method  => 'GET',
    :path    => '/ws/IMFS/GetOptimalUrls.ashx',
    :query   => {
      :filePath => file_path,
      :expiration => expiration
    }
    )
  if response.body[:ResponseCode] != "0"
    raise Excon::Errors::HTTPStatusError.new(response.body)
  end
  response.body[:Download][:DownloadURL]
end

#get_private_url(full_path) ⇒ Object



23
24
25
26
# File 'lib/fog/nirvanix/requests/storage/get_object.rb', line 23

def get_private_url(full_path)
  path = "/#{@nirvanix_session_token}/#{@nirvanix_app_name}/#{@nirvanix_username}/#{full_path}"
  'https://' + get_download_node(full_path) + path
end

#list_folder(folder = '', pageNumber = 1, pageSize = 500) ⇒ Object

The ListFolder method is used to describe the contents of a folder. It lists the files and folders as well as some basic information about the items, such as the file size, metadata, tags and created date. This call supports paging.

Parameters

  • folderPath<~String> - The path to the folder to be listed.

If not specified, the logged in accounts root folder will be listed.

  • pageNumber<~Integer> - The page number to list.

  • pageSie<~Integer> - The size of the page to return. This can be a maximum

of 500 items (this is for files and folders combined per call).



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/nirvanix/requests/storage/list_folder.rb', line 17

def list_folder(folder='', pageNumber=1, pageSize=500)
  request(
    :expects => [200, 201],
    :method  => 'GET',
    :path    => '/ws/IMFS/ListFolder.ashx',
    :query   => {
      :folderPath => folder,
      :pageNumber => pageNumber,
      :pageSize => pageSize
    }
    )
end

#request(params, parse_xml = true, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/fog/nirvanix/storage.rb', line 50

def request(params, parse_xml=true, &block)
  params[:query] ||= {}
  if !params[:no_session]
    params[:query][:sessionToken] = @nirvanix_session_token
  end
  params[:host] ||= @host
  params.merge!({:parser => Fog::ToHashDocument.new}) if parse_xml
  response = @connection.request(params, &block)
end

#upload_file(filename, folder_name, data) ⇒ Object

Upload a file

Parameters

  • name<~String> - Name for container

  • data<~String|File> - data to upload



16
17
18
19
20
21
22
# File 'lib/fog/nirvanix/requests/storage/upload_file.rb', line 16

def upload_file(filename, folder_name, data)
  upload_file_size = file_size(data)
  storage_node = get_upload_token(upload_file_size)
  file_contents = data.read
  path = "/upload.ashx?uploadToken=#{storage_node[:UploadToken]}&destFolderPath=#{folder_name}&fileMD5=#{file_md5(file_contents)}"
  post_data(storage_node[:UploadHost], path, filename, file_contents, true)
end