Class: RubyBox::File
- Inherits:
-
Item
- Object
- Item
- RubyBox::File
show all
- Defined in:
- lib/ruby-box/file.rb
Instance Method Summary
collapse
Methods inherited from Item
#delete, has_many, has_many_paginated, #initialize, #method_missing, #reload_meta, #update
Constructor Details
This class inherits a constructor from RubyBox::Item
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class RubyBox::Item
Instance Method Details
#download ⇒ Object
6
7
8
|
# File 'lib/ruby-box/file.rb', line 6
def download
resp = stream.read
end
|
#stream(opts = {}) ⇒ Object
10
11
12
13
|
# File 'lib/ruby-box/file.rb', line 10
def stream( opts={} )
url = "#{RubyBox::API_URL}/#{resource_name}/#{id}/content"
@session.do_stream( url, opts )
end
|
#update_content(data) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/ruby-box/file.rb', line 32
def update_content( data )
url = "#{RubyBox::UPLOAD_URL}/#{resource_name}/#{id}/content"
uri = URI.parse(url)
request = Net::HTTP::Post::Multipart.new(uri.path, {
"filename" => prepare_upload(data, name),
"folder_id" => parent.id
}, {"if-match" => etag })
resp = @session.request(uri, request)
if resp['entries']
@raw_item = resp['entries'][0]
else
@raw_item = resp
end
self
end
|
#upload_content(data) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/ruby-box/file.rb', line 15
def upload_content( data )
url = "#{RubyBox::UPLOAD_URL}/#{resource_name}/content"
uri = URI.parse(url)
request = Net::HTTP::Post::Multipart.new(uri.path, {
"filename" => UploadIO.new(data, "application/pdf", name),
"folder_id" => parent.id
})
resp = @session.request(uri, request)
if resp['entries']
@raw_item = resp['entries'][0]
else
@raw_item = resp
end
self
end
|