cloudconvert 0.0.5 → 1.0.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
- SHA1:
3
- metadata.gz: fbd33992f2bb0eb736b817259e26ff729b3f3066
4
- data.tar.gz: b3452c6677786aba313a97c260eb13e8d83c306a
2
+ SHA256:
3
+ metadata.gz: 89b916bcf6d9efb3b86d1def064e3b6bb50970466db82b7fdcd3342050c639d8
4
+ data.tar.gz: 68d95fcc22a697704661bb8aa0926b36afabcf1edb41620d1c71c7fc8412959e
5
5
  SHA512:
6
- metadata.gz: 2904f73386d4f1110fa1f95b9f239270bb223b492f0d86f2a71ae7cbfc53b009c2c65ec0125a1c537560f0c042c53806a163d1a1815003ec3a6ca9c784099dc8
7
- data.tar.gz: 97550957b2be2e493e131359d90aaf16c22e0444a190a0a6bda8a0040011a7a60ea1e3cc79807d983ca683a007f310c86db62db7dac44827901126a55fecd870
6
+ metadata.gz: df53fc7aff33f2d745a1ff53d840fa4c8ada45e8ea77bce1a10b3b4cd18de594f777b5c77f5dd43e13efd9754abe3ac4cdb5332ccd247ff918fd6822da0ef5bd
7
+ data.tar.gz: 2fbed2d93cf5c8ed525ebbabc4950e9139fefd7513fadd256b33c6f607505820b2c44009cf9c01b92c1baab69e636c2cb825dc7b40a7a2bbb421fcb8322a29f5
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 Pandurang
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2020 Josias Montag <josias@montag.info>
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
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
- included in all copies or substantial portions of the Software.
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
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
- # Cloudconvert
1
+ cloudconvert-ruby
2
+ =================
2
3
 
3
- Ruby wrapper for CloudConvert [CloudConvert ](https://cloudconvert.org/page/api)
4
+ > This is the official Ruby SDK for the [CloudConvert](https://cloudconvert.com/api/v2) API v2.
4
5
 
5
- ## Installation
6
+ [![Build Status](https://github.com/cloudconvert/cloudconvert-ruby/workflows/Tests/badge.svg)](https://github.com/cloudconvert/cloudconvert-ruby/actions?query=workflow%3ATests)
7
+ [![Latest Stable Version](https://img.shields.io/gem/v/cloudconvert?label=stable)](https://rubygems.org/gems/cloudconvert)
8
+ [![Total Downloads](https://img.shields.io/gem/dt/cloudconvert)](https://rubygems.org/gems/cloudconvert)
9
+ [![License](https://img.shields.io/github/license/cloudconvert/cloudconvert-ruby)](https://rubygems.org/gems/cloudconvert)
10
+
11
+ Installation
12
+ ------------
6
13
 
7
14
  Add this line to your application's Gemfile:
8
15
 
9
- gem 'cloudconvert'
16
+ ```rb
17
+ gem "cloudconvert"
18
+ ```
10
19
 
11
20
  And then execute:
12
21
 
13
- $ bundle
22
+ ```sh
23
+ bundle install
24
+ ```
14
25
 
15
26
  Or install it yourself as:
16
27
 
17
- $ gem install cloudconvert
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
- This is a Ruby wrapper for Cloud Convert where you can convert files from one format to another format.
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
- In this if you specify callback_url then you will be notified on file conversion completion
227
+ ```sh
228
+ rspec --tag unit
229
+ ```
31
230
 
32
- Start a Conversion on Cloud convert
33
231
 
34
- conversion = Cloudconvert::Conversion.new
232
+ Integration Tests
233
+ -----------------
35
234
 
36
- # to start file conversion (options & callback_url parameters are optional)
37
- conversion.convert(inputformat, outputformat, file_path, callback_url, options)
235
+ ```sh
236
+ rspec --tag integration
237
+ ```
38
238
 
39
- # options parameter is Conversion type specific options , which you can get from,
40
- conversion.converter_options(inputformat, outputformat)
41
- #it will return all possible conversion types and possible options(inputformat and outputformat are optional)
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
- # to list all conversions
44
- conversion.list_conversions
243
+ ```
244
+ 53d6fe6b688c31c565907c81de625046 input.pdf
245
+ 99d4c165f77af02015aa647770286cf9 input.png
246
+ ```
45
247
 
46
- # to cancel conversion
47
- conversion.cancel_conversion
48
248
 
49
- # to delete conversion
50
- conversion.delete_conversion
249
+ License
250
+ -------
51
251
 
52
- # to get download link of completed conversion
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
- ## Contributing
255
+ Resources
256
+ ---------
59
257
 
60
- 1. Fork it
61
- 2. Create your feature branch (`git checkout -b my-new-feature`)
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)
@@ -1,26 +1,38 @@
1
- # coding: utf-8
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 = "cloudconvert"
8
- spec.version = Cloudconvert::VERSION
9
- spec.authors = ["Pandurang Waghulde"]
10
- spec.email = ["pandurang.plw@gmail.com"]
11
- spec.description = "Ruby wrapper for Cloud Convert"
12
- spec.summary = "Ruby wrapper for Cloud Convert"
13
- spec.homepage = "https://github.com/pandurang90/cloudconvert"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
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
@@ -1,15 +1,38 @@
1
- require "cloudconvert/version"
2
- require "cloudconvert/configuration"
3
- require "cloudconvert/conversion"
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
- module Cloudconvert
9
- # Your code goes here...
10
- CONVERSION_URL = "https://api.cloudconvert.org/"
11
-
12
- API_KEY_ERROR = "API Key cant be blank!"
13
- Cloudconvert.configure
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