Class: DIDWW::Resource::EncryptedFile
- Defined in:
- lib/didww/resource/encrypted_file.rb
Defined Under Namespace
Classes: UploadError
Class Method Summary collapse
-
.upload(payload) ⇒ String
New resource id.
- .upload_connection ⇒ Faraday::Connection
-
.upload_file(file, fingerprint, description: nil) ⇒ String
New resource id.
Methods inherited from Base
Class Method Details
.upload(payload) ⇒ String
Returns new resource id.
48 49 50 51 52 53 54 55 56 |
# File 'lib/didww/resource/encrypted_file.rb', line 48 def self.upload(payload) connection = upload_connection response = connection.post('/v3/encrypted_files', encrypted_files: payload) if response.status == 201 JSON.parse(response.body, symbolize_names: true).dig(:data, :id) else raise UploadError, "Code: #{response.status} #{response.body}" end end |
.upload_connection ⇒ Faraday::Connection
19 20 21 22 23 24 25 26 |
# File 'lib/didww/resource/encrypted_file.rb', line 19 def self.upload_connection Faraday.new(url: site) do |connection| connection.request :multipart connection.request :url_encoded connection.adapter Faraday.default_adapter connection.use DIDWW::BaseMiddleware end end |
.upload_file(file, fingerprint, description: nil) ⇒ String
Returns new resource id.
33 34 35 36 37 38 39 40 |
# File 'lib/didww/resource/encrypted_file.rb', line 33 def self.upload_file(file, fingerprint, description: nil) payload = { encryption_fingerprint: fingerprint, file: Faraday::Multipart::FilePart.new(file.tempfile, file.content_type), description: description || file.original_filename } upload(payload) end |