file-convert

Use google-api-ruby-client and Google Drive to convert files from one mime-type to another. For available formats see Google Drive API Export Formats.
Installation
Simply add it to your Gemfile:
gem 'file-convert'
Config
Via initializer
FileConvert exposes .configure which accepts a block and passes the config hash.
Example:
FileConvert.configure do |config|
config['google_service_account'] = {
'email' => '<strange-hash>@developer.gserviceaccount.com',
'pkcs12_file_path' => 'config/file_convert_key.p12'
}
end
Via YAML
You need to add a YAML configuration file to /config/file_convert.yml that looks like config/file_convert.sample.yml.
In order to communicate with the Google API, file_convert requires a google developer email Address (email) and pkcs12_file_path.
Visit Google Developers Console and check Credentials. Here you can add a new Client ID. Select Service Account as application type.
You should now be able to download your P12 key and see your developer email address.
Place the P12 key somewhere accessible for your app and provide the location to the config. The sample config assumes your P12 key is located in /config/file_convert_key.p12.
Sample config as in file_convert.samle.yml:
file_convert:
google_service_account:
email: '<strange-hash>@developer.gserviceaccount.com'
pkcs12_file_path: 'config/file_convert_key.p12'
Examples
# converts `path_to_some_file` from <txt> to <pdf>
conversion = FileConvert.convert('path_to_some_file.txt', 'text/plain', 'application/pdf')
# converted body is accessible via `#body`
conversion.body
# .. or define a path to save the converted document to
conversion.save('path_to_new_file.pdf')
Specs
$ bundle exec rakeforrspecandrubocop.$ bundle exec rake buildto also run theintegrationtests located atspec/integration/**/*_integration.rb. Note that you need to have a validconfig/file_convert.ymlpresent 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 test as well.)
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using the ways described above.
Next Steps
- Enable OCR if necessary when uploading files
- Add CLI
- Add different adapter than Google?
License
file-convert is Copyright © 2014 Roman Ernst and tolingo GmbH and may be redistributed under the terms specified in the LICENSE file.