Class: GoodData::Bricks::FsProjectUploadMiddleware

Inherits:
Middleware show all
Defined in:
lib/gooddata/bricks/middleware/fs_upload_middleware.rb

Instance Attribute Summary

Attributes inherited from Middleware

#app

Instance Method Summary collapse

Methods inherited from Middleware

#load_defaults

Methods included from Utils

#returning

Constructor Details

#initialize(options = {}) ⇒ FsProjectUploadMiddleware

Returns a new instance of FsProjectUploadMiddleware.



12
13
14
15
# File 'lib/gooddata/bricks/middleware/fs_upload_middleware.rb', line 12

def initialize(options = {})
  super
  @destination = options[:destination]
end

Instance Method Details

#call(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gooddata/bricks/middleware/fs_upload_middleware.rb', line 17

def call(params)
  params = params.to_hash
  returning(@app.call(params)) do |_|
    destination = @destination
    (params['gdc_files_to_upload'] || []).each do |f|
      path = f[:path]
      case destination.to_sym
      when :staging
        GoodData.client.get '/gdc/account/token', dont_reauth: true
        url = GoodData.project_webdav_path
        GoodData.upload_to_project_webdav(path)
        GoodData.logger.info("Uploaded local file \"#{path}\" to url \"#{url + path}\"")
      end
    end
  end
end