convert_api 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd72fca187099e042455dad6a0ad4f4539c2f029
4
- data.tar.gz: 3473d92471abe8e930dff6be6a1955b3af9bcb91
3
+ metadata.gz: 10c027fe092b92379732b9ace81b981a4cc65ae8
4
+ data.tar.gz: 30e6381b72fb1489f0a20e171afe90fd7ba4f533
5
5
  SHA512:
6
- metadata.gz: 62d27c9cb2cf78f16239b2060c576f3d780d740a2f9bdbc2c3e8151a24e87b6cf61c4a82ffb628807b8b8e0d4bb1825fc1ec17424a1a6cea757bdc84d198b42d
7
- data.tar.gz: 40a26203d6561e25d00821534709e3c05f441d7134589e487f31d9eb8f82d2a7ec5a9d212d3cadfe2ac8d0f17fa761eefba39775b8f5f0c373af3504710cf0de
6
+ metadata.gz: e05161c98250dc7de2af71758838af0723612bd29bb110340f8fb481e6ebd72a50e68b1d0f2d83b42ca39ba9bbe443cf7fceb15b3018ebe1ec2b86f2bec1af22
7
+ data.tar.gz: b1872e5582d1a362d72371112d690b79bf3cec4624ce86b55be515eb86540c80ae0e6eea7c18d6040794cd70c9ac36d31dfa31aecbcc248d391af15e016efefc
data/README.md CHANGED
@@ -25,7 +25,7 @@ You can get your secret at https://www.convertapi.com/a
25
25
 
26
26
  ```ruby
27
27
  ConvertApi.configure do |config|
28
- config.api_secret = 'your api secret'
28
+ config.api_secret = 'your-api-secret'
29
29
  end
30
30
  ```
31
31
 
@@ -5,24 +5,25 @@ module ConvertApi
5
5
  end
6
6
 
7
7
  def run
8
- extension = File.extname(path).downcase
9
- format = extension[1..-1]
8
+ return @resource.file_ext.downcase if @resource.is_a?(UploadIO)
10
9
 
11
- raise(FormatError, 'Unable to detect format') if format.nil?
12
-
13
- format
10
+ format_from_path
14
11
  end
15
12
 
16
13
  private
17
14
 
15
+ def format_from_path
16
+ extension = File.extname(path).downcase
17
+ format = extension[1..-1]
18
+ format || raise(FormatError, 'Unable to detect format')
19
+ end
20
+
18
21
  def path
19
22
  case @resource
20
23
  when String
21
24
  URI(@resource).path
22
25
  when File
23
26
  @resource.path
24
- when UploadIO
25
- @resource.filename
26
27
  else
27
28
  ''
28
29
  end
@@ -2,8 +2,6 @@ require 'uri'
2
2
 
3
3
  module ConvertApi
4
4
  class UploadIO
5
- attr_reader :io, :filename
6
-
7
5
  def initialize(io, filename = nil)
8
6
  @io = io
9
7
  @filename = filename || io_filename || raise(FileNameError, 'IO filename must be provided')
@@ -14,18 +12,30 @@ module ConvertApi
14
12
  end
15
13
 
16
14
  def file_id
17
- @file_id ||= upload_file['FileId']
15
+ result['FileId']
16
+ end
17
+
18
+ def file_name
19
+ result['FileName']
20
+ end
21
+
22
+ def file_ext
23
+ result['FileExt']
18
24
  end
19
25
 
20
26
  private
21
27
 
28
+ def result
29
+ @result ||= upload_file
30
+ end
31
+
22
32
  def upload_file
23
- ConvertApi.client.upload(io, filename)
33
+ ConvertApi.client.upload(@io, @filename)
24
34
  end
25
35
 
26
36
  def io_filename
27
- return unless io.respond_to?(:path)
28
- File.basename(io.path)
37
+ return unless @io.respond_to?(:path)
38
+ File.basename(@io.path)
29
39
  end
30
40
  end
31
41
  end
@@ -1,3 +1,3 @@
1
1
  module ConvertApi
2
- VERSION = '1.0.4'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convert_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Rutkauskas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-16 00:00:00.000000000 Z
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler