Class: Algorithmia::DataFile
Instance Attribute Summary
Attributes inherited from DataObject
#data_uri
Instance Method Summary
collapse
Methods inherited from DataObject
#basename, #initialize, #parent
Instance Method Details
#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
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/algorithmia/data_file.rb', line 28
def put(data)
content_type = case
when data.kind_of?(String) && data.encoding == Encoding::ASCII_8BIT
'application/octet-stream'
when data.kind_of?(String)
'text/plain'
else
'application/json'
end
= {'Content-Type' => content_type }
Algorithmia::Requester.new(@client).put(@url, data, headers: )
true
end
|
#put_file(file_path) ⇒ Object
45
46
47
48
|
# File 'lib/algorithmia/data_file.rb', line 45
def put_file(file_path)
data = File.binread(file_path)
put(data)
end
|