Module: Rest::InternalClient::Mimes

Defined in:
lib/rest/wrappers/internal_client/internal/mimes.rb

Class Method Summary collapse

Class Method Details

.mime_for(path) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rest/wrappers/internal_client/internal/mimes.rb', line 6

def self.mime_for(path)
  ret = Mimes.mime_for_ext(path)
  if ret
    return ret
  end
  return 'text/plain'
end

.mime_for_ext(path) ⇒ Object

takes something like json and returns application/json. If no conversion, returns ext passed in



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rest/wrappers/internal_client/internal/mimes.rb', line 16

def self.mime_for_ext(path)
  ret = nil
  dot = path.rindex('.')
  if dot
    ext = path[dot+1..path.length]
  else
    ext = path
  end
  # feel free to add more mime-types anyone.
  case ext
    when 'xml'
      ret = 'application/xml'
    when 'gif'
      ret = 'image/gif'
    when 'jpg', 'jpeg'
      ret = 'image/jpeg'
    when 'json'
      ret = 'application/json'
    when 'html'
      ret = 'text/html'
    when 'mp3'
      ret = 'audio/mpeg'
    when 'pdf'
      ret = 'application/pdf'
  end
  return ret
end

.mime_for_or_not(ext) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rest/wrappers/internal_client/internal/mimes.rb', line 44

def self.mime_for_or_not(ext)
  ret = Mimes.mime_for_ext(ext)
  if ret
    return ret
  end
  return ext
end