convert_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 490a36cd3073c378252596eeb9a22acfec53842a
4
+ data.tar.gz: 9e44604dd28e83387ca640bce6fc3d7c83c7687f
5
+ SHA512:
6
+ metadata.gz: 6621beb9dc482f270ab41214b6e047fbe70721966a4bb052463983c37c512a710488f1549fef8cd737f2a9601bb0a044863ae3cdd0c3239891adc0d4b355459d
7
+ data.tar.gz: 7c188db89021801b189112674d473ff803a79f4894fb43262e8c719611dac97e07b7a57d9303d143b9cce3b068098f84f350878adf4b1a2709f7782242e81b65
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.2.0
6
+ - 2.3.0
7
+ - 2.4.1
8
+ - 2.5.1
9
+ - ruby-head
10
+ - ruby-head-clang
11
+ - jruby-head
12
+ bundler_args: --jobs=3 --retry=3 --binstubs
13
+ env:
14
+ global:
15
+ secure: Pri+nCT6ayGYkjGO/WfMGkqk4DBKseJjQuWHWdft9YH2G+5dc7UKypDqmlfZvqwLPw2kybepKfh/utRGYsL5nfbET+3Ml8+2Bgaf0IT4Ej/3B5KIdFbivHmRp/NP/Dgh64M+5u1wKEEnw1NIMHwcanQDzPUDtaxqsw1xwowUL5Axr+UnJtWL2bP/RCED2JEgwhBQBFSMBXXwpSK2yFT7X1pInPWX2S0hELxj1UDefLDjp6kEnkrU/u+FjC9RhmYhusx2muXC4pHiqdNL0fDZStgginAQAd92FsMHQyzwewefCGRAg0g25ZmSGx5cHL4BZORdUnxaG9+AS9Wt17tZI2WS9eUBc9yyRU+R76aSo79uJj4RKi1Ljd3+4fyI/9BDz9a2koEgeDbYUHHf0dYaFSLXcOpnLBBPtr0qD02SUP1EcYTOe1/sNMweDLfN67E70YV69+ZqQeb+xgCbAeeoTOGJ9uKR2c91wSZwDjpTXXSLrNeNw98FPRyWxpfRRFQV29ZDPx/cfHt9gAVQVnd+ZBCAFwr353nqE8Ux1wtrxkexPkT8G+TXIgTvvYDfu2WmaO7qrZR2D6427jc4sgndwWfSPgiLw4eW1u3hCyaCnPBsviugtj1sTs2NfnLPdgtSUcKBd4xNbbVQoqZM1qTL139HvpZFB+jD8uoVtgWigUA=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in convert_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ convert_api (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ convert_api!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Tomas Rutkauskas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # ConvertAPI Ruby Client
2
+ ## Convert your files with our online file conversion API
3
+
4
+ The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'convert_api'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Configuration
18
+
19
+ You can get your secret at https://www.convertapi.com/a
20
+
21
+ ```ruby
22
+ ConvertApi.configure do |config|
23
+ config.api_secret = 'your api secret'
24
+ end
25
+ ```
26
+
27
+ ### File conversion
28
+
29
+ Example to convert file to PDF. All supported formats and options can be found
30
+ [here](https://www.convertapi.com).
31
+
32
+ ```ruby
33
+ result = ConvertApi.convert('pdf', File: '/path/to/my_file.docx')
34
+
35
+ # save to file
36
+ result.file.save('/path/to/save/file.pdf')
37
+ ```
38
+
39
+ Other result operations:
40
+
41
+ ```ruby
42
+ # save all result files to folder
43
+ result.save_files('/path/to/save/files')
44
+
45
+ # get result file io
46
+ io = result.file.io
47
+
48
+ # get conversion cost
49
+ conversion_cost = result.conversion_cost
50
+ ```
51
+
52
+ #### Convert file url
53
+
54
+ ```ruby
55
+ result = ConvertApi.convert('pdf', File: 'https://website/my_file.docx')
56
+ ```
57
+
58
+ #### Specifying from format
59
+
60
+ ```ruby
61
+ result = ConvertApi.convert(
62
+ 'pdf',
63
+ { File: /path/to/my_file' },
64
+ from_format: 'docx'
65
+ )
66
+ ```
67
+
68
+ #### Additional conversion parameters
69
+
70
+ ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion
71
+ parameters and explanations can be found [here](https://www.convertapi.com).
72
+
73
+ ```ruby
74
+ result = ConvertApi.convert(
75
+ 'pdf',
76
+ File: /path/to/my_file.docx',
77
+ PageRange: '1-10',
78
+ PdfResolution: '150',
79
+ )
80
+ ```
81
+
82
+ ### User information
83
+
84
+ You can always check remaining seconds amount by fetching [user information](https://www.convertapi.com/doc/user).
85
+
86
+ ```ruby
87
+ user_info = ConvertApi.user
88
+
89
+ puts user_info['SecondsLeft']
90
+ ```
91
+
92
+ ### More examples
93
+
94
+ You can find more advanced examples in the [examples/](examples) folder.
95
+
96
+
97
+ ## Development
98
+
99
+ Run `CONVERT_API_SECRET=your_secret rake spec` to run the tests.
100
+
101
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'convert_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'convert_api'
7
+ spec.version = ConvertApi::VERSION
8
+ spec.authors = ['Tomas Rutkauskas']
9
+ spec.email = ['support@convertapi.com']
10
+
11
+ spec.summary = %q{ConvertAPI client library}
12
+ spec.description = %q{Convert various files like MS Word, Excel, PowerPoint, Images to PDF and Images. Create PDF and Images from url and raw HTML. Extract and create PowerPoint presentation from PDF. Merge, Encrypt, Split, Repair and Decrypt PDF files. All supported files conversions and manipulations can be found at https://www.convertapi.com/doc/supported-formats}
13
+ spec.homepage = 'https://github.com/ConvertAPI/convertapi-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features|examples)/})
18
+ end
19
+
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.16'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,36 @@
1
+ require 'convert_api/version'
2
+ require 'convert_api/configuration'
3
+ require 'convert_api/task'
4
+ require 'convert_api/client'
5
+ require 'convert_api/errors'
6
+ require 'convert_api/result'
7
+ require 'convert_api/result_file'
8
+ require 'convert_api/upload_io'
9
+ require 'convert_api/file_param'
10
+ require 'convert_api/format_detector'
11
+
12
+ module ConvertApi
13
+ URI_REGEXP = URI::regexp(%w(http https))
14
+
15
+ module_function
16
+
17
+ def configure
18
+ yield(config)
19
+ end
20
+
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+
25
+ def convert(to_format, params, from_format: nil, conversion_timeout: nil)
26
+ Task.new(from_format, to_format, params, conversion_timeout: conversion_timeout).run
27
+ end
28
+
29
+ def user
30
+ client.get('user')
31
+ end
32
+
33
+ def client
34
+ @client ||= Client.new
35
+ end
36
+ end
@@ -0,0 +1,134 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'cgi'
4
+ require 'json'
5
+
6
+ module ConvertApi
7
+ class Client
8
+ NET_HTTP_EXCEPTIONS = [
9
+ IOError,
10
+ Errno::ECONNABORTED,
11
+ Errno::ECONNREFUSED,
12
+ Errno::ECONNRESET,
13
+ Errno::EHOSTUNREACH,
14
+ Errno::EINVAL,
15
+ Errno::ENETUNREACH,
16
+ Errno::EPIPE,
17
+ Net::HTTPBadResponse,
18
+ Net::HTTPHeaderSyntaxError,
19
+ Net::ProtocolError,
20
+ SocketError,
21
+ Zlib::GzipFile::Error,
22
+ ]
23
+
24
+ USER_AGENT = "convertapi-ruby-#{VERSION}"
25
+
26
+ DEFAULT_HEADERS = {
27
+ 'User-Agent' => USER_AGENT,
28
+ 'Accept' => 'application/json'
29
+ }
30
+
31
+ def get(path, params = {}, options = {})
32
+ handle_response do
33
+ request = Net::HTTP::Get.new(request_uri(path, params), DEFAULT_HEADERS)
34
+
35
+ http(options).request(request)
36
+ end
37
+ end
38
+
39
+ def post(path, params, options = {})
40
+ handle_response do
41
+ request = Net::HTTP::Post.new(request_uri(path), DEFAULT_HEADERS)
42
+ request.form_data = build_form_data(params)
43
+
44
+ http(options).request(request)
45
+ end
46
+ end
47
+
48
+ def upload(io, filename)
49
+ handle_response do
50
+ request_uri = base_uri.path + 'upload'
51
+ encoded_filename = URI.encode(filename)
52
+
53
+ headers = DEFAULT_HEADERS.merge(
54
+ 'Content-Type' => 'application/octet-stream',
55
+ 'Transfer-Encoding' => 'chunked',
56
+ 'Content-Disposition' => "attachment; filename*=UTF-8''#{encoded_filename}",
57
+ )
58
+
59
+ request = Net::HTTP::Post.new(request_uri, headers)
60
+ request.body_stream = io
61
+
62
+ http(read_timeout: config.upload_timeout).request(request)
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def handle_response
69
+ handle_http_exceptions do
70
+ response = yield
71
+ status = response.code.to_i
72
+
73
+ if status != 200
74
+ raise(
75
+ ClientError,
76
+ status: status,
77
+ body: response.body,
78
+ headers: response.each_header.to_h,
79
+ )
80
+ end
81
+
82
+ JSON.parse(response.body)
83
+ end
84
+ end
85
+
86
+ def handle_http_exceptions
87
+ yield
88
+ rescue *NET_HTTP_EXCEPTIONS => e
89
+ raise(ConnectionFailed, e)
90
+ rescue Timeout::Error, Errno::ETIMEDOUT => e
91
+ raise(TimeoutError, e)
92
+ end
93
+
94
+ def http(read_timeout: nil)
95
+ http = Net::HTTP.new(base_uri.host, base_uri.port)
96
+ http.open_timeout = config.connect_timeout
97
+ http.read_timeout = read_timeout || config.read_timeout
98
+ http.use_ssl = base_uri.scheme == 'https'
99
+ # http.set_debug_output $stderr
100
+ http
101
+ end
102
+
103
+ def request_uri(path, params = {})
104
+ raise(SecretError, 'API secret not configured') if config.api_secret.nil?
105
+
106
+ params_with_secret = params.merge(Secret: config.api_secret)
107
+ query = URI.encode_www_form(params_with_secret)
108
+
109
+ base_uri.path + path + '?' + query
110
+ end
111
+
112
+ def build_form_data(params)
113
+ data = {}
114
+
115
+ params.each do |key, value|
116
+ if value.is_a?(Array)
117
+ value.each_with_index { |v, i| data["#{key}[#{i}]"] = v }
118
+ else
119
+ data[key] = value
120
+ end
121
+ end
122
+
123
+ data
124
+ end
125
+
126
+ def base_uri
127
+ config.base_uri
128
+ end
129
+
130
+ def config
131
+ ConvertApi.config
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,22 @@
1
+ module ConvertApi
2
+ class Configuration
3
+ attr_accessor :api_secret
4
+ attr_accessor :base_uri
5
+ attr_accessor :connect_timeout
6
+ attr_accessor :read_timeout
7
+ attr_accessor :conversion_timeout
8
+ attr_accessor :conversion_timeout_delta
9
+ attr_accessor :upload_timeout
10
+ attr_accessor :download_timeout
11
+
12
+ def initialize
13
+ @base_uri = URI('https://v2.convertapi.com/')
14
+ @connect_timeout = 5
15
+ @read_timeout = 60
16
+ @conversion_timeout = 600
17
+ @conversion_timeout_delta = 10
18
+ @upload_timeout = 600
19
+ @download_timeout = 600
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ module ConvertApi
2
+ class Error < StandardError; end
3
+ class SecretError < Error; end
4
+ class FileNameError < Error; end
5
+ class TimeoutError < Error; end
6
+ class ConnectionFailed < Error; end
7
+ class FormatError < Error; end
8
+
9
+ class ClientError < Error
10
+ attr_reader :response
11
+
12
+ def initialize(response)
13
+ @response = response
14
+ end
15
+
16
+ def to_s
17
+ return "the server responded with status #{http_status}" unless json?
18
+
19
+ "#{error_message} Code: #{code}. #{invalid_parameters}".strip
20
+ end
21
+
22
+ def error_message
23
+ response_json['Message']
24
+ end
25
+
26
+ def code
27
+ response_json['Code']
28
+ end
29
+
30
+ def invalid_parameters
31
+ response_json['InvalidParameters']
32
+ end
33
+
34
+ def http_status
35
+ response[:status]
36
+ end
37
+
38
+ def response_json
39
+ @response_json ||= begin
40
+ JSON.parse(response[:body])
41
+ rescue JSON::ParserError
42
+ {}
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def json?
49
+ response[:headers]['content-type'] =~ /json/
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,20 @@
1
+ module ConvertApi
2
+ module FileParam
3
+ module_function
4
+
5
+ def build(value)
6
+ case value
7
+ when UploadIO, URI_REGEXP
8
+ value
9
+ when Result
10
+ value.file.url
11
+ when ResultFile
12
+ value.url
13
+ when IO
14
+ UploadIO.new(value)
15
+ else
16
+ UploadIO.new(File.open(value))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ module ConvertApi
2
+ class FormatDetector
3
+ DEFAULT_URL_FORMAT = 'url'
4
+
5
+ def initialize(resource)
6
+ @resource = resource
7
+ end
8
+
9
+ def run
10
+ extension = File.extname(path).downcase
11
+
12
+ return DEFAULT_URL_FORMAT if extension.empty? && @resource =~ URI_REGEXP
13
+
14
+ format = extension[1..-1]
15
+
16
+ raise(FormatError, 'Unable to detect format') if format.nil?
17
+
18
+ format
19
+ end
20
+
21
+ private
22
+
23
+ def path
24
+ case @resource
25
+ when String
26
+ URI(@resource).path
27
+ when File
28
+ @resource.path
29
+ when UploadIO
30
+ @resource.filename
31
+ else
32
+ ''
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ module ConvertApi
2
+ class Result
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def conversion_cost
10
+ response['ConversionCost']
11
+ end
12
+
13
+ def file
14
+ files.first
15
+ end
16
+
17
+ def files
18
+ @files ||= response['Files'].map{ |file_info| ResultFile.new(file_info) }
19
+ end
20
+
21
+ def urls
22
+ files.map(&:url)
23
+ end
24
+
25
+ def save_files(path)
26
+ threads = files.map do |file|
27
+ Thread.new { file.save(path) }
28
+ end
29
+
30
+ threads.map(&:value)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ require 'open-uri'
2
+
3
+ module ConvertApi
4
+ class ResultFile
5
+ attr_reader :info
6
+
7
+ def initialize(info)
8
+ @info = info
9
+ end
10
+
11
+ def url
12
+ info['Url']
13
+ end
14
+
15
+ def filename
16
+ info['FileName']
17
+ end
18
+
19
+ def size
20
+ info['FileSize']
21
+ end
22
+
23
+ def io
24
+ @io ||= open(url, download_options)
25
+ end
26
+
27
+ def save(path)
28
+ path = File.join(path, filename) if File.directory?(path)
29
+
30
+ IO.copy_stream(io, path, size)
31
+
32
+ path
33
+ end
34
+
35
+ private
36
+
37
+ def download_options
38
+ options = { read_timeout: config.download_timeout }
39
+
40
+ options[:open_timeout] = config.connect_timeout if RUBY_VERSION > '2.2.0'
41
+
42
+ options.merge('User-Agent' => ConvertApi::Client::USER_AGENT)
43
+ end
44
+
45
+ def config
46
+ ConvertApi.config
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,73 @@
1
+ module ConvertApi
2
+ class Task
3
+ def initialize(from_format, to_format, params, conversion_timeout: nil)
4
+ @from_format = from_format
5
+ @to_format = to_format
6
+ @params = params
7
+ @conversion_timeout = conversion_timeout || config.conversion_timeout
8
+ end
9
+
10
+ def run
11
+ params = normalize_params(@params).merge(
12
+ Timeout: @conversion_timeout,
13
+ StoreFile: true,
14
+ )
15
+
16
+ from_format = @from_format || detect_format(params)
17
+ read_timeout = @conversion_timeout + config.conversion_timeout_delta
18
+
19
+ response = ConvertApi.client.post(
20
+ "#{from_format}/to/#{@to_format}",
21
+ params,
22
+ read_timeout: read_timeout
23
+ )
24
+
25
+ Result.new(response)
26
+ end
27
+
28
+ private
29
+
30
+ def normalize_params(params)
31
+ result = {}
32
+
33
+ symbolize_keys(params).each do |key, value|
34
+ case key
35
+ when :File
36
+ result[:File] = FileParam.build(value)
37
+ when :Files
38
+ result[:Files] = files_batch(value)
39
+ else
40
+ result[key] = value
41
+ end
42
+ end
43
+
44
+ result
45
+ end
46
+
47
+ def symbolize_keys(hash)
48
+ hash.map { |k, v| [k.to_sym, v] }.to_h
49
+ end
50
+
51
+ def files_batch(values)
52
+ files = Array(values).map { |file| FileParam.build(file) }
53
+
54
+ # upload files in parallel
55
+ files
56
+ .select { |file| file.is_a?(UploadIO) }
57
+ .map { |upload_io| Thread.new { upload_io.file_id } }
58
+ .map(&:join)
59
+
60
+ files
61
+ end
62
+
63
+ def detect_format(params)
64
+ resource = params[:File] || params[:Url] || Array(params[:Files]).first
65
+
66
+ FormatDetector.new(resource).run
67
+ end
68
+
69
+ def config
70
+ ConvertApi.config
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,31 @@
1
+ require 'uri'
2
+
3
+ module ConvertApi
4
+ class UploadIO
5
+ attr_reader :io, :filename
6
+
7
+ def initialize(io, filename = nil)
8
+ @io = io
9
+ @filename = filename || io_filename || raise(FileNameError, 'IO filename must be provided')
10
+ end
11
+
12
+ def to_s
13
+ file_id
14
+ end
15
+
16
+ def file_id
17
+ @file_id ||= upload_file['FileId']
18
+ end
19
+
20
+ private
21
+
22
+ def upload_file
23
+ ConvertApi.client.upload(io, filename)
24
+ end
25
+
26
+ def io_filename
27
+ return unless io.respond_to?(:path)
28
+ File.basename(io.path)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module ConvertApi
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: convert_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Rutkauskas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Convert various files like MS Word, Excel, PowerPoint, Images to PDF
56
+ and Images. Create PDF and Images from url and raw HTML. Extract and create PowerPoint
57
+ presentation from PDF. Merge, Encrypt, Split, Repair and Decrypt PDF files. All
58
+ supported files conversions and manipulations can be found at https://www.convertapi.com/doc/supported-formats
59
+ email:
60
+ - support@convertapi.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".ruby-version"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - convert_api.gemspec
75
+ - lib/convert_api.rb
76
+ - lib/convert_api/client.rb
77
+ - lib/convert_api/configuration.rb
78
+ - lib/convert_api/errors.rb
79
+ - lib/convert_api/file_param.rb
80
+ - lib/convert_api/format_detector.rb
81
+ - lib/convert_api/result.rb
82
+ - lib/convert_api/result_file.rb
83
+ - lib/convert_api/task.rb
84
+ - lib/convert_api/upload_io.rb
85
+ - lib/convert_api/version.rb
86
+ homepage: https://github.com/ConvertAPI/convertapi-ruby
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ConvertAPI client library
110
+ test_files: []