cloudconvert-ruby 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e87726c769907828cc989d6b3b54aff32cec743
4
- data.tar.gz: 759538325d05443155f2455cef3a3b23b735308d
3
+ metadata.gz: f55415d6ade196eae24ad851254e7590fac23fb5
4
+ data.tar.gz: 92a6bba134f98c32af7d6ebaaa7ed360226240d9
5
5
  SHA512:
6
- metadata.gz: f2d764f221f9de63b3938ad817646a233752b05e75764003d9a14235287c744e7944e48d9a07bdf411b3ddabfbd8420c9b5f59d99b031b2989f3392b8611e39c
7
- data.tar.gz: cc644015cbdf9fc62b499ae72ee8d35298f99bea2f73f02595900112ef7519603a6e7e205fdcf2996c5fcd64bb3b4a218f39a447a32708039d3fb0b306cf6e52
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: "jpg", output_format: "pdf")
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: "pdf",
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: "jpg", output_format: "pdf")
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: "pdf",
69
+ outputformat: :pdf,
70
70
  file: "link to image",
71
71
  download: "false"
72
72
  )
@@ -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}://api.#{CloudConvert::DOMAIN}/processes"
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
@@ -1,4 +1,4 @@
1
1
  module CloudConvert
2
- class InvalidStep < Exception
2
+ class InvalidStep < StandardError
3
3
  end
4
- end
4
+ 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("api", "process")
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(include_process_id: true)
46
- multi = opts[:file].respond_to?("read")
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: multi) do |response|
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(include_process_id: true)
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 "https://#{@process_response[:subdomain]}.cloudconvert.com/download/#{@process_response[:id]}#{file}"
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(subdomain, action, id="")
109
- id = "/#{id}" if id.length > 0
110
- return "#{CloudConvert::PROTOCOL}://#{subdomain}.#{CloudConvert::DOMAIN}/#{action}#{id}"
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(opts = {})
114
- action = (opts[:include_process_id] ? "process/#{@process_response[:id]}" : "process")
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
@@ -2,7 +2,7 @@ module CloudConvert
2
2
  module VERSION_VALUES #:nodoc:
3
3
  MAJOR = '0'
4
4
  MINOR = '1'
5
- TINY = '8'
5
+ TINY = '9'
6
6
  BETA = nil # Time.now.to_i.to_s
7
7
  end
8
8
 
@@ -10,5 +10,5 @@ require "cloud_convert/lib/deep_symbolize"
10
10
  module CloudConvert
11
11
  # Your code goes here...
12
12
  PROTOCOL = "https"
13
- DOMAIN = "cloudconvert.com"
13
+ API_DOMAIN = "api.cloudconvert.com"
14
14
  end
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.8
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: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler