Module: BulutfonSDK::Util

Included in:
REST::Announcement, REST::OutgoingFax
Defined in:
lib/bulutfon_sdk/util.rb,
lib/bulutfon_sdk/util/client_config.rb

Defined Under Namespace

Classes: ClientConfig

Instance Method Summary collapse

Instance Method Details

#file_content_type(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bulutfon_sdk/util.rb', line 3

def file_content_type(path)
  if File.exist? path
    stdin,stdout,stderr = Open3.popen3(%{file --mime -b #{path}})

    file_err  = stderr.gets
    file_out  = stdout.gets

    raise BulutfonSDK::REST::SDKError.new "The 'file' command line binary was not found." if file_err

    return file_out.split(';')[0].strip if file_err.nil? && (!file_out.nil? && !file_out.empty?)
  end

  raise BulutfonSDK::REST::SDKError.new 'File content type not found'
end