@@ -3,33 +3,38 @@ class Task
33    def  initialize ( from_format ,  to_format ,  params ,  conversion_timeout : nil ) 
44      @from_format  =  from_format 
55      @to_format  =  to_format 
6-       @params  =  params 
76      @conversion_timeout  =  conversion_timeout  || config . conversion_timeout 
8-     end 
9- 
10-     def  run 
11-       params  =  normalize_params ( @params ) . merge ( 
7+       @params  =  normalize_params ( params ) . merge ( 
128        Timeout : @conversion_timeout , 
139        StoreFile : true , 
1410      ) 
11+       @async  =  @params . delete ( :Async ) 
12+     end 
1513
14+     def  run 
1615      read_timeout  =  @conversion_timeout  + config . conversion_timeout_delta  if  @conversion_timeout 
1716
1817      response  =  ConvertApi . client . post ( 
19-         request_path ( params ) , 
20-         params , 
18+         request_path , 
19+         @ params, 
2120        read_timeout : read_timeout , 
2221      ) 
2322
23+       return  AsyncResult . new ( response )  if  async? 
24+ 
2425      Result . new ( response ) 
2526    end 
2627
2728    private 
2829
29-     def  request_path ( params ) 
30-       from_format  =  @from_format  || detect_format ( params ) 
31-       converter  =  params [ :converter ]  ? "/converter/#{ params [ :converter ] }   : '' 
32-       async  =  params [ :Async ]  ? 'async/'  : '' 
30+     def  async? 
31+       !!@async 
32+     end 
33+ 
34+     def  request_path 
35+       from_format  =  @from_format  || detect_format 
36+       converter  =  @params [ :converter ]  ? "/converter/#{ @params [ :converter ] }   : '' 
37+       async  =  async?  ? 'async/'  : '' 
3338
3439      "#{ async } #{ from_format } #{ @to_format } #{ converter }  
3540    end 
@@ -67,10 +72,10 @@ def files_batch(values)
6772      files 
6873    end 
6974
70-     def  detect_format ( params ) 
71-       return  DEFAULT_URL_FORMAT  if  params [ :Url ] 
75+     def  detect_format 
76+       return  DEFAULT_URL_FORMAT  if  @ params[ :Url ] 
7277
73-       resource  =  params [ :File ]  || Array ( params [ :Files ] ) . first 
78+       resource  =  @ params[ :File ]  || Array ( @ params[ :Files ] ) . first 
7479
7580      FormatDetector . new ( resource ,  @to_format ) . run 
7681    end 
0 commit comments