libreconv 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d201da6f6e044de9222041ca137e8ecdd1962991
4
- data.tar.gz: ddd509dad045567bafd05bc563465def3424a511
3
+ metadata.gz: 1c0b2e8c36829fb01420f9da4efb0cd1565d7a65
4
+ data.tar.gz: 940540e2e7786e7834d8aa7fed9ec7cc845a2fec
5
5
  SHA512:
6
- metadata.gz: 1ab245ba4df5b5b464780e8851d49145ecb925ee82a9ee1aa7f1a2c6bc35339f07852126f1a77095c4b0233fbb94d36f422fba4ea5d13871949c905984e26b8e
7
- data.tar.gz: 20705eee2c9e340114d2d5d20351f2540ddf7846ec008af8adc5801f90df41564c4c27b5f23c1bb7ea514c58d24c2d8f9cfa8064840b85031a6400b4ef852780
6
+ metadata.gz: b6126da8cda5ccd76b8585f5c9511349578c6713e77e67968d2d0aca2d4b6166b2c2d2061744781d79b68adf638e36769f1b5a9ce954ad59751057fcced3141d
7
+ data.tar.gz: 09148e1e93cde05f3fb30b58e6774b61a73b73fe9abb92c6911fca799e659c964a8ddc8cc81b1a1709250d0bbbb55031e210790cf67a7735d64b79b503270767
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Libreconv
2
2
 
3
- Convert office documents to PDF using LibreOffice / OpenOffice for the heavy lifting.
3
+ Convert office documents to PDF using LibreOffice / OpenOffice.
4
4
 
5
5
  [![Code Climate](https://codeclimate.com/github/ricn/libreconv.png)](https://codeclimate.com/github/ricn/libreconv)
6
6
 
@@ -29,6 +29,9 @@ require 'libreconv'
29
29
  # This requires that the soffice binary is present in your PATH.
30
30
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')
31
31
 
32
+ # You can also convert a source file directly from an URL
33
+ Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents')
34
+
32
35
  # Converts document.docx to document.pdf
33
36
  # If you for some reason can't have soffice in your PATH you can specifiy the file path to the soffice binary
34
37
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')
@@ -1,3 +1,3 @@
1
1
  module Libreconv
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/libreconv.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "libreconv/version"
2
+ require "uri"
3
+ require "net/http"
2
4
 
3
5
  module Libreconv
4
6
 
@@ -14,14 +16,11 @@ module Libreconv
14
16
  @target_path = target_path
15
17
  @soffice_command = soffice_command
16
18
  determine_soffice_command
19
+ check_source_type
17
20
 
18
21
  unless @soffice_command && File.exists?(@soffice_command)
19
22
  raise IOError, "Can't find Libreoffice or Openoffice executable."
20
23
  end
21
-
22
- unless File.exists?(source)
23
- raise IOError, "Source file (#{source}) does not exist."
24
- end
25
24
  end
26
25
 
27
26
  def convert
@@ -49,5 +48,17 @@ module Libreconv
49
48
 
50
49
  return nil
51
50
  end
51
+
52
+ def check_source_type
53
+ if File.exists?(@source) && File.directory?(@source) == false
54
+ :file
55
+ elsif URI(@source).scheme == "http" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
56
+ :http
57
+ elsif URI(@source).scheme == "https" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
58
+ :https
59
+ else
60
+ raise IOError, "Source (#{@source}) is neither file nor http."
61
+ end
62
+ end
52
63
  end
53
64
  end
@@ -23,7 +23,7 @@ describe Libreconv do
23
23
  lambda { Libreconv::Converter.new(@doc_file, "/target", "/Whatever/soffice") }.should raise_error(IOError)
24
24
  end
25
25
 
26
- it "should raise error if source file does not exists" do
26
+ it "should raise error if source does not exists" do
27
27
  lambda { Libreconv::Converter.new(file_path("nonsense.txt"), "/target") }.should raise_error(IOError)
28
28
  end
29
29
  end
@@ -57,6 +57,14 @@ describe Libreconv do
57
57
  File.exists?(target_file).should == true
58
58
  end
59
59
 
60
+ it "should convert a docx to pdf specifying an URL as source" do
61
+ url = "https://www.filepicker.io/api/file/XqCEPkH9RdOQr0S6zF5N"
62
+ target_file = "#{@target_path}/XqCEPkH9RdOQr0S6zF5N.pdf"
63
+ converter = Libreconv::Converter.new(url, @target_path)
64
+ converter.convert
65
+ File.exists?(target_file).should == true
66
+ end
67
+
60
68
  it "try converting binary file" do
61
69
  source = @bin_file
62
70
  target_file = "#{@target_path}/#{File.basename(source, ".bin")}.pdf"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libreconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Nyström
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-25 00:00:00.000000000 Z
11
+ date: 2013-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler