Fileturn

Ruby Gem Support for FileTurn Api. FileTurn converts your files to different formats.

Api Docs

Check out our api docs for more information.

Installation

Add this line to your application's Gemfile:

gem 'fileturn'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fileturn

Configuration

Retrieve your API Token from Dashboard.

FileTurn.configure(:api_token => "[YOUR KEY]")

Thats it - now you are ready to use FileTurn.

Usage

Converting your files

There are multiple ways to convert a file. If your file is public, we can fetch the file and you just need to specify the url.

conversion = FileTurn::Conversion.process!(
    :url => "http://crypto.stanford.edu/DRM2002/darknet5.doc",
    :type => "WordToPdf"
)

If your file is stored locally, you can use

file = FileTurn::Conversion.process!(
    :file => File.open("localfile.doc"),
    :type => "WordToPdf"
)

Thats all you have to do to convert files. Upon calling that, your file will be queued for converting. If there is an error queuing your file, an exception with base class of FileTurn::FileTurnError will be thrown.

Working with errors:

begin
    file = FileTurn::Conversion.process!(
        :file => File.open("localfile.doc"),
        :type => "WordToPdf"
    )
rescue FileTurn::FileTurnError => ex
    # conversion queueing failed 
end

How will i know when my conversion is done?

Conversion Object

There are few ways to check if your file is done. You can repeatedly call one of these:

conversion.reload!.completed? 
conversion.reload!.failed?
conversion.reload!.processing?
conversion.reload!.created?

When your conversion is done, the conversion object will have temporary download urls.

if conversion.completed?
    download_url = conversion.temporary_download_urls
    time_taken_for_conversion = conversion.processing_time_in_seconds
end

In the case you get a failure, you can retrieve the details using

conversion.error_type
conversion.error_details

Notifications

You can also request notification to be sent to you whenever the status of a conversion changes via webhooks. Go into your Dashboard and specify a webhook url.

Fetching Conversion(s)

You can fetch information of a single conversion using an id.

FileTurn::Conversion.find(id)

Or all the conversions

FileTurn::Conversion.all

Account Details

You can fetch account details

 = FileTurn::Account.load # fetch data from server

# plan details
.plan.name
.plan.max_file_size_in_mb
.plan.conversions_per_month
.plan.max_requests_per_second

# stats for account (for current billing cycle)
.subscription.stats.conversions_left
.subscription.stats.successful_conversions
.subscription.stats.failed_conversions
.subscription.stats.processing_conversions