file-convert 0.1.0 → 0.1.1
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.
- data/README.md +2 -3
- data/lib/file_convert/conversion.rb +8 -5
- data/lib/file_convert/exception.rb +3 -4
- data/lib/file_convert/version.rb +1 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# file-convert [](http://badge.fury.io/rb/file-convert) [](https://travis-ci.org/tolingo/file-convert)
|
1
|
+
# file-convert [](http://badge.fury.io/rb/file-convert) [](https://travis-ci.org/tolingo/file-convert) [](http://tolingo.com)
|
2
2
|
[](https://codeclimate.com/repos/53f4984b6956807963019c1a/feed) [](https://codeclimate.com/repos/53f4984b6956807963019c1a/feed) [](https://gemnasium.com/tolingo/file-convert)
|
3
3
|
|
4
4
|
> Use google-api-ruby-client and Google Drive to convert files from one mime-type to another.
|
@@ -41,8 +41,7 @@ conversion.save('path_to_new_file.pdf')
|
|
41
41
|
|
42
42
|
* `$ bundle exec rake` for `rspec` and `rubocop`.
|
43
43
|
* `$ bundle exec rake build` to also run the `integration` tests located at `spec/integration/**/*_integration.rb`.
|
44
|
-
Note that you need to
|
45
|
-
since we want to actually test the integration with the Google API here. (Do not worry, TravisCI will run these test as well.)
|
44
|
+
Note that you need to configure valid Google API credentials (i.e. set `ENV['email']` and `ENV['pkcspath']`) for these tests to work, since we want to actually test the integration with the Google API here. (Do not worry, TravisCI will run these tests as well.)
|
46
45
|
|
47
46
|
## Contributing
|
48
47
|
|
@@ -15,12 +15,14 @@ module FileConvert
|
|
15
15
|
def initialize(client, remote_file, mime_type)
|
16
16
|
@client = client
|
17
17
|
@remote_file = remote_file
|
18
|
-
@
|
18
|
+
@original_upload_result = remote_file.original_file
|
19
|
+
@remote_file_data = remote_file.data
|
19
20
|
@mime_type = mime_type
|
20
21
|
|
21
|
-
#
|
22
|
+
# Fail if upload errored
|
23
|
+
fail data_error_exception if @original_upload_result.error?
|
24
|
+
# Fail if requested mime-type is not available
|
22
25
|
fail missing_mime_type_exception unless export_links.key?(mime_type)
|
23
|
-
fail data_error_exception if @original_file_data.to_hash.key?('error')
|
24
26
|
|
25
27
|
@file = fetch_file
|
26
28
|
@body = @file.body
|
@@ -41,7 +43,8 @@ module FileConvert
|
|
41
43
|
##
|
42
44
|
# @return [Hash] available mime-type download URIs
|
43
45
|
def export_links
|
44
|
-
@
|
46
|
+
available_links = @remote_file_data['exportLinks'] || {}
|
47
|
+
available_links.to_hash
|
45
48
|
end
|
46
49
|
|
47
50
|
###
|
@@ -56,7 +59,7 @@ module FileConvert
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def data_error_exception
|
59
|
-
Exception::UploadedFileDataError.new @
|
62
|
+
Exception::UploadedFileDataError.new @original_upload_result
|
60
63
|
end
|
61
64
|
|
62
65
|
def missing_mime_type_exception
|
@@ -16,15 +16,14 @@ module FileConvert
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class UploadedFileDataError < StandardError
|
19
|
-
def initialize(
|
19
|
+
def initialize(upload_result)
|
20
20
|
super()
|
21
|
-
@
|
21
|
+
@upload_result = upload_result
|
22
22
|
end
|
23
23
|
|
24
24
|
def message
|
25
25
|
''"
|
26
|
-
An error occured while uploading
|
27
|
-
Data was: #{@file_data}
|
26
|
+
An error occured while uploading: #{@upload_result.error_message}.
|
28
27
|
"''
|
29
28
|
end
|
30
29
|
end
|
data/lib/file_convert/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-09-
|
14
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: google-api-client
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ~>
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 3.
|
39
|
+
version: 3.1.0
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.1.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rubocop
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.26.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - ~>
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.
|
63
|
+
version: 0.26.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: rake
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|