Class: ConvertApi::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/convert_api/task.rb

Instance Method Summary collapse

Constructor Details

#initialize(from_format, to_format, params, conversion_timeout: nil) ⇒ Task

Returns a new instance of Task.



3
4
5
6
7
8
# File 'lib/convert_api/task.rb', line 3

def initialize(from_format, to_format, params, conversion_timeout: nil)
  @from_format = from_format
  @to_format = to_format
  @params = params
  @conversion_timeout = conversion_timeout || config.conversion_timeout
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/convert_api/task.rb', line 10

def run
  params = normalize_params(@params).merge(
    Timeout: @conversion_timeout,
    StoreFile: true,
  )

  from_format = @from_format || detect_format(params)
  read_timeout = @conversion_timeout + config.conversion_timeout_delta if @conversion_timeout

  response = ConvertApi.client.post(
    "convert/#{from_format}/to/#{@to_format}",
    params,
    read_timeout: read_timeout,
  )

  Result.new(response)
end