Class: Dina::FileConnection
- Inherits:
-
Object
- Object
- Dina::FileConnection
- Defined in:
- lib/dina/models/object_store/file_connection.rb
Instance Method Summary collapse
-
#initialize(options = {}) {|_self| ... } ⇒ FileConnection
constructor
A new instance of FileConnection.
- #run(request_method, path, params: nil, headers: {}, body: nil) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ FileConnection
Returns a new instance of FileConnection.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dina/models/object_store/file_connection.rb', line 6 def initialize( = {}) site = .fetch(:site) = .slice(:proxy, :ssl, :request, :headers, :params) = Array(.fetch(:adapter, Faraday.default_adapter)) @faraday = Faraday.new(site, ) do |builder| builder.request :multipart builder.response :json builder.adapter(*) end yield(self) if block_given? end |
Instance Method Details
#run(request_method, path, params: nil, headers: {}, body: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dina/models/object_store/file_connection.rb', line 19 def run(request_method, path, params: nil, headers: {}, body: nil) path = path + "/#{body[:data]["attributes"]["group"].downcase}" if body[:data]["attributes"].key?("isDerivative") path = path + "/derivative" end file_path = body[:data]["attributes"]["filePath"] mime_type = body[:data]["attributes"]["dcFormat"] file_name = body[:data]["attributes"]["fileName"] body[:file] = Faraday::Multipart::FilePart.new( file_path, mime_type, file_name ) response = @faraday.run_request(request_method, path, body, headers) do |request| request.params.update(params) if params end attributes = response.body.dup response.body["meta"] = {} response.body["errors"] = [] response.body["data"] = { "id" => attributes["uuid"], "type" => "file", "relationships" => {}, "attributes" => attributes } response end |