uploadcare-ruby 3.1.1 → 3.2.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: 50f31851c1ededcc13b14099d5451a2cae8ad1a1c36ce45bbe47447fc536dc3a
4
- data.tar.gz: 0c5eecb5f2583645455230fb5679c65612e322a4dcae82cae97e5b9fc702dab4
3
+ metadata.gz: f1c9e31f806af7e05c558fac2f5474b1b79bbe6585437049a2ecca5cc7011b46
4
+ data.tar.gz: 3da125b462b72f76f1cc52b3d9654354399d4864eba72b34e474c5d9a05ca22b
5
5
  SHA512:
6
- metadata.gz: 0a1c5aef9d35b915e2a691ecaed88a1687bba7c7692e6c5066999e1348c5ba0bc9fe76e4afd3eea08da72b57f9a58379a7fc287385a316c6a12e795005e9b66e
7
- data.tar.gz: 44a5eb8c106bd7b803428d4d8c7ad056b723dfc014baa4e94fd390c0924732a14b3d7ad9e262fa6e7de02a75bca073ee19b8476eda64c86b6fee1817380124c5
6
+ metadata.gz: '06814335c0ac2733f7a71ad0a9f04af2c9e3160d59de4d3d88231403a6e02366a10bb8db9405762d6a2ed70c82fb0185e5e11e59763cc2f04f79a67c89f52718'
7
+ data.tar.gz: 9c9d034e9d510c0d1839f5b13164a810ee26c58eb75cdcff3aaf6e54aeb6a5f2a0a9c20f2d75d0b6c6f5856eba7a8ccb2b42b7cb4b7ea45f74f5242120bf5534
data/CHANGELOG.md CHANGED
@@ -1,36 +1,41 @@
1
1
  # Changelog
2
2
 
3
- ## 3.1.1 2021-10-13
3
+ ## 3.2.0 2021-11-16
4
4
 
5
- - Fix Uploadcare::File#store
6
- - Fix Uploadcare::File#delete
5
+ - Added option `signing_secret` to the `Uploadcare::Webhook`
6
+ - Added webhook signature verifier class `Uploadcare::Param::WebhookSignatureVerifier`
7
7
 
8
- ## 3.1.0 2021-09-21
8
+ ## 3.1.1 2021-10-13
9
9
 
10
- - Added documents and videos conversion
11
- - Added new attributes to the Entity class (variations, video_info, source, rekognition_info)
12
- - Added an opportunity to add custom logic to large files uploading process
10
+ - Fixed `Uploadcare::File#store`
11
+ - Fixed `Uploadcare::File#delete`
13
12
 
14
- ## 3.0.5 2021-04-15
13
+ ## 3.1.0 2021-09-21
14
+
15
+ - Added documents and videos conversions
16
+ - Added new attributes to the Entity class (`variations`, `video_info`, `source`, `rekognition_info`)
17
+ - Added an option to add custom logic to large files uploading process
18
+
19
+ ## 3.0.5 — 2021-04-15
15
20
 
16
21
  - Replace Travis-CI with Github Actions
17
22
  - Automate gem pushing
18
23
 
19
- ## 3.0.4-dev 2020-03-19
24
+ ## 3.0.4-dev 2020-03-19
20
25
 
21
- - Added better pagination methods for GroupList & FileList
26
+ - Added better pagination methods for `GroupList` & `FileList`
22
27
  - Improved documentation and install instructions
23
28
  - Added CI
24
29
 
25
- ## 3.0.3-dev 2020-03-13
26
- - Added better pagination and iterators for GroupList & FileList
30
+ ## 3.0.3-dev 2020-03-13
31
+ - Added better pagination and iterators for `GroupList` & `FileList`
27
32
 
28
- ## 3.0.2-dev 2020-03-11
33
+ ## 3.0.2-dev 2020-03-11
29
34
 
30
- - Expanded File and Group entities
35
+ - Expanded `File` and `Group` entities
31
36
  - Changed user agent syntax
32
37
 
33
- ## 3.0.1-dev 2020-03-11
38
+ ## 3.0.1-dev 2020-03-11
34
39
 
35
40
  - Added Upload/group functionality
36
41
  - Added user API
@@ -38,7 +43,7 @@
38
43
  - Isolated clients, entities and concerns
39
44
  - Expanded documentation
40
45
 
41
- ## 3.0.0-dev 2020-02-18
46
+ ## 3.0.0-dev 2020-02-18
42
47
 
43
48
  ### Changed
44
49
  - Rewrote gem from scratch
data/README.md CHANGED
@@ -52,7 +52,7 @@ And then execute:
52
52
 
53
53
  $ bundle
54
54
 
55
- If already not, create your project in [Uploadcare dashboard](https://uploadcare.com/dashboard/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby) and copy
55
+ If already not, create your project in [Uploadcare dashboard](https://app.uploadcare.com/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby) and copy
56
56
  its API keys from there.
57
57
 
58
58
  Set your Uploadcare keys in config file or through environment variables:
@@ -75,7 +75,10 @@ Uploadcare.config.secret_key = "demoprivatekey"
75
75
 
76
76
  This section contains practical usage examples. Please note, everything that
77
77
  follows gets way more clear once you've looked through our
78
- [docs](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby).
78
+ [docs](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby)
79
+ and [Upload](https://uploadcare.com/api-refs/upload-api/) and [REST](https://uploadcare.com/api-refs/rest-api/) API refs.
80
+
81
+ You can also find an example project [here](https://github.com/uploadcare/uploadcare-rails-example).
79
82
 
80
83
  ### Uploading files
81
84
  #### Uploading and storing a single file
@@ -295,8 +298,8 @@ how they should be fetched:
295
298
  - **:limit** — Controls page size. Accepts values from 1 to 1000, defaults to 100.
296
299
  - **:stored** — Can be either `true` or `false`. When true, file list will contain only stored files. When false — only not stored.
297
300
  - **:removed** — Can be either `true` or `false`. When true, file list will contain only removed files. When false — all except removed. Defaults to false.
298
- - **:ordering** — Controls the order of returned files. Available values: `datetime_updated`, `-datetime_updated`, `size`, `-size`. Defaults to `datetime_uploaded`. More info can be found [here](https://uploadcare.com/documentation/rest/#file-files/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby).
299
- - **:from** — Specifies the starting point for a collection. Resulting collection will contain files from the given value and to the end in a direction set by an **ordering** option. When files are ordered by `datetime_updated` in any direction, accepts either a `DateTime` object or an ISO 8601 string. When files are ordered by size, accepts non-negative integers (size in bytes). More info can be found [here](https://uploadcare.com/documentation/rest/#file-files/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby).
301
+ - **:ordering** — Controls the order of returned files. Available values: `datetime_updated`, `-datetime_updated`, `size`, `-size`. Defaults to `datetime_uploaded`. More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/filesList).
302
+ - **:from** — Specifies the starting point for a collection. Resulting collection will contain files from the given value and to the end in a direction set by an **ordering** option. When files are ordered by `datetime_updated` in any direction, accepts either a `DateTime` object or an ISO 8601 string. When files are ordered by size, accepts non-negative integers (size in bytes). More info can be found [here](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/filesList).
300
303
 
301
304
  Options used to create a file list can be accessed through `#options` method.
302
305
  Note that, once set, they don't affect file fetching process anymore and are
@@ -369,18 +372,67 @@ https://uploadcare.com/docs/api_reference/rest/webhooks/
369
372
  You can use webhooks to provide notifications about your uploads to target urls.
370
373
  This gem lets you create and manage webhooks.
371
374
 
375
+ Each webhook payload can be signed with a secret (the `signing_secret` option) to ensure that the request comes from the expected sender.
376
+ More info about secure webhooks [here](https://uploadcare.com/docs/security/secure-webhooks/).
377
+
372
378
  ```ruby
373
- Uploadcare::Webhook.create(target_url: "https://example.com/listen", event: "file.uploaded", is_active: true)
374
- Uploadcare::Webhook.update(<webhook_id>, target_url: "https://newexample.com/listen/new", event: "file.uploaded", is_active: true)
379
+ Uploadcare::Webhook.create(target_url: "https://example.com/listen", event: "file.uploaded", is_active: true, signing_secret: "some-secret")
380
+ Uploadcare::Webhook.update(<webhook_id>, target_url: "https://newexample.com/listen/new", event: "file.uploaded", is_active: true, signing_secret: "some-secret")
375
381
  Uploadcare::Webhook.delete("https://example.com/listen")
376
382
  Uploadcare::Webhook.list
377
383
  ```
378
384
 
385
+ ##### Webhook signature verification
386
+
387
+ The gem has a helper class to verify a webhook signature from headers —
388
+ `Uploadcare::Param::WebhookSignatureVerifier`. This class accepts three
389
+ important options:
390
+
391
+ - **:webhook_body** — this option represents parameters received in the webhook
392
+ request in the JSON format.
393
+ **NOTE**: if you're using Rails, you should exclude options `controller`,
394
+ `action` and `post` from the `webhook_body`.
395
+ - **:signing_secret** — the secret that was set while creating/updating a
396
+ webhook. This option can be specified as an ENV var with the name
397
+ `UC_SIGNING_SECRET` — then no need to send it to the verifier class.
398
+ - **:x_uc_signature_header** — the content of the `X-Uc-Signature` HTTP header
399
+ in the webhook request.
400
+
401
+ Using the `Uploadcare::Param::WebhookSignatureVerifier` class example:
402
+
403
+ ```ruby
404
+ webhook_body = '{...}'
405
+
406
+ signing_secret = "12345X"
407
+ x_uc_signature_header = "v1=9b31c7dd83fdbf4a2e12b19d7f2b9d87d547672a325b9492457292db4f513c70"
408
+
409
+ Uploadcare::Param::WebhookSignatureVerifier.valid?(signing_secret: signing_secret, x_uc_signature_header: x_uc_signature_header, webhook_body: webhook_body)
410
+ ```
411
+
412
+ You can write your verifier. Example code:
413
+
414
+ ```ruby
415
+ webhook_body_json = '{...}'
416
+
417
+ signing_secret = ENV['UC_SIGNING_SECRET']
418
+ x_uc_signature_header = "v1=f4d859ed2fe47b9a4fcc81693d34e58ad12366a841e58a7072c1530483689cc0"
419
+
420
+ digest = OpenSSL::Digest.new('sha256')
421
+
422
+ calculated_signature = "v1=#{OpenSSL::HMAC.hexdigest(digest, signing_secret.force_encoding("utf-8"), webhook_body_json.force_encoding("utf-8"))}"
423
+
424
+ if calculated_signature == x_uc_signature_header
425
+ puts "WebHook signature matches!"
426
+ else
427
+ puts "WebHook signature mismatch!"
428
+ end
429
+ ```
430
+
379
431
  #### Project
380
432
 
381
433
  `Project` provides basic info about the connected Uploadcare project. That
382
434
  object is also an Hashie::Mash, so every methods out of
383
- [these](https://uploadcare.com/documentation/rest/#project/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-ruby) will work.
435
+ [these](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/projectInfo) will work.
384
436
 
385
437
  ```ruby
386
438
  @project = Uploadcare::Project.project
@@ -399,8 +451,6 @@ object is also an Hashie::Mash, so every methods out of
399
451
 
400
452
  ##### Video
401
453
 
402
- Uploadcare can encode video files from all popular formats, adjust their quality, format and dimensions, cut out a video fragment, and generate thumbnails via [REST API](https://uploadcare.com/api-refs/rest-api/v0.6.0/).
403
-
404
454
  After each video file upload you obtain a file identifier in UUID format.
405
455
  Then you can use this file identifier to convert your video in multiple ways:
406
456
 
@@ -461,7 +511,7 @@ Params in the response:
461
511
  - **original_source** - built path for a particular video with all the conversion operations and parameters.
462
512
  - **token** - a processing job token that can be used to get a [job status](https://uploadcare.com/docs/transformations/video-encoding/#status) (see below).
463
513
  - **uuid** - UUID of your processed video file.
464
- - **thumbnails_group_uuid** - holds :uuid-thumb-group, a UUID of a [file group](https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/groupsList) with thumbnails for an output video, based on the thumbs [operation](https://uploadcare.com/docs/transformations/video-encoding/#operation-thumbs) parameters.
514
+ - **thumbnails_group_uuid** - holds :uuid-thumb-group, a UUID of a [file group](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/groupsList) with thumbnails for an output video, based on the thumbs [operation](https://uploadcare.com/docs/transformations/video-encoding/#operation-thumbs) parameters.
465
515
  - **problems** - problems related to your processing job, if any.
466
516
 
467
517
  To convert multiple videos just add params as a hash for each video to the first argument of the `Uploadcare::VideoConverter#convert` method:
@@ -508,12 +558,10 @@ Params in the response:
508
558
  - **thumbnails_group_uuid** - holds :uuid-thumb-group, a UUID of a file group with thumbnails for an output video, based on the thumbs operation parameters.
509
559
  - **uuid** - a UUID of your processed video file.
510
560
 
511
- More examples and options can be found [here](https://uploadcare.com/docs/transformations/video-encoding/#video-encoding)
561
+ More examples and options can be found [here](https://uploadcare.com/docs/transformations/video-encoding/#video-encoding).
512
562
 
513
563
  ##### Document
514
564
 
515
- Uploadcare allows converting documents to the following target formats: doc, docx, xls, xlsx, odt, ods, rtf, txt, pdf, jpg, png. Document Conversion works via our [REST API](https://uploadcare.com/api-refs/rest-api/v0.6.0/).
516
-
517
565
  After each document file upload you obtain a file identifier in UUID format.
518
566
  Then you can use this file identifier to convert your document to a new format:
519
567
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'rest_client'
4
+
3
5
  module Uploadcare
4
6
  module Client
5
7
  # API client for getting project info
@@ -14,7 +14,9 @@ module Uploadcare
14
14
  'target_url': options[:target_url],
15
15
  'event': options[:event] || 'file.uploaded',
16
16
  'is_active': options[:is_active].nil? ? true : options[:is_active]
17
- }.to_json
17
+ }.merge(
18
+ { 'signing_secret': options[:signing_secret] }.compact
19
+ ).to_json
18
20
  post(uri: '/webhooks/', content: body)
19
21
  end
20
22
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest/md5'
4
+
5
+ module Uploadcare
6
+ module Param
7
+ # This object verifies a signature received along with webhook headers
8
+ class WebhookSignatureVerifier
9
+ # @see https://uploadcare.com/docs/security/secure-webhooks/
10
+ def self.valid?(options = {})
11
+ webhook_body_json = options[:webhook_body]
12
+ signing_secret = options[:signing_secret] || ENV['UC_SIGNING_SECRET']
13
+ x_uc_signature_header = options[:x_uc_signature_header]
14
+
15
+ digest = OpenSSL::Digest.new('sha256')
16
+
17
+ calculated_signature = "v1=#{OpenSSL::HMAC.hexdigest(digest, signing_secret, webhook_body_json)}"
18
+
19
+ calculated_signature == x_uc_signature_header
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploadcare
4
- VERSION = '3.1.1'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/uploadcare.rb CHANGED
@@ -17,6 +17,9 @@ require 'entity/project'
17
17
  require 'entity/uploader'
18
18
  require 'entity/webhook'
19
19
 
20
+ # Param
21
+ require 'param/webhook_signature_verifier'
22
+
20
23
  # General api
21
24
  require 'api/api'
22
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan Redka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-14 00:00:00.000000000 Z
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_struct
@@ -214,6 +214,7 @@ files:
214
214
  - lib/uploadcare/param/upload/signature_generator.rb
215
215
  - lib/uploadcare/param/upload/upload_params_generator.rb
216
216
  - lib/uploadcare/param/user_agent.rb
217
+ - lib/uploadcare/param/webhook_signature_verifier.rb
217
218
  - lib/uploadcare/ruby/version.rb
218
219
  - uploadcare-ruby.gemspec
219
220
  homepage: https://github.com/uploadcare/uploadcare-ruby
@@ -241,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
242
  - !ruby/object:Gem::Version
242
243
  version: '0'
243
244
  requirements: []
244
- rubygems_version: 3.2.22
245
+ rubygems_version: 3.0.1
245
246
  signing_key:
246
247
  specification_version: 4
247
248
  summary: Ruby wrapper for uploadcare API