Class: CloudConvert::Process
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#conversion_response ⇒ Object
readonly
Returns the value of attribute conversion_response.
-
#download_url(file = "") ⇒ Object
readonly
Returns the value of attribute download_url.
-
#input_format ⇒ Object
readonly
Returns the value of attribute input_format.
-
#output_format ⇒ Object
readonly
Returns the value of attribute output_format.
-
#process_response ⇒ Object
readonly
Returns the value of attribute process_response.
-
#status_response ⇒ Object
readonly
Returns the value of attribute status_response.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
Instance Method Summary collapse
- #convert(opts) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #download(path, file_name = "") ⇒ Object
-
#initialize(args = {}) ⇒ Process
constructor
A new instance of Process.
- #status ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Process
Returns a new instance of Process.
18 19 20 21 22 23 |
# File 'lib/cloud_convert/process.rb', line 18 def initialize(args = {}) @input_format = args[:input_format] @output_format = args[:output_format] @step = :awaiting_creation @client = args[:client] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def client @client end |
#conversion_response ⇒ Object (readonly)
Returns the value of attribute conversion_response.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def conversion_response @conversion_response end |
#download_url(file = "") ⇒ Object (readonly)
Returns the value of attribute download_url.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def download_url @download_url end |
#input_format ⇒ Object (readonly)
Returns the value of attribute input_format.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def input_format @input_format end |
#output_format ⇒ Object (readonly)
Returns the value of attribute output_format.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def output_format @output_format end |
#process_response ⇒ Object (readonly)
Returns the value of attribute process_response.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def process_response @process_response end |
#status_response ⇒ Object (readonly)
Returns the value of attribute status_response.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def status_response @status_response end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
7 8 9 |
# File 'lib/cloud_convert/process.rb', line 7 def step @step end |
Instance Method Details
#convert(opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cloud_convert/process.rb', line 43 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, params: opts, multi: multi) do |response| response.parsed_response[:success] = true create_parsed_response(:conversion_response, response.parsed_response) @step = @conversion_response[:step].to_sym end return convert_response response end |
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloud_convert/process.rb', line 25 def create raise CloudConvert::InvalidStep unless @step == :awaiting_creation url = construct_url("api", "process") response = send_request(http_method: :post, url: url, params: { "apikey" => @client.api_key, "inputformat" => @input_format, "outputformat" => @outputformat }) 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 |
#delete ⇒ Object
80 81 82 83 84 85 |
# File 'lib/cloud_convert/process.rb', line 80 def delete url = construct_url(process_response[:subdomain], "process", process_response[:id]) response = HTTMultiParty.delete(url) @step = :deleted if response.response.code == "200" return convert_response response end |
#download(path, file_name = "") ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cloud_convert/process.rb', line 68 def download(path, file_name="") 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| f.binmode f.write response.parsed_response full_path.to_s end end |
#status ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/cloud_convert/process.rb', line 58 def status url = process_url(include_process_id: true) 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 return convert_response response end |