doc_converter 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/doc_converter.rb +69 -0
  3. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ff87e2aa5492ddbcc34bec08e0b19e1dcb7e49b
4
+ data.tar.gz: c486de1dfa4c760d9fc8d7c7787fe873f83b35f0
5
+ SHA512:
6
+ metadata.gz: 83ce5a1e54dfa48d64a20a76dd3c72ae50b97a8e39f607d7f4c6deb9a03f8cdc5b79690fd8ce4217d20c436d3bea527d6bce68430d6459339adeabf6babad85e
7
+ data.tar.gz: 46f2012a243eb90ed4b9ee84728e02fc4395072ef8e7ba6e882f3e9393877394c8d937459cee2334fae324abe830f1e4f0058c424f22402040fde2a98310965f
@@ -0,0 +1,69 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+ require 'rest_client'
4
+ require 'rubygems'
5
+ require 'yaml'
6
+
7
+ class DocConverter
8
+ include Base64
9
+ include OpenSSL
10
+ include RestClient
11
+
12
+ # Configuration defaults
13
+ @config = {
14
+ :server_address => "http://documentconverter.elasticbeanstalk.com",
15
+ :api_key => 'my_api_key',
16
+ :secret_key => 'my_secret_key'
17
+ }
18
+
19
+ @valid_config_keys = @config.keys
20
+
21
+ # Configure through hash
22
+ def self.configure(opts = {})
23
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
24
+ end
25
+
26
+ # Configure through yaml file
27
+ def self.configure_with(path_to_yaml_file)
28
+
29
+ begin
30
+ config = YAML::load(IO.read(path_to_yaml_file))
31
+ rescue Errno::ENOENT
32
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
33
+ rescue Psych::SyntaxError
34
+ log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
35
+ end
36
+
37
+ configure(config)
38
+ end
39
+
40
+ def self.config
41
+ @config
42
+ end
43
+
44
+
45
+ def self.convert_document(file_path, destiny_format, upload_method)
46
+
47
+ hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/convert_document/')).strip
48
+
49
+ if upload_method == 'FILE'
50
+ RestClient.post config[:server_address]+'/api/convert_document/', :document => { :file => File.new(file_path), :destination_format => destiny_format,
51
+ :upload_method => upload_method }, :api_key => config[:api_key], :hash => hash, :content_type => :json, :accept => :json
52
+ else
53
+ RestClient.post config[:server_address]+'/api/convert_document/', :document => { :file => file_path, :destination_format => destiny_format,
54
+ :upload_method => upload_method }, :api_key => config[:api_key], :hash => hash, :content_type => :json, :accept => :json
55
+ end
56
+ end
57
+
58
+ def self.get_formats(ext)
59
+ hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/convert_document/')).strip
60
+ RestClient.get config[:server_address]+'/api/convert_document/', {:params => {:extension => ext, :api_key => config[:api_key], :hash => hash},
61
+ :content_type => :json, :accept => :json}
62
+ end
63
+
64
+ def self.get_free_space
65
+ hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), config[:secret_key], config[:server_address]+'/api/free_space/')).strip
66
+ RestClient.get config[:server_address]+'/api/free_space/', {:params => {:api_key => config[:api_key], :hash => hash}, :content_type => :json, :accept => :json}
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doc_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Avila
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This library allows you to convert documents into another with the format
42
+ you desire
43
+ email:
44
+ - gonzaloavila16@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/doc_converter.rb
50
+ homepage:
51
+ licenses: []
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.1.10
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: convert your documents
73
+ test_files: []