From a5b7f2d9acab1e87d49b46701991f44e5826174a Mon Sep 17 00:00:00 2001 From: Pedro F Steimbruch Date: Thu, 9 Nov 2017 13:28:44 -0200 Subject: [PATCH 1/2] adding mode option when creating a process --- lib/cloud_convert/process.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/cloud_convert/process.rb b/lib/cloud_convert/process.rb index 8bf7daa..fb2d4b2 100644 --- a/lib/cloud_convert/process.rb +++ b/lib/cloud_convert/process.rb @@ -22,15 +22,16 @@ def initialize(args = {}) @client = args[:client] end - def create + def create mode = 'convert' raise CloudConvert::InvalidStep unless @step == :awaiting_creation url = construct_url("api", "process") - response = send_request(http_method: :post, - url: url, + response = send_request(http_method: :post, + url: url, params: { "apikey" => @client.api_key, "inputformat" => @input_format, - "outputformat" => @output_format + "outputformat" => @output_format, + "mode" => mode }) do | response| @step = :awaiting_conversion response.parsed_response[:success] = true @@ -44,8 +45,8 @@ def convert(opts) raise CloudConvert::InvalidStep if @step == :awaiting_creation url = process_url(include_process_id: true) multi = opts[:file].respond_to?("read") - response = send_request(http_method: :post, - url: url, + response = send_request(http_method: :post, + url: url, params: opts, multi: multi) do |response| response.parsed_response[:success] = true @@ -66,13 +67,13 @@ def status return convert_response response end - def download(path, file_name="") + def download(path, file_name="") raise CloudConvert::InvalidStep if @step == :awaiting_creation response = HTTMultiParty.get(download_url(file_name)) return update_download_progress response unless response.response.code == "200" file_name = response.response.header['content-disposition'][/filename=(\"?)(.+)\1/, 2] if file_name.strip.empty? full_path = full_path(path, file_name) - return full_path.open("w") do |f| + return full_path.open("w") do |f| f.binmode f.write response.parsed_response full_path.to_s @@ -93,14 +94,14 @@ def download_url(file = "") return "https://#{@process_response[:subdomain]}.cloudconvert.com/download/#{@process_response[:id]}#{file}" end - + private def send_request(opts) request = opts[:params] || {} args = [opts[:http_method], opts[:url], {query: request, detect_mime_type: (true if opts[:multi])}] response = CloudConvert::Client.send(*args) - yield(response) if block_given? and (response.response.code == "200" || + yield(response) if block_given? and (response.response.code == "200" || (response.parsed_response.kind_of?(Hash) and response.parsed_response.key?("step"))) return response end From 7a70dc6949fc042e89357019a4c9f794c8a2f484 Mon Sep 17 00:00:00 2001 From: Pedro F Steimbruch Date: Thu, 9 Nov 2017 14:18:44 -0200 Subject: [PATCH 2/2] trying to fix the request for info mode --- lib/cloud_convert/process.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/cloud_convert/process.rb b/lib/cloud_convert/process.rb index fb2d4b2..cd246ca 100644 --- a/lib/cloud_convert/process.rb +++ b/lib/cloud_convert/process.rb @@ -25,14 +25,20 @@ def initialize(args = {}) def create mode = 'convert' raise CloudConvert::InvalidStep unless @step == :awaiting_creation url = construct_url("api", "process") + + params = { "apikey" => @client.api_key, + "inputformat" => @input_format, + "outputformat" => @output_format, + "mode" => mode } + + if mode == 'info' + params.delete(:outputformat) + params.merge!(wait: true, download: false) + end + response = send_request(http_method: :post, url: url, - params: { - "apikey" => @client.api_key, - "inputformat" => @input_format, - "outputformat" => @output_format, - "mode" => mode - }) do | response| + params: params) do | response| @step = :awaiting_conversion response.parsed_response[:success] = true create_parsed_response(:process_response, response.parsed_response)