cloudconvert 1.0.2 → 1.1.0

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
  SHA256:
3
- metadata.gz: f6dde202d9202295f93e2614fb19358b5c1f97a12679e51da3b837de71c68bcc
4
- data.tar.gz: 99ec57ec28509a9a3f1231de3a74b09687185e7b3d4972365b6c655d4c43b243
3
+ metadata.gz: f05a16c577e0b30ddf30f9e73a087e1b79d40570f11b5a6013d98d9c372494c0
4
+ data.tar.gz: 7252a59fffb66d0797a04014251a3825a976a3470c8ca0d1adcd10865950512f
5
5
  SHA512:
6
- metadata.gz: 6fef45ad6dc438ac6e7ac8efb99a3592180d95b01aafc02f1e19ae34029607894c41ffa16325e85a3612a84c361ba5cde0703c4859330b71ae983aaeeaa894af
7
- data.tar.gz: 1239105391c68e937fa414c6224dc54ce838725d4108e9ecc2380bddfa90acb881592338a444fa6dde11957fe07523be1170a2886f28bf016f7252f387fae77e
6
+ metadata.gz: bf3531174c00eb2b7ea64fac80e91a40a497ffdaed32f834fd9edb497b6fadf4514a6a6ada0e50fdd0e1d7e83f763d982408e4e883b9625bfcfcdda1bf2c3ead
7
+ data.tar.gz: a9a5b932ebf1eee1ada6a1d779bdf73ee6e1572fcaccfb2430496746d2ed8c83b8798e7e38fd61dea16b3a356d9391f05379a8d5137965d7281f5aed23690f3d
data/README.md CHANGED
@@ -207,6 +207,26 @@ The `verify`/`verify_request` methods return `true`/`false`, use `verify!` or `v
207
207
  You can read the [full list of events](https://cloudconvert.com/api/v2/webhooks) CloudConvert can notify you about in our documentation.
208
208
 
209
209
 
210
+ Signed URL
211
+ --------
212
+
213
+ Signed URLs allow converting files on demand only using URL query parameters. The Ruby SDK allows to generate such URLs. Therefore, you need to obtain a signed URL base and a signing secret on the [CloudConvert Dashboard](https://cloudconvert.com/dashboard/api/v2/signed-urls).
214
+
215
+ ```rb
216
+ base = 'https://s.cloudconvert.com/...' # You can find it in your signed URL settings.
217
+ signing_secret = '...' # You can find it in your signed URL settings.
218
+ cache_key = 'cache-key' # Allows caching of the result file for 24h
219
+
220
+ job = {
221
+ tasks: {
222
+ "import-it": { operation: "import/url", filename: "test.file", url: "http://invalid.url" },
223
+ "convert-it": { input: "import-it", operation: "convert", output_format: "pdf" },
224
+ }
225
+ }
226
+
227
+ url = CloudConvert::SignedUrl.sign(base, signing_secret, job, cache_key)
228
+ ```
229
+
210
230
  Development
211
231
  -----------
212
232
 
@@ -75,13 +75,18 @@ module CloudConvert
75
75
  Down.download(url, *args, **options)
76
76
  end
77
77
 
78
- private
79
-
80
78
  # @return [String]
81
79
  def api_host
82
80
  @api_host ||= sandbox ? SANDBOX_URL : API_URL
83
81
  end
84
82
 
83
+ # @return [String]
84
+ def api_sync_host
85
+ @api_sync_host ||= sandbox ? SANDBOX_SYNC_URL : API_SYNC_URL
86
+ end
87
+
88
+ private
89
+
85
90
  # @return [Faraday::Client]
86
91
  def connection
87
92
  @connection ||= Faraday.new(url: api_host, headers: headers) do |f|
@@ -41,7 +41,7 @@ module CloudConvert
41
41
  # @param id [String]
42
42
  # @return [Job]
43
43
  def wait(id)
44
- Job.result(client.get("/v2/jobs/#{id}/wait", {}))
44
+ Job.result(client.get(client.api_sync_host + "/v2/jobs/#{id}", {}))
45
45
  end
46
46
 
47
47
  # @param id [String]
@@ -51,7 +51,7 @@ module CloudConvert
51
51
  # @param id [String]
52
52
  # @return [Task]
53
53
  def wait(id)
54
- Task.result(client.get("/v2/tasks/#{id}/wait"))
54
+ Task.result(client.get(client.api_sync_host + "/v2/tasks/#{id}"))
55
55
  end
56
56
 
57
57
  # @param file [File, String, IO] Either a String filename to a local file or an open IO object.
@@ -0,0 +1,24 @@
1
+ module CloudConvert
2
+ class SignedUrl
3
+ class << self
4
+ # @param base [String] The base from for your signed URL settings.
5
+ # @param signing_secret [String] The signing secret from for your signed URL settings.
6
+ # @param job [Hash] The job to create the signed URL for
7
+ # @param cache_key [String] Allows caching of the result file for 24h
8
+ # @return [String] The signed URL
9
+ def sign(base, signing_secret, job, cache_key = nil)
10
+ url = base
11
+
12
+ url += "?job=" + Base64.urlsafe_encode64(job.to_json, padding: false)
13
+
14
+ unless cache_key.nil?
15
+ url += "&cache_key=" + cache_key
16
+ end
17
+
18
+ url += "&s=" + OpenSSL::HMAC.hexdigest("SHA256", signing_secret, url)
19
+
20
+ url
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module CloudConvert
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/cloudconvert.rb CHANGED
@@ -30,9 +30,12 @@ require "cloudconvert/user"
30
30
  require "cloudconvert/version"
31
31
  require "cloudconvert/webhook"
32
32
  require "cloudconvert/webhook/processor"
33
+ require "cloudconvert/signed_url"
33
34
 
34
35
  module CloudConvert
35
36
  API_URL = "https://api.cloudconvert.com".freeze
36
37
  SANDBOX_URL = "https://api.sandbox.cloudconvert.com".freeze
38
+ API_SYNC_URL = "https://sync.api.cloudconvert.com".freeze
39
+ SANDBOX_SYNC_URL = "https://sync.api.sandbox.cloudconvert.com".freeze
37
40
  USER_AGENT = "CloudConvertRubyGem/#{CloudConvert::VERSION}".freeze
38
41
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudconvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josias Montag
8
8
  - Steve Lacey
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-29 00:00:00.000000000 Z
12
+ date: 2022-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -358,6 +358,7 @@ files:
358
358
  - lib/cloudconvert/resources/jobs.rb
359
359
  - lib/cloudconvert/resources/tasks.rb
360
360
  - lib/cloudconvert/resources/users.rb
361
+ - lib/cloudconvert/signed_url.rb
361
362
  - lib/cloudconvert/task.rb
362
363
  - lib/cloudconvert/user.rb
363
364
  - lib/cloudconvert/version.rb
@@ -370,7 +371,7 @@ metadata:
370
371
  bug_tracker_uri: https://github.com/cloudconvert/cloudconvert-ruby/issues
371
372
  documentation_uri: https://cloudconvert.com/api/v2
372
373
  source_code_uri: https://github.com/cloudconvert/cloudconvert-ruby
373
- post_install_message:
374
+ post_install_message:
374
375
  rdoc_options: []
375
376
  require_paths:
376
377
  - lib
@@ -385,8 +386,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
386
  - !ruby/object:Gem::Version
386
387
  version: '0'
387
388
  requirements: []
388
- rubygems_version: 3.2.15
389
- signing_key:
389
+ rubygems_version: 3.0.3.1
390
+ signing_key:
390
391
  specification_version: 4
391
392
  summary: A Ruby interface to the CloudConvert API v2.
392
393
  test_files: []