uploadcare-ruby 4.4.2 → 5.0.0.rc1
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 +4 -4
- data/.env.example +7 -0
- data/.github/workflows/gem-push.yml +1 -1
- data/.github/workflows/ruby.yml +10 -13
- data/.gitignore +9 -0
- data/.rubocop.yml +95 -8
- data/CHANGELOG.md +78 -0
- data/Gemfile +23 -6
- data/MIGRATING_V5.md +290 -0
- data/README.md +422 -671
- data/Rakefile +5 -1
- data/api_examples/README.md +77 -0
- data/api_examples/rest_api/delete_files_storage.rb +3 -5
- data/api_examples/rest_api/delete_files_uuid_metadata_key.rb +3 -4
- data/api_examples/rest_api/delete_files_uuid_storage.rb +3 -4
- data/api_examples/rest_api/delete_groups_uuid.rb +3 -4
- data/api_examples/rest_api/delete_webhooks_unsubscribe.rb +3 -4
- data/api_examples/rest_api/get_addons_aws_rekognition_detect_labels_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_aws_rekognition_detect_moderation_labels_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_remove_bg_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_uc_clamav_virus_scan_execute_status.rb +3 -6
- data/api_examples/rest_api/get_convert_document_status_token.rb +3 -5
- data/api_examples/rest_api/get_convert_document_uuid.rb +3 -5
- data/api_examples/rest_api/get_convert_video_status_token.rb +3 -5
- data/api_examples/rest_api/get_files.rb +3 -5
- data/api_examples/rest_api/get_files_uuid.rb +3 -5
- data/api_examples/rest_api/get_files_uuid_metadata.rb +3 -5
- data/api_examples/rest_api/get_files_uuid_metadata_key.rb +3 -5
- data/api_examples/rest_api/get_groups.rb +3 -5
- data/api_examples/rest_api/get_groups_uuid.rb +3 -5
- data/api_examples/rest_api/get_project.rb +3 -5
- data/api_examples/rest_api/get_webhooks.rb +3 -5
- data/api_examples/rest_api/post_addons_aws_rekognition_detect_labels_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_aws_rekognition_detect_moderation_labels_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_remove_bg_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_uc_clamav_virus_scan_execute.rb +3 -5
- data/api_examples/rest_api/post_convert_document.rb +3 -6
- data/api_examples/rest_api/post_convert_video.rb +3 -10
- data/api_examples/rest_api/post_files_local_copy.rb +3 -6
- data/api_examples/rest_api/post_files_remote_copy.rb +3 -7
- data/api_examples/rest_api/post_webhooks.rb +3 -9
- data/api_examples/rest_api/put_files_storage.rb +3 -8
- data/api_examples/rest_api/put_files_uuid_metadata_key.rb +3 -7
- data/api_examples/rest_api/put_files_uuid_storage.rb +3 -5
- data/api_examples/rest_api/put_webhooks_id.rb +3 -11
- data/api_examples/support/example_helper.rb +250 -0
- data/api_examples/support/run_rest_example.rb +161 -0
- data/api_examples/support/run_upload_example.rb +88 -0
- data/api_examples/upload_api/get_from_url_status.rb +3 -5
- data/api_examples/upload_api/get_group_info.rb +3 -6
- data/api_examples/upload_api/get_info.rb +3 -6
- data/api_examples/upload_api/post_base.rb +3 -5
- data/api_examples/upload_api/post_from_url.rb +3 -5
- data/api_examples/upload_api/post_group.rb +3 -8
- data/api_examples/upload_api/post_multipart_complete.rb +3 -7
- data/api_examples/upload_api/post_multipart_start.rb +3 -7
- data/api_examples/upload_api/put_multipart_part.rb +4 -0
- data/bin/console +1 -1
- data/docs/release-notes-5.0.0.rc1.md +34 -0
- data/examples/README.md +39 -0
- data/examples/batch_upload.rb +54 -0
- data/examples/group_creation.rb +88 -0
- data/examples/large_file_upload.rb +88 -0
- data/examples/simple_upload.rb +39 -0
- data/examples/upload_with_progress.rb +84 -0
- data/examples/url_upload.rb +56 -0
- data/lib/uploadcare/api/rest/addons.rb +107 -0
- data/lib/uploadcare/api/rest/document_conversions.rb +65 -0
- data/lib/uploadcare/api/rest/file_metadata.rb +71 -0
- data/lib/uploadcare/api/rest/files.rb +112 -0
- data/lib/uploadcare/api/rest/groups.rb +49 -0
- data/lib/uploadcare/api/rest/project.rb +23 -0
- data/lib/uploadcare/api/rest/video_conversions.rb +52 -0
- data/lib/uploadcare/api/rest/webhooks.rb +74 -0
- data/lib/uploadcare/api/rest.rb +254 -0
- data/lib/uploadcare/api/upload/files.rb +313 -0
- data/lib/uploadcare/api/upload/groups.rb +72 -0
- data/lib/uploadcare/api/upload.rb +272 -0
- data/lib/uploadcare/client/addons_accessor.rb +85 -0
- data/lib/uploadcare/client/api.rb +33 -0
- data/lib/uploadcare/client/conversions_accessor.rb +33 -0
- data/lib/uploadcare/client/document_conversions_accessor.rb +41 -0
- data/lib/uploadcare/client/file_metadata_accessor.rb +46 -0
- data/lib/uploadcare/client/files_accessor.rb +82 -0
- data/lib/uploadcare/client/groups_accessor.rb +35 -0
- data/lib/uploadcare/client/project_accessor.rb +17 -0
- data/lib/uploadcare/client/video_conversions_accessor.rb +33 -0
- data/lib/uploadcare/client/webhooks_accessor.rb +42 -0
- data/lib/uploadcare/client.rb +127 -0
- data/lib/uploadcare/cname_generator.rb +68 -0
- data/lib/uploadcare/collections/batch_result.rb +35 -0
- data/lib/uploadcare/collections/paginated.rb +165 -0
- data/lib/uploadcare/configuration.rb +81 -0
- data/lib/uploadcare/exception/auth_error.rb +2 -6
- data/lib/uploadcare/exception/configuration_error.rb +4 -0
- data/lib/uploadcare/exception/conversion_error.rb +2 -6
- data/lib/uploadcare/exception/invalid_request_error.rb +4 -0
- data/lib/uploadcare/exception/multipart_upload_error.rb +4 -0
- data/lib/uploadcare/exception/not_found_error.rb +4 -0
- data/lib/uploadcare/exception/request_error.rb +2 -6
- data/lib/uploadcare/exception/retry_error.rb +2 -6
- data/lib/uploadcare/exception/throttle_error.rb +7 -11
- data/lib/uploadcare/exception/unknown_status_error.rb +4 -0
- data/lib/uploadcare/exception/upload_error.rb +4 -0
- data/lib/uploadcare/exception/upload_timeout_error.rb +4 -0
- data/lib/uploadcare/internal/authenticator.rb +101 -0
- data/lib/uploadcare/internal/error_handler.rb +102 -0
- data/lib/uploadcare/internal/signature_generator.rb +31 -0
- data/lib/uploadcare/internal/throttle_handler.rb +36 -0
- data/lib/uploadcare/internal/upload_io.rb +110 -0
- data/lib/uploadcare/internal/upload_params_generator.rb +86 -0
- data/lib/uploadcare/internal/user_agent.rb +22 -0
- data/lib/uploadcare/operations/multipart_upload.rb +213 -0
- data/lib/uploadcare/operations/upload_router.rb +162 -0
- data/lib/uploadcare/resources/addon_execution.rb +97 -0
- data/lib/uploadcare/resources/base_resource.rb +61 -0
- data/lib/uploadcare/resources/document_conversion.rb +81 -0
- data/lib/uploadcare/resources/file.rb +366 -0
- data/lib/uploadcare/resources/file_metadata.rb +135 -0
- data/lib/uploadcare/resources/group.rb +142 -0
- data/lib/uploadcare/resources/project.rb +26 -0
- data/lib/uploadcare/resources/video_conversion.rb +59 -0
- data/lib/uploadcare/resources/webhook.rb +85 -0
- data/lib/uploadcare/result.rb +85 -0
- data/lib/uploadcare/signed_url_generators/akamai_generator.rb +60 -56
- data/lib/uploadcare/signed_url_generators/base_generator.rb +15 -15
- data/lib/uploadcare/version.rb +7 -0
- data/lib/uploadcare/webhook_signature_verifier.rb +60 -0
- data/lib/uploadcare.rb +84 -50
- data/mise.toml +2 -0
- data/uploadcare-ruby.gemspec +8 -7
- metadata +102 -74
- data/api_examples/upload_api/put_presigned_url_x.rb +0 -8
- data/lib/uploadcare/api/api.rb +0 -25
- data/lib/uploadcare/client/addons_client.rb +0 -69
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +0 -59
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +0 -45
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +0 -46
- data/lib/uploadcare/client/file_client.rb +0 -48
- data/lib/uploadcare/client/file_list_client.rb +0 -46
- data/lib/uploadcare/client/file_metadata_client.rb +0 -36
- data/lib/uploadcare/client/group_client.rb +0 -45
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +0 -58
- data/lib/uploadcare/client/multipart_upload_client.rb +0 -64
- data/lib/uploadcare/client/project_client.rb +0 -20
- data/lib/uploadcare/client/rest_client.rb +0 -77
- data/lib/uploadcare/client/rest_group_client.rb +0 -43
- data/lib/uploadcare/client/upload_client.rb +0 -46
- data/lib/uploadcare/client/uploader_client.rb +0 -128
- data/lib/uploadcare/client/webhook_client.rb +0 -49
- data/lib/uploadcare/concern/error_handler.rb +0 -54
- data/lib/uploadcare/concern/throttle_handler.rb +0 -25
- data/lib/uploadcare/concern/upload_error_handler.rb +0 -32
- data/lib/uploadcare/entity/addons.rb +0 -14
- data/lib/uploadcare/entity/conversion/base_converter.rb +0 -43
- data/lib/uploadcare/entity/conversion/document_converter.rb +0 -15
- data/lib/uploadcare/entity/conversion/video_converter.rb +0 -15
- data/lib/uploadcare/entity/decorator/paginator.rb +0 -79
- data/lib/uploadcare/entity/entity.rb +0 -18
- data/lib/uploadcare/entity/file.rb +0 -103
- data/lib/uploadcare/entity/file_list.rb +0 -32
- data/lib/uploadcare/entity/file_metadata.rb +0 -30
- data/lib/uploadcare/entity/group.rb +0 -49
- data/lib/uploadcare/entity/group_list.rb +0 -24
- data/lib/uploadcare/entity/project.rb +0 -13
- data/lib/uploadcare/entity/uploader.rb +0 -93
- data/lib/uploadcare/entity/webhook.rb +0 -14
- data/lib/uploadcare/param/authentication_header.rb +0 -37
- data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +0 -39
- data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +0 -64
- data/lib/uploadcare/param/param.rb +0 -10
- data/lib/uploadcare/param/secure_auth_header.rb +0 -51
- data/lib/uploadcare/param/simple_auth_header.rb +0 -14
- data/lib/uploadcare/param/upload/signature_generator.rb +0 -24
- data/lib/uploadcare/param/upload/upload_params_generator.rb +0 -41
- data/lib/uploadcare/param/user_agent.rb +0 -21
- data/lib/uploadcare/param/webhook_signature_verifier.rb +0 -23
- data/lib/uploadcare/ruby/version.rb +0 -5
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'rest_client'
|
|
4
|
-
|
|
5
|
-
module Uploadcare
|
|
6
|
-
module Client
|
|
7
|
-
# client for webhook management
|
|
8
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Webhook
|
|
9
|
-
class WebhookClient < RestClient
|
|
10
|
-
# Create webhook
|
|
11
|
-
# @see https://uploadcare.com/docs/api_reference/rest/webhooks/#subscribe
|
|
12
|
-
def create(options = {})
|
|
13
|
-
body = {
|
|
14
|
-
target_url: options[:target_url],
|
|
15
|
-
event: options[:event] || 'file.uploaded',
|
|
16
|
-
is_active: options[:is_active].nil? ? true : options[:is_active]
|
|
17
|
-
}.merge(
|
|
18
|
-
{ signing_secret: options[:signing_secret] }.compact
|
|
19
|
-
).to_json
|
|
20
|
-
post(uri: '/webhooks/', content: body)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Returns array (not paginated list) of webhooks
|
|
24
|
-
# @see https://uploadcare.com/docs/api_reference/rest/webhooks/#get-list
|
|
25
|
-
def list
|
|
26
|
-
get(uri: '/webhooks/')
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Permanently deletes subscription
|
|
30
|
-
# @see https://uploadcare.com/docs/api_reference/rest/webhooks/#unsubscribe
|
|
31
|
-
def delete(target_url)
|
|
32
|
-
body = { target_url: target_url }.to_json
|
|
33
|
-
request(method: 'DELETE', uri: '/webhooks/unsubscribe/', content: body)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Updates webhook
|
|
37
|
-
# @see https://uploadcare.com/docs/api_reference/rest/webhooks/#subscribe-update
|
|
38
|
-
def update(id, options = {})
|
|
39
|
-
body = options.to_json
|
|
40
|
-
put(uri: "/webhooks/#{id}/", content: body)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
alias create_webhook create
|
|
44
|
-
alias list_webhooks list
|
|
45
|
-
alias delete_webhook delete
|
|
46
|
-
alias update_webhook update
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Concerns
|
|
5
|
-
# Wrapper for responses
|
|
6
|
-
# raises errors instead of returning monads
|
|
7
|
-
module ErrorHandler
|
|
8
|
-
include Exception
|
|
9
|
-
|
|
10
|
-
# Extension of ApiStruct's failure method
|
|
11
|
-
#
|
|
12
|
-
# Raises errors instead of returning falsey objects
|
|
13
|
-
# @see https://github.com/rubygarage/api_struct/blob/master/lib/api_struct/client.rb#L55
|
|
14
|
-
def failure(response)
|
|
15
|
-
catch_upload_errors(response)
|
|
16
|
-
parsed_response = JSON.parse(response.body.to_s)
|
|
17
|
-
raise RequestError, parsed_response['detail'] || parsed_response.map { |k, v| "#{k}: #{v}" }.join('; ')
|
|
18
|
-
rescue JSON::ParserError
|
|
19
|
-
raise RequestError, response.body.to_s
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Extension of ApiStruct's wrap method
|
|
23
|
-
#
|
|
24
|
-
# Catches throttling errors and Upload API errors
|
|
25
|
-
#
|
|
26
|
-
# @see https://github.com/rubygarage/api_struct/blob/master/lib/api_struct/client.rb#L45
|
|
27
|
-
def wrap(response)
|
|
28
|
-
raise_throttling_error(response) if response.status == 429
|
|
29
|
-
return failure(response) if response.status >= 300
|
|
30
|
-
|
|
31
|
-
catch_upload_errors(response)
|
|
32
|
-
success(response)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
# Raise ThrottleError. Also, tells in error when server will be ready for next request
|
|
38
|
-
def raise_throttling_error(response)
|
|
39
|
-
retry_after = (response.headers['Retry-After'].to_i + 1) || 11
|
|
40
|
-
raise ThrottleError.new(retry_after), "Response throttled, retry #{retry_after} seconds later"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Upload API returns its errors with code 200, and stores its actual code and details within response message
|
|
44
|
-
# This methods detects that and raises apropriate error
|
|
45
|
-
def catch_upload_errors(response)
|
|
46
|
-
return unless response.code == 200
|
|
47
|
-
|
|
48
|
-
parsed_response = JSON.parse(response.body.to_s)
|
|
49
|
-
error = parsed_response['error'] if parsed_response.is_a?(Hash)
|
|
50
|
-
raise RequestError, error if error
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Concerns
|
|
5
|
-
# This module lets clients send request multiple times if request is throttled
|
|
6
|
-
module ThrottleHandler
|
|
7
|
-
# call given block. If ThrottleError is returned, it will wait and attempt again 4 more times
|
|
8
|
-
# @yield executable block (HTTP request that may be throttled)
|
|
9
|
-
def handle_throttling
|
|
10
|
-
(Uploadcare.config.max_throttle_attempts - 1).times do
|
|
11
|
-
# rubocop:disable Style/RedundantBegin
|
|
12
|
-
begin
|
|
13
|
-
return yield
|
|
14
|
-
rescue(Exception::ThrottleError) => e
|
|
15
|
-
wait_time = e.timeout
|
|
16
|
-
sleep(wait_time)
|
|
17
|
-
next
|
|
18
|
-
end
|
|
19
|
-
# rubocop:enable Style/RedundantBegin
|
|
20
|
-
end
|
|
21
|
-
yield
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Concerns
|
|
5
|
-
# Wrapper for responses
|
|
6
|
-
# raises errors instead of returning monads
|
|
7
|
-
module UploadErrorHandler
|
|
8
|
-
include Exception
|
|
9
|
-
|
|
10
|
-
# Extension of ApiStruct's failure method
|
|
11
|
-
#
|
|
12
|
-
# Raises errors instead of returning falsey objects
|
|
13
|
-
# @see https://github.com/rubygarage/api_struct/blob/master/lib/api_struct/client.rb#L55
|
|
14
|
-
def failure(response)
|
|
15
|
-
catch_throttling_error(response)
|
|
16
|
-
parsed_response = JSON.parse(response.body.to_s)
|
|
17
|
-
raise RequestError, parsed_response['detail']
|
|
18
|
-
rescue JSON::ParserError
|
|
19
|
-
raise RequestError, response.status
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def catch_throttling_error(response)
|
|
25
|
-
return unless response.code == 429
|
|
26
|
-
|
|
27
|
-
retry_after = (response.headers['Retry-After'].to_i + 1) || 11
|
|
28
|
-
raise ThrottleError.new(retry_after), "Response throttled, retry #{retry_after} seconds later"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
# This serializer is responsible for addons handling
|
|
6
|
-
#
|
|
7
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons
|
|
8
|
-
class Addons < Entity
|
|
9
|
-
client_service AddonsClient
|
|
10
|
-
|
|
11
|
-
attr_entity :request_id, :status, :result
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
module Conversion
|
|
6
|
-
# This serializer lets a user convert uploaded documents
|
|
7
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/documentConvert
|
|
8
|
-
class BaseConverter < Entity
|
|
9
|
-
class << self
|
|
10
|
-
# Converts files
|
|
11
|
-
#
|
|
12
|
-
# @param params [Array] of hashes with params or [Hash]
|
|
13
|
-
# @option options [Boolean] :store whether to store file on servers.
|
|
14
|
-
def convert(params, options = {})
|
|
15
|
-
files_params = params.is_a?(Hash) ? [params] : params
|
|
16
|
-
conversion_client.new.convert_many(files_params, options)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Returns a status of a conversion job
|
|
20
|
-
#
|
|
21
|
-
# @param token [Integer, String] token obtained from a server in convert method
|
|
22
|
-
def status(token)
|
|
23
|
-
conversion_client.new.get_conversion_status(token)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Returns the document format and possible conversion formats.
|
|
27
|
-
#
|
|
28
|
-
# @param uuid [String] UUID of the document
|
|
29
|
-
def info(uuid)
|
|
30
|
-
conversion_client.new.document_info(uuid)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def conversion_client
|
|
36
|
-
clients[:base]
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
include Conversion
|
|
43
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'base_converter'
|
|
4
|
-
|
|
5
|
-
module Uploadcare
|
|
6
|
-
module Entity
|
|
7
|
-
module Conversion
|
|
8
|
-
# This serializer lets a user convert uploaded documents
|
|
9
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/documentConvert
|
|
10
|
-
class DocumentConverter < BaseConverter
|
|
11
|
-
client_service Client::Conversion::DocumentConversionClient
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'base_converter'
|
|
4
|
-
|
|
5
|
-
module Uploadcare
|
|
6
|
-
module Entity
|
|
7
|
-
module Conversion
|
|
8
|
-
# This serializer lets a user convert uploaded videos, and usually returns an array of results
|
|
9
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/videoConvert
|
|
10
|
-
class VideoConverter < BaseConverter
|
|
11
|
-
client_service Client::Conversion::VideoConversionClient
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
# @abstract
|
|
6
|
-
module Decorator
|
|
7
|
-
# provides pagination methods for things in Uploadcare that paginate,
|
|
8
|
-
# namely [FileList] and [Group]
|
|
9
|
-
#
|
|
10
|
-
# Requirements:
|
|
11
|
-
# - Should be Entity with Client
|
|
12
|
-
# - Associated Client should have `list` method that returns objects with pagination
|
|
13
|
-
# - Response should have :next, :previous, :total, :per_page params and :results fields
|
|
14
|
-
module Paginator
|
|
15
|
-
@entity ||= Hashie::Mash.new
|
|
16
|
-
|
|
17
|
-
# meta data of a pagination object
|
|
18
|
-
def meta
|
|
19
|
-
Hashie::Mash.new(next: @entity[:next], previous: @entity[:previous],
|
|
20
|
-
total: @entity[:total], per_page: @entity[:per_page])
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Returns new instance of current object on next page
|
|
24
|
-
def next_page
|
|
25
|
-
url = @entity[:next]
|
|
26
|
-
return unless url
|
|
27
|
-
|
|
28
|
-
query = URI.decode_www_form(URI(url).query).to_h
|
|
29
|
-
query = query.to_h { |k, v| [k.to_sym, v] }
|
|
30
|
-
self.class.list(**query)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Returns new instance of current object on previous page
|
|
34
|
-
def previous_page
|
|
35
|
-
url = @entity[:previous]
|
|
36
|
-
return unless url
|
|
37
|
-
|
|
38
|
-
query = URI.decode_www_form(URI(url).query).to_h
|
|
39
|
-
query = query.to_h { |k, v| [k.to_sym, v] }
|
|
40
|
-
self.class.list(**query)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Attempts to load the entire list after offset into results of current object
|
|
44
|
-
#
|
|
45
|
-
# It's possible to avoid loading objects on previous pages by offsetting them first
|
|
46
|
-
def load
|
|
47
|
-
return self if @entity[:next].nil? || @entity[:results].length == @entity[:total]
|
|
48
|
-
|
|
49
|
-
np = self
|
|
50
|
-
until np.next.nil?
|
|
51
|
-
np = np.next_page
|
|
52
|
-
@entity[:results].concat(np.results.map(&:to_h))
|
|
53
|
-
end
|
|
54
|
-
@entity[:next] = nil
|
|
55
|
-
@entity[:per_page] = @entity[:total]
|
|
56
|
-
self
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# iterate through pages, starting with current one
|
|
60
|
-
#
|
|
61
|
-
# @yield [Block]
|
|
62
|
-
def each(&block)
|
|
63
|
-
current_page = self
|
|
64
|
-
while current_page
|
|
65
|
-
current_page.results.each(&block)
|
|
66
|
-
current_page = current_page.next_page
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Load and return all objects in list
|
|
71
|
-
#
|
|
72
|
-
# @return [Array]
|
|
73
|
-
def all
|
|
74
|
-
load[:results]
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
Gem.find_files('client/**/*.rb').each { |path| require path }
|
|
4
|
-
|
|
5
|
-
module Uploadcare
|
|
6
|
-
# Entities represent objects existing in Uploadcare cloud
|
|
7
|
-
#
|
|
8
|
-
# Typically, Entities inherit class methods from {Client} instance methods
|
|
9
|
-
# @see Client
|
|
10
|
-
module Entity
|
|
11
|
-
# @abstract
|
|
12
|
-
class Entity < ApiStruct::Entity
|
|
13
|
-
include Client
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
include Entity
|
|
18
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
# This serializer returns a single file
|
|
6
|
-
#
|
|
7
|
-
# @see https://uploadcare.com/docs/api_reference/rest/handling_projects/
|
|
8
|
-
class File < Entity
|
|
9
|
-
RESPONSE_PARAMS = %i[
|
|
10
|
-
datetime_removed datetime_stored datetime_uploaded is_image is_ready mime_type original_file_url
|
|
11
|
-
original_filename size url uuid variations content_info metadata appdata source
|
|
12
|
-
].freeze
|
|
13
|
-
|
|
14
|
-
client_service FileClient
|
|
15
|
-
|
|
16
|
-
attr_entity(*RESPONSE_PARAMS)
|
|
17
|
-
|
|
18
|
-
def datetime_stored
|
|
19
|
-
Uploadcare.config.logger&.warn 'datetime_stored property has been deprecated, and will be removed without a replacement in future.' # rubocop:disable Layout/LineLength
|
|
20
|
-
@entity.datetime_stored
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# gets file's uuid - even if it's only initialized with url
|
|
24
|
-
# @returns [String]
|
|
25
|
-
def uuid
|
|
26
|
-
return @entity.uuid if @entity.uuid
|
|
27
|
-
|
|
28
|
-
uuid = @entity.url.gsub('https://ucarecdn.com/', '')
|
|
29
|
-
uuid.gsub(%r{/.*}, '')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# loads file metadata, if it's initialized with url or uuid
|
|
33
|
-
def load
|
|
34
|
-
initialize(File.info(uuid).entity)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# The method to convert a document file to another file
|
|
38
|
-
# gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class]
|
|
39
|
-
# @returns [File]
|
|
40
|
-
def convert_document(params = {}, options = {}, converter = Conversion::DocumentConverter)
|
|
41
|
-
convert_file(params, converter, options)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# The method to convert a video file to another file
|
|
45
|
-
# gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class]
|
|
46
|
-
# @returns [File]
|
|
47
|
-
def convert_video(params = {}, options = {}, converter = Conversion::VideoConverter)
|
|
48
|
-
convert_file(params, converter, options)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Copies file to current project
|
|
52
|
-
#
|
|
53
|
-
# source can be UID or full CDN link
|
|
54
|
-
#
|
|
55
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createLocalCopy
|
|
56
|
-
def self.local_copy(source, args = {})
|
|
57
|
-
response = FileClient.new.local_copy(source: source, **args).success[:result]
|
|
58
|
-
File.new(response)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# copy file to different project
|
|
62
|
-
#
|
|
63
|
-
# source can be UID or full CDN link
|
|
64
|
-
#
|
|
65
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createRemoteCopy
|
|
66
|
-
def self.remote_copy(source, target, args = {})
|
|
67
|
-
FileClient.new.remote_copy(source: source, target: target, **args).success[:result]
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Instance version of {internal_copy}
|
|
71
|
-
def local_copy(args = {})
|
|
72
|
-
File.local_copy(uuid, **args)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Instance version of {external_copy}
|
|
76
|
-
def remote_copy(target, args = {})
|
|
77
|
-
File.remote_copy(uuid, target, **args)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Store a single file, preventing it from being deleted in 2 weeks
|
|
81
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/storeFile
|
|
82
|
-
def store
|
|
83
|
-
File.store(uuid)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/deleteFileStorage
|
|
87
|
-
def delete
|
|
88
|
-
File.delete(uuid)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
private
|
|
92
|
-
|
|
93
|
-
def convert_file(params, converter, options = {})
|
|
94
|
-
raise Uploadcare::Exception::ConversionError, 'The first argument must be a Hash' unless params.is_a?(Hash)
|
|
95
|
-
|
|
96
|
-
params_with_symbolized_keys = params.to_h { |k, v| [k.to_sym, v] }
|
|
97
|
-
params_with_symbolized_keys[:uuid] = uuid
|
|
98
|
-
result = converter.convert(params_with_symbolized_keys, options)
|
|
99
|
-
result.success? ? File.info(result.value![:result].first[:uuid]) : result
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'uploadcare/entity/file'
|
|
4
|
-
require 'uploadcare/entity/decorator/paginator'
|
|
5
|
-
require 'dry/monads'
|
|
6
|
-
require 'api_struct'
|
|
7
|
-
|
|
8
|
-
module Uploadcare
|
|
9
|
-
module Entity
|
|
10
|
-
# This serializer returns lists of files
|
|
11
|
-
#
|
|
12
|
-
# This is a paginated list, so all pagination methods apply
|
|
13
|
-
# @see Uploadcare::Entity::Decorator::Paginator
|
|
14
|
-
class FileList < ApiStruct::Entity
|
|
15
|
-
include Uploadcare::Entity::Decorator::Paginator
|
|
16
|
-
client_service Client::FileListClient
|
|
17
|
-
|
|
18
|
-
attr_entity :next, :previous, :total, :per_page
|
|
19
|
-
|
|
20
|
-
has_entities :results, as: Uploadcare::Entity::File
|
|
21
|
-
has_entities :result, as: Uploadcare::Entity::File
|
|
22
|
-
|
|
23
|
-
# alias for result/results, depending on which API this FileList was initialized from
|
|
24
|
-
# @return [Array] of [Uploadcare::Entity::File]
|
|
25
|
-
def files
|
|
26
|
-
results
|
|
27
|
-
rescue ApiStruct::EntityError
|
|
28
|
-
result
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
# This serializer is responsible for file metadata handling
|
|
6
|
-
#
|
|
7
|
-
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-metadata
|
|
8
|
-
class FileMetadata < Entity
|
|
9
|
-
client_service FileMetadataClient
|
|
10
|
-
|
|
11
|
-
class << self
|
|
12
|
-
def index(uuid)
|
|
13
|
-
::Uploadcare::Client::FileMetadataClient.new.index(uuid).success
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def show(uuid, key)
|
|
17
|
-
::Uploadcare::Client::FileMetadataClient.new.show(uuid, key).success
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def update(uuid, key, value)
|
|
21
|
-
::Uploadcare::Client::FileMetadataClient.new.update(uuid, key, value).success
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def delete(uuid, key)
|
|
25
|
-
::Uploadcare::Client::FileMetadataClient.new.delete(uuid, key).success || '200 OK'
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'uploadcare/entity/file'
|
|
4
|
-
|
|
5
|
-
module Uploadcare
|
|
6
|
-
module Entity
|
|
7
|
-
# Groups serve a purpose of better organizing files in your Uploadcare projects.
|
|
8
|
-
#
|
|
9
|
-
# You can create one from a set of files by using their UUIDs.
|
|
10
|
-
#
|
|
11
|
-
# @see https://uploadcare.com/docs/api_reference/upload/groups/
|
|
12
|
-
class Group < Entity
|
|
13
|
-
client_service RestGroupClient, prefix: 'rest', only: %i[store info delete]
|
|
14
|
-
client_service GroupClient
|
|
15
|
-
|
|
16
|
-
attr_entity :id, :datetime_created, :datetime_stored, :files_count, :cdn_url, :url
|
|
17
|
-
has_entities :files, as: Uploadcare::Entity::File
|
|
18
|
-
|
|
19
|
-
# Remove these lines and bump api_struct version when this PR is accepted:
|
|
20
|
-
# @see https://github.com/rubygarage/api_struct/pull/15
|
|
21
|
-
def self.store(uuid)
|
|
22
|
-
rest_store(uuid).success || '200 OK'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Get a file group by its ID.
|
|
26
|
-
def self.group_info(uuid)
|
|
27
|
-
rest_info(uuid)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def self.delete(uuid)
|
|
31
|
-
rest_delete(uuid).success || '200 OK'
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# gets groups's id - even if it's only initialized with cdn_url
|
|
35
|
-
# @return [String]
|
|
36
|
-
def id
|
|
37
|
-
return @entity.id if @entity.id
|
|
38
|
-
|
|
39
|
-
id = @entity.cdn_url.gsub('https://ucarecdn.com/', '')
|
|
40
|
-
id.gsub(%r{/.*}, '')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# loads group metadata, if it's initialized with url or id
|
|
44
|
-
def load
|
|
45
|
-
initialize(Group.info(id).entity)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'uploadcare/entity/group'
|
|
4
|
-
require 'uploadcare/entity/decorator/paginator'
|
|
5
|
-
|
|
6
|
-
module Uploadcare
|
|
7
|
-
module Entity
|
|
8
|
-
# List of groups
|
|
9
|
-
#
|
|
10
|
-
# @see https://uploadcare.com/docs/api_reference/upload/groups/
|
|
11
|
-
#
|
|
12
|
-
# This is a paginated list, so all pagination methods apply
|
|
13
|
-
# @see Uploadcare::Entity::Decorator::Paginator
|
|
14
|
-
class GroupList < Entity
|
|
15
|
-
include Uploadcare::Entity::Decorator::Paginator
|
|
16
|
-
client_service RestGroupClient, only: :list
|
|
17
|
-
|
|
18
|
-
attr_entity :next, :previous, :total, :per_page, :results
|
|
19
|
-
has_entities :results, as: Group
|
|
20
|
-
|
|
21
|
-
alias groups results
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Uploadcare
|
|
4
|
-
module Entity
|
|
5
|
-
# This serializer returns info about a project and its data
|
|
6
|
-
# @see https://uploadcare.com/docs/api_reference/rest/handling_projects/
|
|
7
|
-
class Project < Entity
|
|
8
|
-
client_service ProjectClient
|
|
9
|
-
|
|
10
|
-
attr_entity :collaborators, :pub_key, :name, :autostore_enabled
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|