lib/cloud_convert/process.rb in cloudconvert-ruby-0.1.8 vs lib/cloud_convert/process.rb in cloudconvert-ruby-0.1.9
- old
+ new
@@ -22,44 +22,56 @@
@client = args[:client]
end
def create
raise CloudConvert::InvalidStep unless @step == :awaiting_creation
- url = construct_url("api", "process")
+ url = construct_url("process")
response = send_request(http_method: :post,
url: url,
params: {
"apikey" => @client.api_key,
"inputformat" => @input_format,
"outputformat" => @output_format
}) do | response|
@step = :awaiting_conversion
response.parsed_response[:success] = true
create_parsed_response(:process_response, response.parsed_response)
- @process_response[:subdomain] = extract_subdomain_from_url(@process_response[:url])
end
return convert_response response
end
def convert(opts)
raise CloudConvert::InvalidStep if @step == :awaiting_creation
- url = process_url(include_process_id: true)
- multi = opts[:file].respond_to?("read")
+ url = process_url()
+ if opts[:file].respond_to?("read")
+ file_to_upload = opts[:file]
+ opts.delete(:file)
+ end
response = send_request(http_method: :post,
url: url,
params: opts,
- multi: multi) do |response|
+ multi: false) do |response|
response.parsed_response[:success] = true
create_parsed_response(:conversion_response, response.parsed_response)
@step = @conversion_response[:step].to_sym
+
+ if(file_to_upload)
+ send_request(http_method: :post,
+ url: "#{CloudConvert::PROTOCOL}:#{@conversion_response[:upload][:url]}",
+ params: {
+ "file": file_to_upload
+ },
+ multi: true)
+ end
+
end
return convert_response response
end
def status
raise CloudConvert::InvalidStep if @step == :awaiting_creation
- url = process_url(include_process_id: true)
+ url = process_url()
response = send_request(http_method: :get,
url: url) do |response|
create_parsed_response(:status_response, response.parsed_response)
@step = @status_response[:step].to_sym
end
@@ -88,11 +100,11 @@
end
def download_url(file = "")
raise CloudConvert::InvalidStep if @step == :awaiting_creation
file = "/#{file}" unless file.nil? or file.strip.empty?
- return "https://#{@process_response[:subdomain]}.cloudconvert.com/download/#{@process_response[:id]}#{file}"
+ return "#{CloudConvert::PROTOCOL}:#{@conversion_response[:output][:url]}#{file}"
end
private
@@ -103,28 +115,24 @@
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
- def construct_url(subdomain, action, id="")
- id = "/#{id}" if id.length > 0
- return "#{CloudConvert::PROTOCOL}://#{subdomain}.#{CloudConvert::DOMAIN}/#{action}#{id}"
+ def construct_url(action, id="")
+ id = "/#{id}" if id.length > 0
+ return "#{CloudConvert::PROTOCOL}://#{CloudConvert::API_DOMAIN}/#{action}#{id}"
end
- def process_url(opts = {})
- action = (opts[:include_process_id] ? "process/#{@process_response[:id]}" : "process")
- return construct_url(@process_response[:subdomain], action)
+ def process_url()
+ return "#{CloudConvert::PROTOCOL}:#{@process_response[:url]}"
end
def create_parsed_response(variable_symbol, parsed_response)
symbolized_response = parsed_response.deep_symbolize
return self.instance_variable_set("@#{variable_symbol.to_s}", symbolized_response)
end
- def extract_subdomain_from_url(url)
- return url.split(".")[0].tr('/','')
- end
def convert_response(response)
case @client.return_type
when :response
return response.response