Class: MountableFileServer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mountable_file_server/client.rb

Instance Method Summary collapse

Instance Method Details

#move_to_permanent_storage(fid) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mountable_file_server/client.rb', line 7

def move_to_permanent_storage(fid)
  if MountableFileServer.config.base_url.start_with?('http')
    uri = ::URI.parse(MountableFileServer.config.base_url)
    http = Net::HTTP.new(uri.host, uri.port)
    http.set_debug_output($stdout)
    request = Net::HTTP::Post.new(uri.request_uri + fid + '/store-permanent')

    http.request(request)
  else
    MountableFileServer::Server.new.call({
      "rack.input" => StringIO.new(""),
      "REQUEST_METHOD"=> "POST",
      "PATH_INFO"=> "/#{fid}/store-permanent",
    })
  end
end

#remove_from_storage(fid) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mountable_file_server/client.rb', line 24

def remove_from_storage(fid)
  if MountableFileServer.config.base_url.start_with?('http')
    uri = ::URI.parse(MountableFileServer.config.base_url)
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Delete.new(uri.request_uri + fid)

    http.request(request)
  else
    MountableFileServer::Server.new.call({
      "rack.input" => StringIO.new(""),
      "REQUEST_METHOD"=> "DELETE",
      "PATH_INFO"=> "/#{fid}",
    })
  end
end

#url_for(fid) ⇒ Object



40
41
42
# File 'lib/mountable_file_server/client.rb', line 40

def url_for(fid)
  MountableFileServer.config.base_url + fid
end