cloudconvert 1.0.2 → 1.1.1

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: c673e3ee8e95029ba169554f076d54a63ccafeb2935708da8882babddba6f2dd
4
+ data.tar.gz: cae666dc7dda6a117cf0f81ba40086e35c135b63e478972aa082eabd631ae6c4
5
5
  SHA512:
6
- metadata.gz: 6fef45ad6dc438ac6e7ac8efb99a3592180d95b01aafc02f1e19ae34029607894c41ffa16325e85a3612a84c361ba5cde0703c4859330b71ae983aaeeaa894af
7
- data.tar.gz: 1239105391c68e937fa414c6224dc54ce838725d4108e9ecc2380bddfa90acb881592338a444fa6dde11957fe07523be1170a2886f28bf016f7252f387fae77e
6
+ metadata.gz: d571515f826da72d7334981057c0d4cf987d5c34abf05353ad5479a3e10a3554f3ff76ea040f6841bda769400b076be9a1aed07435197d516e26aa0a0b226508
7
+ data.tar.gz: fb6262513b578d91d6c65a1ba8bbe40e149b051ba684458fb025e81e07fcdcea127cbe361aca89d8d78a80e344d5b40b55b8a92cb1342e3f5b50603255545b0b
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
 
data/cloudconvert.gemspec CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "activesupport", ">= 4.0"
21
21
  spec.add_dependency "down", "~> 5.0"
22
22
  spec.add_dependency "equalizer"
23
- spec.add_dependency "faraday", "~> 1.0"
24
- spec.add_dependency "faraday_middleware", "~> 1.0"
23
+ spec.add_dependency "faraday", ">= 2.0.1"
24
+ spec.add_dependency "faraday-multipart"
25
+ spec.add_dependency "faraday-follow_redirects"
25
26
  spec.add_dependency "forwardable"
26
27
  spec.add_dependency "json"
27
28
  spec.add_dependency "memoizable", "~> 0.4"
@@ -75,21 +75,26 @@ 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|
88
93
  f.adapter Faraday.default_adapter
89
94
  f.request :json
90
95
  f.request :multipart
91
- f.use CloudConvert::Middleware::ParseJson, content_type: /\bjson$/
92
- f.use FaradayMiddleware::FollowRedirects, callback: lambda { |response, redirect|
96
+ f.response :json, content_type: /\bjson$/, parser_options: { object_class: OpenStruct }
97
+ f.response :follow_redirects, callback: lambda { |response, redirect|
93
98
  redirect.request_headers.delete("Content-Length")
94
99
  redirect.request_headers.delete("Content-Type")
95
100
  }
@@ -1,5 +1,5 @@
1
1
  module CloudConvert
2
- class File < Faraday::FilePart
2
+ class File < Faraday::Multipart::FilePart
3
3
  def initialize(file, content_type = nil, *parts)
4
4
  content_type ||= "text/plain" if file.is_a? StringIO
5
5
  content_type ||= Marcel::Magic.by_magic(file) || Marcel::Magic.by_path(file)
@@ -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.1"
3
3
  end
@@ -11,7 +11,7 @@ module CloudConvert::Webhook::Processor
11
11
 
12
12
  def create
13
13
  method = event.name.gsub(".", "_")
14
- raise NoMethodError.new("#{name}##{method} not implemented") unless respond_to?(method, true)
14
+ raise NoMethodError.new("#{self.class.name}##{method} not implemented") unless respond_to?(method, true)
15
15
  send(method, event)
16
16
  head(:ok)
17
17
  end
data/lib/cloudconvert.rb CHANGED
@@ -3,7 +3,8 @@ require "active_support/core_ext/hash/reverse_merge"
3
3
  require "down"
4
4
  require "equalizer"
5
5
  require "faraday"
6
- require "faraday_middleware"
6
+ require "faraday/follow_redirects"
7
+ require "faraday/multipart"
7
8
  require "forwardable"
8
9
  require "json"
9
10
  require "memoizable"
@@ -20,7 +21,6 @@ require "cloudconvert/error"
20
21
  require "cloudconvert/event"
21
22
  require "cloudconvert/file"
22
23
  require "cloudconvert/job"
23
- require "cloudconvert/middleware"
24
24
  require "cloudconvert/resource"
25
25
  require "cloudconvert/resources/jobs"
26
26
  require "cloudconvert/resources/tasks"
@@ -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.1
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: 2023-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -57,30 +57,44 @@ dependencies:
57
57
  name: faraday
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '1.0'
62
+ version: 2.0.1
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '1.0'
69
+ version: 2.0.1
70
70
  - !ruby/object:Gem::Dependency
71
- name: faraday_middleware
71
+ name: faraday-multipart
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '1.0'
76
+ version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '1.0'
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: faraday-follow_redirects
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: forwardable
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -353,11 +367,11 @@ files:
353
367
  - lib/cloudconvert/event.rb
354
368
  - lib/cloudconvert/file.rb
355
369
  - lib/cloudconvert/job.rb
356
- - lib/cloudconvert/middleware.rb
357
370
  - lib/cloudconvert/resource.rb
358
371
  - lib/cloudconvert/resources/jobs.rb
359
372
  - lib/cloudconvert/resources/tasks.rb
360
373
  - lib/cloudconvert/resources/users.rb
374
+ - lib/cloudconvert/signed_url.rb
361
375
  - lib/cloudconvert/task.rb
362
376
  - lib/cloudconvert/user.rb
363
377
  - lib/cloudconvert/version.rb
@@ -370,7 +384,7 @@ metadata:
370
384
  bug_tracker_uri: https://github.com/cloudconvert/cloudconvert-ruby/issues
371
385
  documentation_uri: https://cloudconvert.com/api/v2
372
386
  source_code_uri: https://github.com/cloudconvert/cloudconvert-ruby
373
- post_install_message:
387
+ post_install_message:
374
388
  rdoc_options: []
375
389
  require_paths:
376
390
  - lib
@@ -385,8 +399,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
399
  - !ruby/object:Gem::Version
386
400
  version: '0'
387
401
  requirements: []
388
- rubygems_version: 3.2.15
389
- signing_key:
402
+ rubygems_version: 3.0.3.1
403
+ signing_key:
390
404
  specification_version: 4
391
405
  summary: A Ruby interface to the CloudConvert API v2.
392
406
  test_files: []
@@ -1,9 +0,0 @@
1
- module CloudConvert
2
- module Middleware
3
- class ParseJson < FaradayMiddleware::ParseJson
4
- define_parser do |body, parser_options|
5
- JSON.parse(body, object_class: OpenStruct) unless body.blank?
6
- end
7
- end
8
- end
9
- end