Module: Zotero::FileUpload
- Included in:
- Client
- Defined in:
- lib/zotero/file_upload.rb
Overview
File upload methods for handling attachment uploads
Instance Method Summary collapse
- #external_post(url, multipart_data:) ⇒ Object
- #post_form(path, form_data:, if_match: nil, if_none_match: nil, params: {}) ⇒ Object
- #register_upload(path, upload_key:) ⇒ Object
- #request_upload_authorization(path, filename:, md5: nil, mtime: nil, existing_file: false) ⇒ Object
Instance Method Details
#external_post(url, multipart_data:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zotero/file_upload.rb', line 16 def external_post(url, multipart_data:) response = http_request(:post, url, body: multipart_data, multipart: true, format: :plain) code = response.code.to_i case code when 200..299 response.body else raise Error, "External upload failed: HTTP #{code} - #{response.message}" end end |
#post_form(path, form_data:, if_match: nil, if_none_match: nil, params: {}) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/zotero/file_upload.rb', line 6 def post_form(path, form_data:, if_match: nil, if_none_match: nil, params: {}) headers = auth_headers.merge(default_headers) headers["Content-Type"] = "application/x-www-form-urlencoded" headers["If-Match"] = if_match if if_match headers["If-None-Match"] = if_none_match if if_none_match response = http_request(:post, path, headers: headers, body: form_data, params: params) handle_response(response) end |
#register_upload(path, upload_key:) ⇒ Object
38 39 40 |
# File 'lib/zotero/file_upload.rb', line 38 def register_upload(path, upload_key:) post_form(path, form_data: { upload: upload_key }) end |
#request_upload_authorization(path, filename:, md5: nil, mtime: nil, existing_file: false) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/zotero/file_upload.rb', line 28 def (path, filename:, md5: nil, mtime: nil, existing_file: false) form_data = { upload: filename, md5: md5, mtime: mtime }.compact if existing_file post_form(path, form_data: form_data, if_match: md5.to_s) else post_form(path, form_data: form_data, if_none_match: "*") end end |