Class: DIDWW::Resource::EncryptedFile
- Defined in:
- lib/didww/resource/encrypted_file.rb
Defined Under Namespace
Classes: UploadError
Class Method Summary collapse
- .upload(payload) ⇒ Array<String>
- .upload_connection ⇒ Faraday::Connection
- .upload_files(files, fingerprint) ⇒ Array<String>
Methods inherited from Base
Class Method Details
.upload(payload) ⇒ Array<String>
47 48 49 50 51 52 53 54 55 |
# File 'lib/didww/resource/encrypted_file.rb', line 47 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)[:ids] else raise UploadError, "Code: #{response.status} #{response.body}" end end |
.upload_connection ⇒ Faraday::Connection
17 18 19 20 21 22 23 24 |
# File 'lib/didww/resource/encrypted_file.rb', line 17 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_files(files, fingerprint) ⇒ Array<String>
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/didww/resource/encrypted_file.rb', line 29 def self.upload_files(files, fingerprint) items = files.map do |file| { file: Faraday::UploadIO.new(file.tempfile, file.content_type), description: file.original_filename } end payload = { encryption_fingerprint: fingerprint, items: items } upload(payload) end |