cloudconvert 0.0.5 → 1.0.0
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 +5 -5
- data/LICENSE.txt +17 -18
- data/README.md +234 -39
- data/cloudconvert.gemspec +34 -22
- data/lib/cloudconvert.rb +33 -10
- data/lib/cloudconvert/base.rb +173 -0
- data/lib/cloudconvert/client.rb +107 -0
- data/lib/cloudconvert/collection.rb +15 -0
- data/lib/cloudconvert/entity.rb +21 -0
- data/lib/cloudconvert/error.rb +108 -0
- data/lib/cloudconvert/event.rb +14 -0
- data/lib/cloudconvert/file.rb +9 -0
- data/lib/cloudconvert/job.rb +18 -0
- data/lib/cloudconvert/middleware.rb +9 -0
- data/lib/cloudconvert/resource.rb +9 -0
- data/lib/cloudconvert/resources/jobs.rb +54 -0
- data/lib/cloudconvert/resources/tasks.rb +80 -0
- data/lib/cloudconvert/resources/users.rb +10 -0
- data/lib/cloudconvert/task.rb +43 -0
- data/lib/cloudconvert/user.rb +18 -0
- data/lib/cloudconvert/version.rb +2 -2
- data/lib/cloudconvert/webhook.rb +54 -0
- data/lib/cloudconvert/webhook/processor.rb +29 -0
- metadata +303 -24
- data/.gitignore +0 -21
- data/Gemfile +0 -7
- data/Rakefile +0 -1
- data/lib/cloudconvert/configuration.rb +0 -21
- data/lib/cloudconvert/conversion.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 89b916bcf6d9efb3b86d1def064e3b6bb50970466db82b7fdcd3342050c639d8
|
4
|
+
data.tar.gz: 68d95fcc22a697704661bb8aa0926b36afabcf1edb41620d1c71c7fc8412959e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df53fc7aff33f2d745a1ff53d840fa4c8ada45e8ea77bce1a10b3b4cd18de594f777b5c77f5dd43e13efd9754abe3ac4cdb5332ccd247ff918fd6822da0ef5bd
|
7
|
+
data.tar.gz: 2fbed2d93cf5c8ed525ebbabc4950e9139fefd7513fadd256b33c6f607505820b2c44009cf9c01b92c1baab69e636c2cb825dc7b40a7a2bbb421fcb8322a29f5
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2020 Josias Montag <josias@montag.info>
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,64 +1,259 @@
|
|
1
|
-
|
1
|
+
cloudconvert-ruby
|
2
|
+
=================
|
2
3
|
|
3
|
-
Ruby
|
4
|
+
> This is the official Ruby SDK for the [CloudConvert](https://cloudconvert.com/api/v2) API v2.
|
4
5
|
|
5
|
-
|
6
|
+
[](https://github.com/cloudconvert/cloudconvert-ruby/actions?query=workflow%3ATests)
|
7
|
+
[](https://rubygems.org/gems/cloudconvert)
|
8
|
+
[](https://rubygems.org/gems/cloudconvert)
|
9
|
+
[](https://rubygems.org/gems/cloudconvert)
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
6
13
|
|
7
14
|
Add this line to your application's Gemfile:
|
8
15
|
|
9
|
-
|
16
|
+
```rb
|
17
|
+
gem "cloudconvert"
|
18
|
+
```
|
10
19
|
|
11
20
|
And then execute:
|
12
21
|
|
13
|
-
|
22
|
+
```sh
|
23
|
+
bundle install
|
24
|
+
```
|
14
25
|
|
15
26
|
Or install it yourself as:
|
16
27
|
|
17
|
-
|
28
|
+
```sh
|
29
|
+
gem install cloudconvert
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
Creating API Client
|
34
|
+
-------------------
|
35
|
+
|
36
|
+
```rb
|
37
|
+
cloudconvert = CloudConvert::Client.new(api_key: "API_KEY", sandbox: false)
|
38
|
+
```
|
39
|
+
|
40
|
+
Or set the environment variables `CLOUDCONVERT_API_KEY` and `CLOUDCONVERT_SANDBOX` and use:
|
41
|
+
|
42
|
+
```rb
|
43
|
+
cloudconvert = CloudConvert::Client.new
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
Creating Jobs
|
48
|
+
-------------
|
49
|
+
|
50
|
+
```rb
|
51
|
+
cloudconvert.jobs.create({
|
52
|
+
tasks: [
|
53
|
+
{
|
54
|
+
name: "import-my-file",
|
55
|
+
operation: "import/url",
|
56
|
+
url: "https://my-url"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
name: "convert-my-file",
|
60
|
+
operation: "convert",
|
61
|
+
input: "import-my-file",
|
62
|
+
output_format: "pdf",
|
63
|
+
some_other_option: "value"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
name: "export-my-file",
|
67
|
+
operation: "export/url",
|
68
|
+
input: "convert-my-file"
|
69
|
+
},
|
70
|
+
]
|
71
|
+
})
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
Downloading Files
|
76
|
+
-----------------
|
77
|
+
|
78
|
+
CloudConvert can generate public URLs for using `export/url` tasks.
|
79
|
+
|
80
|
+
You can use these URLs to download output files:
|
81
|
+
|
82
|
+
```rb
|
83
|
+
exported_url_task_id = "84e872fc-d823-4363-baab-eade2e05ee54"
|
84
|
+
task = cloudconvert.tasks.wait(exported_url_task_id) # Wait for job completion
|
85
|
+
file = task.result.files.first
|
86
|
+
export = cloudconvert.download(file.url)
|
87
|
+
```
|
88
|
+
|
89
|
+
By default the remote file will be downloaded into a temporary location and returned as a `Tempfile`.
|
90
|
+
If you would like the file to be downloaded to a specific location on disk, you can specify the `:destination` option:
|
91
|
+
|
92
|
+
```rb
|
93
|
+
export = cloudconvert.download(file.url, destination: "/path/to/destination")
|
94
|
+
```
|
95
|
+
|
96
|
+
The `download` method is powered by the [Down gem](https://github.com/janko/down),
|
97
|
+
for the full list of arguments see the [the down docs](https://github.com/janko/down#down).
|
98
|
+
|
99
|
+
|
100
|
+
Uploading Files
|
101
|
+
---------------
|
102
|
+
|
103
|
+
Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)):
|
104
|
+
|
105
|
+
```rb
|
106
|
+
job = cloudconvert.jobs.create({
|
107
|
+
tasks: [
|
108
|
+
{
|
109
|
+
name: "upload-my-file",
|
110
|
+
operation: "import/upload",
|
111
|
+
}
|
112
|
+
]
|
113
|
+
})
|
114
|
+
```
|
115
|
+
|
116
|
+
After you've created a `import/upload` task, you can upload a file:
|
117
|
+
|
118
|
+
```rb
|
119
|
+
upload_task = job.tasks.where(operation: "import/upload").first
|
120
|
+
|
121
|
+
response = cloudconvert.tasks.upload("/path/to/sample.pdf", upload_task)
|
122
|
+
|
123
|
+
updated_task = cloudconvert.tasks.find(upload_task.id)
|
124
|
+
```
|
125
|
+
|
126
|
+
Alternatively, instead of a path, you can pass in an open `IO` object:
|
127
|
+
|
128
|
+
```rb
|
129
|
+
file = File.open("/path/to/sample.pdf")
|
130
|
+
response = cloudconvert.tasks.upload(file, upload_task)
|
131
|
+
```
|
132
|
+
|
133
|
+
If you need to manually specify a `mimetype` or `filename` use our file wrapper:
|
134
|
+
|
135
|
+
```rb
|
136
|
+
file = CloudConvert::File.new("/path/to/sample.pdf", "video/mp4", "sample.mp4")
|
137
|
+
response = cloudconvert.tasks.upload(file, upload_task)
|
138
|
+
```
|
139
|
+
|
140
|
+
|
141
|
+
Webhooks
|
142
|
+
--------
|
143
|
+
|
144
|
+
Webhooks can be created on the [CloudConvert Dashboard](https://cloudconvert.com/dashboard/api/v2/webhooks),
|
145
|
+
where you can also find the signing secret.
|
146
|
+
|
147
|
+
If you're using Rails, you'll want to configure a route to receive the CloudConvert webhook POST requests:
|
148
|
+
|
149
|
+
```rb
|
150
|
+
# config/routes.rb
|
151
|
+
resource :cloudconvert_webhooks, controller: :cloud_convert_webhooks, only: :create
|
152
|
+
```
|
153
|
+
|
154
|
+
Then create a new controller that uses our processor concern:
|
155
|
+
|
156
|
+
```rb
|
157
|
+
# app/controllers/cloudconvert_webhooks_controller.rb
|
158
|
+
class CloudConvertWebhooksController < ActionController::Base
|
159
|
+
include CloudConvert::Webhook::Processor
|
160
|
+
|
161
|
+
# Handle job.created event
|
162
|
+
def job_created(event)
|
163
|
+
# TODO: handle job.created webhook
|
164
|
+
end
|
165
|
+
|
166
|
+
# Handle job.finished event
|
167
|
+
def job_finished(event)
|
168
|
+
# TODO: handle job.finished webhook
|
169
|
+
end
|
170
|
+
|
171
|
+
# Handle job.failed event
|
172
|
+
def job_failed(event)
|
173
|
+
# TODO: handle job.failed webhook
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
|
178
|
+
def webhook_secret(event)
|
179
|
+
ENV['CLOUDCONVERT_WEBHOOK_SECRET']
|
180
|
+
end
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
Alternatively, you can verify the payload yourself:
|
185
|
+
|
186
|
+
```rb
|
187
|
+
payload = request.body.read
|
188
|
+
signature = request.headers["CloudConvert-Signature"]
|
189
|
+
secret = "..." # You can find it in your webhook settings
|
190
|
+
|
191
|
+
if CloudConvert::Webhook::verify(payload, signature, secret)
|
192
|
+
event = CloudConvert::Webhook::event(payload)
|
193
|
+
event.name == "job.finished"
|
194
|
+
puts event.job.id
|
195
|
+
puts event.job.tasks.count
|
196
|
+
end
|
197
|
+
```
|
198
|
+
|
199
|
+
Or by passing in a request:
|
200
|
+
|
201
|
+
```rb
|
202
|
+
CloudConvert::Webhook::verify_request(request, secret)
|
203
|
+
```
|
204
|
+
|
205
|
+
The `verify`/`verify_request` methods return `true`/`false`, use `verify!` or `verify_request!` if you'd rather raise a `CloudConvert::Webhook::Error`.
|
206
|
+
|
207
|
+
You can read the [full list of events](https://cloudconvert.com/api/v2/webhooks) CloudConvert can notify you about in our documentation.
|
208
|
+
|
209
|
+
|
210
|
+
Development
|
211
|
+
-----------
|
212
|
+
|
213
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
214
|
+
|
215
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
216
|
+
|
217
|
+
|
218
|
+
Contributing
|
219
|
+
------------
|
220
|
+
|
221
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cloudconvert/cloudconvert-ruby.
|
18
222
|
|
19
|
-
## Usage
|
20
223
|
|
21
|
-
|
22
|
-
|
23
|
-
Configure CloudConvert
|
24
|
-
|
25
|
-
Cloudconvert.configure do |config|
|
26
|
-
config.api_key = your_api_key
|
27
|
-
config.callback = callback_url
|
28
|
-
end
|
224
|
+
Unit Tests
|
225
|
+
----------
|
29
226
|
|
30
|
-
|
227
|
+
```sh
|
228
|
+
rspec --tag unit
|
229
|
+
```
|
31
230
|
|
32
|
-
Start a Conversion on Cloud convert
|
33
231
|
|
34
|
-
|
232
|
+
Integration Tests
|
233
|
+
-----------------
|
35
234
|
|
36
|
-
|
37
|
-
|
235
|
+
```sh
|
236
|
+
rspec --tag integration
|
237
|
+
```
|
38
238
|
|
39
|
-
|
40
|
-
|
41
|
-
|
239
|
+
By default, this runs the integration tests against [VCR recordings](https://github.com/vcr/vcr) of the Sandbox API with an official CloudConvert account.
|
240
|
+
If you would like to use your own account, you can set your API key using the `CLOUDCONVERT_API_KEY` environment variable and disable VCR with `VCR=off` or by using the `rake spec:sandbox` task.
|
241
|
+
In this case you need to whitelist the following MD5 hashes for Sandbox API (using the CloudConvert dashboard).
|
42
242
|
|
43
|
-
|
44
|
-
|
243
|
+
```
|
244
|
+
53d6fe6b688c31c565907c81de625046 input.pdf
|
245
|
+
99d4c165f77af02015aa647770286cf9 input.png
|
246
|
+
```
|
45
247
|
|
46
|
-
# to cancel conversion
|
47
|
-
conversion.cancel_conversion
|
48
248
|
|
49
|
-
|
50
|
-
|
249
|
+
License
|
250
|
+
-------
|
51
251
|
|
52
|
-
|
53
|
-
conversion.download_link
|
252
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
253
|
|
55
|
-
# to get current status of conversion
|
56
|
-
conversion.status
|
57
254
|
|
58
|
-
|
255
|
+
Resources
|
256
|
+
---------
|
59
257
|
|
60
|
-
|
61
|
-
|
62
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
-
5. Create new Pull Request
|
258
|
+
* [API v2 Documentation](https://cloudconvert.com/api/v2)
|
259
|
+
* [CloudConvert Blog](https://cloudconvert.com/blog)
|
data/cloudconvert.gemspec
CHANGED
@@ -1,26 +1,38 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'cloudconvert/version'
|
1
|
+
require_relative "lib/cloudconvert/version"
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.
|
15
|
-
|
16
|
-
spec.
|
17
|
-
spec.
|
18
|
-
spec.
|
19
|
-
spec.
|
20
|
-
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
|
24
|
-
spec.add_dependency "faraday"
|
4
|
+
spec.name = "cloudconvert"
|
5
|
+
spec.version = CloudConvert::VERSION
|
6
|
+
spec.authors = ["Josias Montag", "Steve Lacey"]
|
7
|
+
spec.email = %w[josias@montag.info steve@steve.ly]
|
8
|
+
spec.description = "A Ruby interface to the CloudConvert API v2."
|
9
|
+
spec.summary = spec.description
|
10
|
+
spec.homepage = "https://cloudconvert.com/api/v2"
|
11
|
+
spec.files = %w[cloudconvert.gemspec LICENSE.txt README.md] + Dir["lib/**/*.rb"]
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.require_paths = %w[lib]
|
14
|
+
spec.required_ruby_version = ">= 2.7"
|
15
|
+
spec.add_dependency "activesupport", ">= 4.0"
|
16
|
+
spec.add_dependency "down", "~> 5.0"
|
17
|
+
spec.add_dependency "equalizer"
|
18
|
+
spec.add_dependency "faraday", "~> 1.0"
|
19
|
+
spec.add_dependency "faraday_middleware", "~> 1.0"
|
20
|
+
spec.add_dependency "forwardable"
|
25
21
|
spec.add_dependency "json"
|
22
|
+
spec.add_dependency "memoizable", "~> 0.4"
|
23
|
+
spec.add_dependency "mimemagic", "~> 0.3.5"
|
24
|
+
spec.add_dependency "openssl"
|
25
|
+
spec.add_dependency "ostruct"
|
26
|
+
spec.add_dependency "schemacop", "~> 2.4"
|
27
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
|
+
spec.add_development_dependency "climate_control"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "rack", "~> 2.2"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "rubocop", "~> 1.5"
|
34
|
+
spec.add_development_dependency "securerandom"
|
35
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
36
|
+
spec.add_development_dependency "webmock"
|
37
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
26
38
|
end
|
data/lib/cloudconvert.rb
CHANGED
@@ -1,15 +1,38 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "
|
4
|
-
|
1
|
+
require "active_support/concern"
|
2
|
+
require "active_support/core_ext/hash/reverse_merge"
|
3
|
+
require "down"
|
4
|
+
require "equalizer"
|
5
5
|
require "faraday"
|
6
|
+
require "faraday_middleware"
|
7
|
+
require "forwardable"
|
6
8
|
require "json"
|
9
|
+
require "memoizable"
|
10
|
+
require "mimemagic"
|
11
|
+
require "openssl"
|
12
|
+
require "ostruct"
|
13
|
+
require "schemacop"
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
require "cloudconvert/base"
|
16
|
+
require "cloudconvert/client"
|
17
|
+
require "cloudconvert/collection"
|
18
|
+
require "cloudconvert/entity"
|
19
|
+
require "cloudconvert/error"
|
20
|
+
require "cloudconvert/event"
|
21
|
+
require "cloudconvert/file"
|
22
|
+
require "cloudconvert/job"
|
23
|
+
require "cloudconvert/middleware"
|
24
|
+
require "cloudconvert/resource"
|
25
|
+
require "cloudconvert/resources/jobs"
|
26
|
+
require "cloudconvert/resources/tasks"
|
27
|
+
require "cloudconvert/resources/users"
|
28
|
+
require "cloudconvert/task"
|
29
|
+
require "cloudconvert/user"
|
30
|
+
require "cloudconvert/version"
|
31
|
+
require "cloudconvert/webhook"
|
32
|
+
require "cloudconvert/webhook/processor"
|
14
33
|
|
34
|
+
module CloudConvert
|
35
|
+
API_URL = "https://api.cloudconvert.com".freeze
|
36
|
+
SANDBOX_URL = "https://api.sandbox.cloudconvert.com".freeze
|
37
|
+
USER_AGENT = "CloudConvertRubyGem/#{CloudConvert::VERSION}".freeze
|
15
38
|
end
|