cloudconvert-ruby 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +4 -4
 - data/lib/cloud_convert/client.rb +1 -1
 - data/lib/cloud_convert/exceptions.rb +2 -2
 - data/lib/cloud_convert/process.rb +24 -16
 - data/lib/cloud_convert/version.rb +1 -1
 - data/lib/cloudconvert-ruby.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f55415d6ade196eae24ad851254e7590fac23fb5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 92a6bba134f98c32af7d6ebaaa7ed360226240d9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 45420245a687159591c3f6e72faa7c9d88dd39edbae4f7e9066ae685f701106e30eb9944b954b51ec19223b6bc4d7dc50eeb0218c70b05fbfb9516f4bc085256
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8881389fcfb8d6588b130ed22ea2d0aa046c2febe022005d358d896392af2fe960b52c267300ea7acc6c282fa0d3f1ca1593cc7acbe0be65819ea064958944c1
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -20,12 +20,12 @@ And then execute: 
     | 
|
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
            ```ruby
         
     | 
| 
       22 
22 
     | 
    
         
             
            @client = CloudConvert::Client.new(api_key: "Your API Key")
         
     | 
| 
       23 
     | 
    
         
            -
            @process = @client.build_process(input_format:  
     | 
| 
      
 23 
     | 
    
         
            +
            @process = @client.build_process(input_format: :jpg, output_format: :pdf)
         
     | 
| 
       24 
24 
     | 
    
         
             
            @process_response = @process.create
         
     | 
| 
       25 
25 
     | 
    
         
             
            if @process_response[:success]
         
     | 
| 
       26 
26 
     | 
    
         
             
                @conversion_response = @process.convert(
         
     | 
| 
       27 
27 
     | 
    
         
             
                    input: "download",
         
     | 
| 
       28 
     | 
    
         
            -
                    outputformat:  
     | 
| 
      
 28 
     | 
    
         
            +
                    outputformat: :pdf,
         
     | 
| 
       29 
29 
     | 
    
         
             
                    file: "link to image",
         
     | 
| 
       30 
30 
     | 
    
         
             
                    download: "false"
         
     | 
| 
       31 
31 
     | 
    
         
             
                )
         
     | 
| 
         @@ -48,7 +48,7 @@ Once the client object is created, we can build a process for our conversion. In 
     | 
|
| 
       48 
48 
     | 
    
         
             
            Note: You can build as many processes as you want, just make sure that you are aware of any limitations placed on your account by Cloud Convert before you start converting files.
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
            ```ruby
         
     | 
| 
       51 
     | 
    
         
            -
            @process = @client.build_process(input_format:  
     | 
| 
      
 51 
     | 
    
         
            +
            @process = @client.build_process(input_format: :jpg, output_format: :pdf)
         
     | 
| 
       52 
52 
     | 
    
         
             
            ```
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
            We now need to tell Cloud Convert that we are creating a process. To do this, we will use the `create` method.
         
     | 
| 
         @@ -66,7 +66,7 @@ To start a conversion, you can execute the `convert` method. For all the paramet 
     | 
|
| 
       66 
66 
     | 
    
         
             
            ```ruby
         
     | 
| 
       67 
67 
     | 
    
         
             
            @conversion_response = @process.convert(
         
     | 
| 
       68 
68 
     | 
    
         
             
                      input: "download",
         
     | 
| 
       69 
     | 
    
         
            -
                      outputformat:  
     | 
| 
      
 69 
     | 
    
         
            +
                      outputformat: :pdf,
         
     | 
| 
       70 
70 
     | 
    
         
             
                      file: "link to image",
         
     | 
| 
       71 
71 
     | 
    
         
             
                      download: "false"
         
     | 
| 
       72 
72 
     | 
    
         
             
                    )
         
     | 
    
        data/lib/cloud_convert/client.rb
    CHANGED
    
    | 
         @@ -41,7 +41,7 @@ module CloudConvert 
     | 
|
| 
       41 
41 
     | 
    
         
             
                ##
         
     | 
| 
       42 
42 
     | 
    
         
             
                # Returns an array of hash with the results from the Cloud Convert list endpoint.
         
     | 
| 
       43 
43 
     | 
    
         
             
                def list
         
     | 
| 
       44 
     | 
    
         
            -
                    url = "#{CloudConvert::PROTOCOL} 
     | 
| 
      
 44 
     | 
    
         
            +
                    url = "#{CloudConvert::PROTOCOL}://#{CloudConvert::API_DOMAIN}/processes"
         
     | 
| 
       45 
45 
     | 
    
         
             
                    response = CloudConvert::Client.send(:get, url, {query: {apikey: self.api_key}})
         
     | 
| 
       46 
46 
     | 
    
         
             
                    return convert_response response
         
     | 
| 
       47 
47 
     | 
    
         
             
                end  
         
     | 
| 
         @@ -24,7 +24,7 @@ module CloudConvert 
     | 
|
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                def create
         
     | 
| 
       26 
26 
     | 
    
         
             
                    raise CloudConvert::InvalidStep unless @step == :awaiting_creation
         
     | 
| 
       27 
     | 
    
         
            -
                    url = construct_url(" 
     | 
| 
      
 27 
     | 
    
         
            +
                    url = construct_url("process")
         
     | 
| 
       28 
28 
     | 
    
         
             
                    response = send_request(http_method: :post, 
         
     | 
| 
       29 
29 
     | 
    
         
             
                                            url: url, 
         
     | 
| 
       30 
30 
     | 
    
         
             
                                            params: {
         
     | 
| 
         @@ -35,29 +35,41 @@ module CloudConvert 
     | 
|
| 
       35 
35 
     | 
    
         
             
                        @step = :awaiting_conversion
         
     | 
| 
       36 
36 
     | 
    
         
             
                        response.parsed_response[:success] = true
         
     | 
| 
       37 
37 
     | 
    
         
             
                        create_parsed_response(:process_response, response.parsed_response)
         
     | 
| 
       38 
     | 
    
         
            -
                        @process_response[:subdomain] = extract_subdomain_from_url(@process_response[:url])
         
     | 
| 
       39 
38 
     | 
    
         
             
                    end
         
     | 
| 
       40 
39 
     | 
    
         
             
                    return convert_response response
         
     | 
| 
       41 
40 
     | 
    
         
             
                end
         
     | 
| 
       42 
41 
     | 
    
         | 
| 
       43 
42 
     | 
    
         
             
                def convert(opts)
         
     | 
| 
       44 
43 
     | 
    
         
             
                    raise CloudConvert::InvalidStep if @step == :awaiting_creation
         
     | 
| 
       45 
     | 
    
         
            -
                    url = process_url( 
     | 
| 
       46 
     | 
    
         
            -
                     
     | 
| 
      
 44 
     | 
    
         
            +
                    url = process_url()
         
     | 
| 
      
 45 
     | 
    
         
            +
                    if opts[:file].respond_to?("read")
         
     | 
| 
      
 46 
     | 
    
         
            +
                      file_to_upload = opts[:file]
         
     | 
| 
      
 47 
     | 
    
         
            +
                      opts.delete(:file)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
       47 
49 
     | 
    
         
             
                    response = send_request(http_method: :post, 
         
     | 
| 
       48 
50 
     | 
    
         
             
                                            url: url, 
         
     | 
| 
       49 
51 
     | 
    
         
             
                                            params: opts,
         
     | 
| 
       50 
     | 
    
         
            -
                                            multi:  
     | 
| 
      
 52 
     | 
    
         
            +
                                            multi: false) do |response|
         
     | 
| 
       51 
53 
     | 
    
         
             
                        response.parsed_response[:success] = true
         
     | 
| 
       52 
54 
     | 
    
         
             
                        create_parsed_response(:conversion_response, response.parsed_response)
         
     | 
| 
       53 
55 
     | 
    
         
             
                        @step = @conversion_response[:step].to_sym
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                        if(file_to_upload)
         
     | 
| 
      
 58 
     | 
    
         
            +
                          send_request(http_method: :post,
         
     | 
| 
      
 59 
     | 
    
         
            +
                                       url: "#{CloudConvert::PROTOCOL}:#{@conversion_response[:upload][:url]}",
         
     | 
| 
      
 60 
     | 
    
         
            +
                                       params: {
         
     | 
| 
      
 61 
     | 
    
         
            +
                                           "file": file_to_upload
         
     | 
| 
      
 62 
     | 
    
         
            +
                                       },
         
     | 
| 
      
 63 
     | 
    
         
            +
                                       multi: true)
         
     | 
| 
      
 64 
     | 
    
         
            +
                        end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
       54 
66 
     | 
    
         
             
                    end
         
     | 
| 
       55 
67 
     | 
    
         
             
                    return convert_response response
         
     | 
| 
       56 
68 
     | 
    
         
             
                end
         
     | 
| 
       57 
69 
     | 
    
         | 
| 
       58 
70 
     | 
    
         
             
                def status
         
     | 
| 
       59 
71 
     | 
    
         
             
                    raise CloudConvert::InvalidStep if @step == :awaiting_creation
         
     | 
| 
       60 
     | 
    
         
            -
                    url = process_url( 
     | 
| 
      
 72 
     | 
    
         
            +
                    url = process_url()
         
     | 
| 
       61 
73 
     | 
    
         
             
                    response = send_request(http_method: :get,
         
     | 
| 
       62 
74 
     | 
    
         
             
                                            url: url) do |response|
         
     | 
| 
       63 
75 
     | 
    
         
             
                        create_parsed_response(:status_response, response.parsed_response)
         
     | 
| 
         @@ -90,7 +102,7 @@ module CloudConvert 
     | 
|
| 
       90 
102 
     | 
    
         
             
                def download_url(file = "")
         
     | 
| 
       91 
103 
     | 
    
         
             
                    raise CloudConvert::InvalidStep if @step == :awaiting_creation
         
     | 
| 
       92 
104 
     | 
    
         
             
                    file = "/#{file}" unless file.nil? or file.strip.empty?
         
     | 
| 
       93 
     | 
    
         
            -
                    return " 
     | 
| 
      
 105 
     | 
    
         
            +
                    return "#{CloudConvert::PROTOCOL}:#{@conversion_response[:output][:url]}#{file}"
         
     | 
| 
       94 
106 
     | 
    
         
             
                end
         
     | 
| 
       95 
107 
     | 
    
         | 
| 
       96 
108 
     | 
    
         | 
| 
         @@ -105,14 +117,13 @@ module CloudConvert 
     | 
|
| 
       105 
117 
     | 
    
         
             
                    return response
         
     | 
| 
       106 
118 
     | 
    
         
             
                end
         
     | 
| 
       107 
119 
     | 
    
         | 
| 
       108 
     | 
    
         
            -
                def construct_url( 
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
                def construct_url(action, id="")
         
     | 
| 
      
 121 
     | 
    
         
            +
                  id = "/#{id}" if id.length > 0
         
     | 
| 
      
 122 
     | 
    
         
            +
                  return "#{CloudConvert::PROTOCOL}://#{CloudConvert::API_DOMAIN}/#{action}#{id}"
         
     | 
| 
       111 
123 
     | 
    
         
             
                end
         
     | 
| 
       112 
124 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
                def process_url( 
     | 
| 
       114 
     | 
    
         
            -
                     
     | 
| 
       115 
     | 
    
         
            -
                    return construct_url(@process_response[:subdomain], action)
         
     | 
| 
      
 125 
     | 
    
         
            +
                def process_url()
         
     | 
| 
      
 126 
     | 
    
         
            +
                    return "#{CloudConvert::PROTOCOL}:#{@process_response[:url]}"
         
     | 
| 
       116 
127 
     | 
    
         
             
                end
         
     | 
| 
       117 
128 
     | 
    
         | 
| 
       118 
129 
     | 
    
         | 
| 
         @@ -121,9 +132,6 @@ module CloudConvert 
     | 
|
| 
       121 
132 
     | 
    
         
             
                    return self.instance_variable_set("@#{variable_symbol.to_s}", symbolized_response)
         
     | 
| 
       122 
133 
     | 
    
         
             
                end
         
     | 
| 
       123 
134 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
                def extract_subdomain_from_url(url)
         
     | 
| 
       125 
     | 
    
         
            -
                    return url.split(".")[0].tr('/','')
         
     | 
| 
       126 
     | 
    
         
            -
                end
         
     | 
| 
       127 
135 
     | 
    
         | 
| 
       128 
136 
     | 
    
         
             
                def convert_response(response)
         
     | 
| 
       129 
137 
     | 
    
         
             
                    case @client.return_type
         
     | 
    
        data/lib/cloudconvert-ruby.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cloudconvert-ruby
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.9
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Edwin Velasquez
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-07-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |