Class: Algorithmia::DataFile
- Inherits:
-
DataObject
- Object
- DataObject
- Algorithmia::DataFile
- Defined in:
- lib/algorithmia/data_file.rb
Instance Attribute Summary
Attributes inherited from DataObject
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #get ⇒ Object
- #get_file ⇒ Object
- #put(data) ⇒ Object (also: #put_json)
- #put_file(file_path) ⇒ Object
Methods inherited from DataObject
#basename, #initialize, #parent
Constructor Details
This class inherits a constructor from Algorithmia::DataObject
Instance Method Details
#delete ⇒ Object
39 40 41 42 |
# File 'lib/algorithmia/data_file.rb', line 39 def delete Algorithmia::Requester.new(@client).delete(@url) true end |
#exists? ⇒ 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 |
#get ⇒ Object
24 25 26 |
# File 'lib/algorithmia/data_file.rb', line 24 def get Algorithmia::Requester.new(@client).get(@url).body end |
#get_file ⇒ Object
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 |