Class: DropboxApi::Endpoints::ContentUpload
- Defined in:
- lib/dropbox_api/endpoints/content_upload.rb
Direct Known Subclasses
Files::Upload, Files::UploadSessionAppendV2, Files::UploadSessionFinish, Files::UploadSessionStart
Instance Method Summary collapse
- #build_request(params, content) ⇒ Object
-
#initialize(builder) ⇒ ContentUpload
constructor
A new instance of ContentUpload.
- #perform_request(params, content) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(builder) ⇒ ContentUpload
Returns a new instance of ContentUpload.
3 4 5 6 7 |
# File 'lib/dropbox_api/endpoints/content_upload.rb', line 3 def initialize(builder) @connection = builder.build("https://content.dropboxapi.com") do |c| c.response :decode_result end end |
Instance Method Details
#build_request(params, content) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dropbox_api/endpoints/content_upload.rb', line 9 def build_request(params, content) # TODO: It would be better to have a stream object on which we can call # #read, rather than the full file content. body = content headers = { 'Dropbox-API-Arg' => JSON.dump(params), 'Content-Type' => 'application/octet-stream' } if body.respond_to?(:length) headers['Content-Length'] = body.length.to_s elsif body.respond_to?(:stat) headers['Content-Length'] = body.stat.size.to_s end return body, headers end |
#perform_request(params, content) ⇒ Object
26 27 28 |
# File 'lib/dropbox_api/endpoints/content_upload.rb', line 26 def perform_request(params, content) process_response(get_response(params, content)) end |