Class: DocConverter

Inherits:
Object
  • Object
show all
Includes:
Base64, OpenSSL, RestClient
Defined in:
lib/doc_converter.rb

Class Method Summary collapse

Class Method Details

.configObject



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

def self.config
  @config
end

.configure(opts = {}) ⇒ Object

Configure through hash



22
23
24
# File 'lib/doc_converter.rb', line 22

def self.configure(opts = {})
  opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
end

.configure_with(path_to_yaml_file) ⇒ Object

Configure through yaml file



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/doc_converter.rb', line 27

def self.configure_with(path_to_yaml_file)

  begin
    config = YAML::load(IO.read(path_to_yaml_file))
    rescue Errno::ENOENT
    log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
  rescue Psych::SyntaxError
    log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
  end

  configure(config)
end

.convert_document(file_path, destiny_format, upload_method) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/doc_converter.rb', line 45

def self.convert_document(file_path, destiny_format, upload_method)
 
 hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/convert_document/')).strip
 
 if upload_method == 'FILE'
  RestClient.post config[:server_address]+'/api/convert_document/', :document => { :file => File.new(file_path), :destination_format => destiny_format, 
                            :upload_method => upload_method }, :api_key => config[:api_key], :hash => hash, :content_type => :json, :accept => :json  
 else
  RestClient.post config[:server_address]+'/api/convert_document/', :document => { :file => file_path, :destination_format => destiny_format, 
                            :upload_method => upload_method }, :api_key => config[:api_key], :hash => hash, :content_type => :json, :accept => :json
 end
end

.get_formats(ext) ⇒ Object



58
59
60
61
62
# File 'lib/doc_converter.rb', line 58

def self.get_formats(ext)
  hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/convert_document/')).strip
  RestClient.get config[:server_address]+'/api/convert_document/', {:params => {:extension => ext, :api_key => config[:api_key], :hash => hash}, 
                                                                :content_type => :json, :accept => :json}
end

.get_free_spaceObject



64
65
66
67
# File 'lib/doc_converter.rb', line 64

def self.get_free_space
  hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/free_space/')).strip
  RestClient.get config[:server_address]+'/api/free_space/', {:params => {:api_key => config[:api_key], :hash => hash}, :content_type => :json, :accept => :json}
end