Class: DropboxApi::MiddleWare::PathRoot

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/dropbox_api/middleware/path_root.rb

Constant Summary collapse

HEADER_NAME =
'Dropbox-API-Path-Root'

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ PathRoot

Returns a new instance of PathRoot.



6
7
8
9
# File 'lib/dropbox_api/middleware/path_root.rb', line 6

def initialize(app, options = {})
  super(app)
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/dropbox_api/middleware/path_root.rb', line 27

def call(env)
  if !namespace_id.nil?
    env[:request_headers][HEADER_NAME] ||= namespace_id_header_value
  end

  @app.call env
end

#namespace_idObject



11
12
13
14
15
16
17
# File 'lib/dropbox_api/middleware/path_root.rb', line 11

def namespace_id
  if @options[:namespace_id].nil?
    return nil
  else
    return @options[:namespace_id]
  end
end

#namespace_id_header_valueObject



19
20
21
22
23
24
25
# File 'lib/dropbox_api/middleware/path_root.rb', line 19

def namespace_id_header_value
  JSON.dump(
    DropboxApi::Metadata::NamespaceId.new({
      'namespace_id' => namespace_id
    }).to_hash
  )
end