Class: Algorithmia::DataFile

Inherits:
DataObject show all
Defined in:
lib/algorithmia/data_file.rb

Instance Attribute Summary

Attributes inherited from DataObject

#data_uri

Instance Method Summary collapse

Methods inherited from DataObject

#basename, #initialize, #parent

Constructor Details

This class inherits a constructor from Algorithmia::DataObject

Instance Method Details

#deleteObject



39
40
41
42
# File 'lib/algorithmia/data_file.rb', line 39

def delete
  Algorithmia::Requester.new(@client).delete(@url)
  true
end

#exists?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/algorithmia/data_file.rb', line 6

def exists?
  Algorithmia::Requester.new(@client).head(@url)
  true
rescue Errors::NotFoundError
  false
end

#getObject



24
25
26
# File 'lib/algorithmia/data_file.rb', line 24

def get
  Algorithmia::Requester.new(@client).get(@url).body
end

#get_fileObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/algorithmia/data_file.rb', line 13

def get_file
  response = get

  tempfile = Tempfile.open(File.basename(@url)) do |f|
    f.write response
    f
  end

  File.new(tempfile.path)
end

#put(data) ⇒ Object Also known as: put_json



28
29
30
# File 'lib/algorithmia/data_file.rb', line 28

def put(data)
  Algorithmia::Requester.new(@client).put(@url, data, headers: {})
end

#put_file(file_path) ⇒ Object



34
35
36
37
# File 'lib/algorithmia/data_file.rb', line 34

def put_file(file_path)
  data = File.binread(file_path)
  put(data)
end