uploadcare-ruby 2.1.2 → 3.1.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 +4 -4
- data/.github/workflows/gem-push.yml +20 -0
- data/.github/workflows/ruby.yml +52 -0
- data/.gitignore +13 -6
- data/.rspec +2 -0
- data/.rubocop.yml +33 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +29 -47
- data/DEVELOPMENT.md +18 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +433 -527
- data/Rakefile +5 -5
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/uploadcare/api/api.rb +25 -0
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +59 -0
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +41 -0
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +46 -0
- data/lib/uploadcare/client/file_client.rb +44 -0
- data/lib/uploadcare/client/file_list_client.rb +46 -0
- data/lib/uploadcare/client/group_client.rb +45 -0
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +57 -0
- data/lib/uploadcare/client/multipart_upload_client.rb +64 -0
- data/lib/uploadcare/client/project_client.rb +18 -0
- data/lib/uploadcare/client/rest_client.rb +74 -0
- data/lib/uploadcare/client/rest_group_client.rb +23 -0
- data/lib/uploadcare/client/upload_client.rb +43 -0
- data/lib/uploadcare/client/uploader_client.rb +101 -0
- data/lib/uploadcare/client/webhook_client.rb +47 -0
- data/lib/uploadcare/concern/error_handler.rb +54 -0
- data/lib/uploadcare/concern/throttle_handler.rb +25 -0
- data/lib/uploadcare/concern/upload_error_handler.rb +32 -0
- data/lib/uploadcare/entity/conversion/base_converter.rb +36 -0
- data/lib/uploadcare/entity/conversion/document_converter.rb +15 -0
- data/lib/uploadcare/entity/conversion/video_converter.rb +15 -0
- data/lib/uploadcare/entity/decorator/paginator.rb +79 -0
- data/lib/uploadcare/entity/entity.rb +18 -0
- data/lib/uploadcare/entity/file.rb +106 -0
- data/lib/uploadcare/entity/file_list.rb +31 -0
- data/lib/uploadcare/entity/group.rb +40 -0
- data/lib/uploadcare/entity/group_list.rb +24 -0
- data/lib/uploadcare/entity/project.rb +13 -0
- data/lib/uploadcare/entity/uploader.rb +81 -0
- data/lib/uploadcare/entity/webhook.rb +14 -0
- data/lib/uploadcare/exception/conversion_error.rb +8 -0
- data/lib/uploadcare/exception/request_error.rb +9 -0
- data/lib/uploadcare/exception/throttle_error.rb +16 -0
- data/lib/uploadcare/param/authentication_header.rb +25 -0
- data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +39 -0
- data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +64 -0
- data/lib/uploadcare/param/param.rb +10 -0
- data/lib/uploadcare/param/secure_auth_header.rb +37 -0
- data/lib/uploadcare/param/simple_auth_header.rb +14 -0
- data/lib/uploadcare/param/upload/signature_generator.rb +24 -0
- data/lib/uploadcare/param/upload/upload_params_generator.rb +23 -0
- data/lib/uploadcare/param/user_agent.rb +21 -0
- data/lib/uploadcare/ruby/version.rb +5 -0
- data/lib/uploadcare.rb +36 -32
- data/uploadcare-ruby.gemspec +50 -37
- metadata +107 -113
- data/.travis.yml +0 -26
- data/UPGRADE_NOTES.md +0 -36
- data/lib/uploadcare/api/file_api.rb +0 -7
- data/lib/uploadcare/api/file_list_api.rb +0 -19
- data/lib/uploadcare/api/file_storage_api.rb +0 -34
- data/lib/uploadcare/api/group_api.rb +0 -38
- data/lib/uploadcare/api/group_list_api.rb +0 -17
- data/lib/uploadcare/api/project_api.rb +0 -9
- data/lib/uploadcare/api/raw_api.rb +0 -38
- data/lib/uploadcare/api/uploading_api/upload_params.rb +0 -72
- data/lib/uploadcare/api/uploading_api.rb +0 -71
- data/lib/uploadcare/api/validators/file_list_options_validator.rb +0 -73
- data/lib/uploadcare/api/validators/group_list_options_validator.rb +0 -49
- data/lib/uploadcare/api.rb +0 -26
- data/lib/uploadcare/errors/errors.rb +0 -64
- data/lib/uploadcare/resources/file.rb +0 -164
- data/lib/uploadcare/resources/file_list.rb +0 -14
- data/lib/uploadcare/resources/group.rb +0 -115
- data/lib/uploadcare/resources/group_list.rb +0 -14
- data/lib/uploadcare/resources/project.rb +0 -13
- data/lib/uploadcare/resources/resource_list.rb +0 -83
- data/lib/uploadcare/rest/auth/auth.rb +0 -31
- data/lib/uploadcare/rest/auth/secure.rb +0 -43
- data/lib/uploadcare/rest/auth/simple.rb +0 -16
- data/lib/uploadcare/rest/connections/api_connection.rb +0 -53
- data/lib/uploadcare/rest/connections/upload_connection.rb +0 -22
- data/lib/uploadcare/rest/middlewares/auth_middleware.rb +0 -24
- data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +0 -33
- data/lib/uploadcare/rest/middlewares/raise_error_middleware.rb +0 -21
- data/lib/uploadcare/utils/parser.rb +0 -71
- data/lib/uploadcare/utils/user_agent.rb +0 -44
- data/lib/uploadcare/version.rb +0 -3
- data/spec/api/file_list_api_spec.rb +0 -95
- data/spec/api/file_storage_api_spec.rb +0 -88
- data/spec/api/group_list_api_spec.rb +0 -59
- data/spec/api/raw_api_spec.rb +0 -25
- data/spec/api/uploading_api/upload_params_spec.rb +0 -99
- data/spec/api/uploading_api_spec.rb +0 -59
- data/spec/resources/file_list_spec.rb +0 -25
- data/spec/resources/file_spec.rb +0 -223
- data/spec/resources/group_list_spec.rb +0 -25
- data/spec/resources/group_spec.rb +0 -101
- data/spec/resources/operations_spec.rb +0 -59
- data/spec/resources/project_spec.rb +0 -21
- data/spec/rest/api_connection_spec.rb +0 -68
- data/spec/rest/auth/secure_spec.rb +0 -66
- data/spec/rest/auth/simple_spec.rb +0 -31
- data/spec/rest/errors_spec.rb +0 -75
- data/spec/rest/upload_connection_spec.rb +0 -19
- data/spec/shared/resource_list.rb +0 -188
- data/spec/spec_helper.rb +0 -54
- data/spec/uploadcare_spec.rb +0 -43
- data/spec/utils/parser_spec.rb +0 -85
- data/spec/utils/user_agent_spec.rb +0 -46
- data/spec/view.png +0 -0
- data/spec/view2.jpg +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Entity
|
|
5
|
+
# This serializer lets user upload files by various means, and usually returns an array of files
|
|
6
|
+
# @see https://uploadcare.com/api-refs/upload-api/#tag/Upload
|
|
7
|
+
class Uploader < Entity
|
|
8
|
+
client_service UploaderClient
|
|
9
|
+
client_service MultipartUploaderClient, only: :upload, prefix: :multipart
|
|
10
|
+
|
|
11
|
+
attr_entity :files
|
|
12
|
+
has_entities :files, as: Uploadcare::Entity::File
|
|
13
|
+
|
|
14
|
+
# Upload file or group of files from array, File, or url
|
|
15
|
+
#
|
|
16
|
+
# @param object [Array], [String] or [File]
|
|
17
|
+
# @param [Hash] options options for upload
|
|
18
|
+
# @option options [Boolean] :store (false) whether to store file on servers.
|
|
19
|
+
def self.upload(object, **options)
|
|
20
|
+
if big_file?(object)
|
|
21
|
+
multipart_upload(object, **options)
|
|
22
|
+
elsif file?(object)
|
|
23
|
+
upload_file(object, **options)
|
|
24
|
+
elsif object.is_a?(Array)
|
|
25
|
+
upload_files(object, **options)
|
|
26
|
+
elsif object.is_a?(String)
|
|
27
|
+
upload_from_url(object, **options)
|
|
28
|
+
else
|
|
29
|
+
raise ArgumentError, "Expected input to be a file/Array/URL, given: `#{object}`"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# upload single file
|
|
34
|
+
def self.upload_file(file, **options)
|
|
35
|
+
response = UploaderClient.new.upload_many([file], **options)
|
|
36
|
+
Uploadcare::Entity::File.info(response.success.to_a.flatten[-1])
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# upload multiple files
|
|
40
|
+
def self.upload_files(arr, **options)
|
|
41
|
+
response = UploaderClient.new.upload_many(arr, **options)
|
|
42
|
+
response.success.map { |pair| Uploadcare::Entity::File.new(uuid: pair[1], original_filename: pair[0]) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# upload file of size above 10mb (involves multipart upload)
|
|
46
|
+
def self.multipart_upload(file, **options, &block)
|
|
47
|
+
response = MultipartUploaderClient.new.upload(file, **options, &block)
|
|
48
|
+
Uploadcare::Entity::File.new(response.success)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# upload files from url
|
|
52
|
+
# @param url [String]
|
|
53
|
+
def self.upload_from_url(url, **options)
|
|
54
|
+
response = UploaderClient.new.upload_from_url(url, **options)
|
|
55
|
+
return response.success[:token] unless response.success[:files]
|
|
56
|
+
|
|
57
|
+
response.success[:files].map { |file_data| Uploadcare::Entity::File.new(file_data) }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# gets a status of upload from url
|
|
61
|
+
# @param url [String]
|
|
62
|
+
def self.get_upload_from_url_status(token)
|
|
63
|
+
UploaderClient.new.get_upload_from_url_status(token)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class << self
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# check if object is a file
|
|
70
|
+
def file?(object)
|
|
71
|
+
object.respond_to?(:path) && ::File.exist?(object.path)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# check if object needs to be uploaded using multipart upload
|
|
75
|
+
def big_file?(object)
|
|
76
|
+
file?(object) && object.size >= Uploadcare.config.multipart_size_threshold
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Entity
|
|
5
|
+
# This serializer is responsible for webhook handling
|
|
6
|
+
#
|
|
7
|
+
# @see https://uploadcare.com/docs/api_reference/rest/webhooks/
|
|
8
|
+
class Webhook < Entity
|
|
9
|
+
client_service WebhookClient
|
|
10
|
+
|
|
11
|
+
attr_entity :id, :created, :updated, :event, :target_url, :project, :is_active
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Exception
|
|
5
|
+
# Exception for throttled requests
|
|
6
|
+
class ThrottleError < StandardError
|
|
7
|
+
attr_reader :timeout
|
|
8
|
+
|
|
9
|
+
# @param timeout [Float] Amount of seconds the request have been throttled for
|
|
10
|
+
def initialize(timeout = 10.0)
|
|
11
|
+
super
|
|
12
|
+
@timeout = timeout
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest/md5'
|
|
4
|
+
require 'param/secure_auth_header'
|
|
5
|
+
require 'param/simple_auth_header'
|
|
6
|
+
|
|
7
|
+
module Uploadcare
|
|
8
|
+
module Param
|
|
9
|
+
# This object returns headers needed for authentication
|
|
10
|
+
# This authentication method is more secure, but more tedious
|
|
11
|
+
class AuthenticationHeader
|
|
12
|
+
# @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare
|
|
13
|
+
def self.call(**options)
|
|
14
|
+
case Uploadcare.config.auth_type
|
|
15
|
+
when 'Uploadcare'
|
|
16
|
+
SecureAuthHeader.call(**options)
|
|
17
|
+
when 'Uploadcare.Simple'
|
|
18
|
+
SimpleAuthHeader.call
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError, "Unknown auth_scheme: '#{Uploadcare.config.auth_type}'"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Param
|
|
5
|
+
module Conversion
|
|
6
|
+
module Document
|
|
7
|
+
class ProcessingJobUrlBuilder
|
|
8
|
+
class << self
|
|
9
|
+
def call(uuid:, format: nil, page: nil)
|
|
10
|
+
[
|
|
11
|
+
uuid_part(uuid),
|
|
12
|
+
format_part(format),
|
|
13
|
+
page_part(page)
|
|
14
|
+
].compact.join('-')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def uuid_part(uuid)
|
|
20
|
+
"#{uuid}/document/"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def format_part(format)
|
|
24
|
+
return if format.nil?
|
|
25
|
+
|
|
26
|
+
"/format/#{format}/"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def page_part(page)
|
|
30
|
+
return if page.nil?
|
|
31
|
+
|
|
32
|
+
"/page/#{page}/"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Param
|
|
5
|
+
module Conversion
|
|
6
|
+
module Video
|
|
7
|
+
class ProcessingJobUrlBuilder
|
|
8
|
+
class << self
|
|
9
|
+
# rubocop:disable Metrics/ParameterLists
|
|
10
|
+
def call(uuid:, size: {}, quality: nil, format: nil, cut: {}, thumbs: {})
|
|
11
|
+
[
|
|
12
|
+
uuid_part(uuid),
|
|
13
|
+
size_part(size),
|
|
14
|
+
quality_part(quality),
|
|
15
|
+
format_part(format),
|
|
16
|
+
cut_part(cut),
|
|
17
|
+
thumbs_part(thumbs)
|
|
18
|
+
].compact.join('-')
|
|
19
|
+
end
|
|
20
|
+
# rubocop:enable Metrics/ParameterLists
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def uuid_part(uuid)
|
|
25
|
+
"#{uuid}/video/"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def size_part(size)
|
|
29
|
+
return if size.empty?
|
|
30
|
+
|
|
31
|
+
dimensions = "#{size[:width]}x#{size[:height]}" if size[:width] || size[:height]
|
|
32
|
+
resize_mode = (size[:resize_mode]).to_s
|
|
33
|
+
"/size/#{dimensions}/#{resize_mode}/".squeeze('/')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def quality_part(quality)
|
|
37
|
+
return if quality.nil?
|
|
38
|
+
|
|
39
|
+
"/quality/#{quality}/"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def format_part(format)
|
|
43
|
+
return if format.nil?
|
|
44
|
+
|
|
45
|
+
"/format/#{format}/"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def cut_part(cut)
|
|
49
|
+
return if cut.empty?
|
|
50
|
+
|
|
51
|
+
"/cut/#{cut[:start_time]}/#{cut[:length]}/"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def thumbs_part(thumbs)
|
|
55
|
+
return if thumbs.empty?
|
|
56
|
+
|
|
57
|
+
"/thumbs~#{thumbs[:N]}/#{thumbs[:number]}/".squeeze('/')
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
# @abstract
|
|
5
|
+
# This module is responsible for everything related to generation of request params -
|
|
6
|
+
# such as authentication headers, signatures and serialized uploads
|
|
7
|
+
module Param
|
|
8
|
+
end
|
|
9
|
+
include Param
|
|
10
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest/md5'
|
|
4
|
+
|
|
5
|
+
module Uploadcare
|
|
6
|
+
module Param
|
|
7
|
+
# This object returns headers needed for authentication
|
|
8
|
+
# This authentication method is more secure, but more tedious
|
|
9
|
+
class SecureAuthHeader
|
|
10
|
+
# @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare
|
|
11
|
+
def self.call(**options)
|
|
12
|
+
@method = options[:method]
|
|
13
|
+
@body = options[:content] || ''
|
|
14
|
+
@content_type = options[:content_type]
|
|
15
|
+
@uri = options[:uri]
|
|
16
|
+
@date_for_header = timestamp
|
|
17
|
+
{
|
|
18
|
+
'Date': @date_for_header,
|
|
19
|
+
'Authorization': "Uploadcare #{Uploadcare.config.public_key}:#{signature}"
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
def signature
|
|
25
|
+
content_md5 = Digest::MD5.hexdigest(@body)
|
|
26
|
+
sign_string = [@method, content_md5, @content_type, @date_for_header, @uri].join("\n")
|
|
27
|
+
digest = OpenSSL::Digest.new('sha1')
|
|
28
|
+
OpenSSL::HMAC.hexdigest(digest, Uploadcare.config.secret_key, sign_string)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def timestamp
|
|
32
|
+
Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uploadcare
|
|
4
|
+
module Param
|
|
5
|
+
# This object returns simple header for authentication
|
|
6
|
+
# Simple header is relatively unsafe, but can be useful for debug and development
|
|
7
|
+
class SimpleAuthHeader
|
|
8
|
+
# @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-simple
|
|
9
|
+
def self.call
|
|
10
|
+
{ 'Authorization': "Uploadcare.Simple #{Uploadcare.config.public_key}:#{Uploadcare.config.secret_key}" }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
|
|
5
|
+
module Uploadcare
|
|
6
|
+
module Param
|
|
7
|
+
module Upload
|
|
8
|
+
# This class generates signatures for protected uploads
|
|
9
|
+
class SignatureGenerator
|
|
10
|
+
# @see https://uploadcare.com/docs/api_reference/upload/signed_uploads/
|
|
11
|
+
# @return [Hash] signature and its expiration time
|
|
12
|
+
def self.call
|
|
13
|
+
expires_at = Time.now.to_i + Uploadcare.config.upload_signature_lifetime
|
|
14
|
+
to_sign = Uploadcare.config.secret_key + expires_at.to_s
|
|
15
|
+
signature = Digest::MD5.hexdigest(to_sign)
|
|
16
|
+
{
|
|
17
|
+
'signature': signature,
|
|
18
|
+
'expire': expires_at
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
|
|
5
|
+
module Uploadcare
|
|
6
|
+
module Param
|
|
7
|
+
module Upload
|
|
8
|
+
# This class generates body params for uploads
|
|
9
|
+
class UploadParamsGenerator
|
|
10
|
+
# @see https://uploadcare.com/docs/api_reference/upload/request_based/
|
|
11
|
+
def self.call(store = 'auto')
|
|
12
|
+
store = '1' if store == true
|
|
13
|
+
store = '0' if store == false
|
|
14
|
+
{
|
|
15
|
+
'UPLOADCARE_PUB_KEY' => Uploadcare.config.public_key,
|
|
16
|
+
'UPLOADCARE_STORE' => store,
|
|
17
|
+
'signature' => (Upload::SignatureGenerator.call if Uploadcare.config.sign_uploads)
|
|
18
|
+
}.reject { |_k, v| v.nil? }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uploadcare'
|
|
4
|
+
|
|
5
|
+
module Uploadcare
|
|
6
|
+
module Param
|
|
7
|
+
# This header is added to track libraries using Uploadcare API
|
|
8
|
+
class UserAgent
|
|
9
|
+
# Generate header from Gem's config
|
|
10
|
+
#
|
|
11
|
+
# @example Uploadcare::Param::UserAgent.call
|
|
12
|
+
# UploadcareRuby/3.0.0-dev/Pubkey_(Ruby/2.6.3;UploadcareRuby)
|
|
13
|
+
def self.call
|
|
14
|
+
framework_data = Uploadcare.config.framework_data || ''
|
|
15
|
+
framework_data_string = "; #{Uploadcare.config.framework_data}" unless framework_data.empty?
|
|
16
|
+
public_key = Uploadcare.config.public_key
|
|
17
|
+
"UploadcareRuby/#{VERSION}/#{public_key} (Ruby/#{RUBY_VERSION}#{framework_data_string})"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/uploadcare.rb
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
require 'json'
|
|
3
|
-
require 'ostruct'
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# Gem version
|
|
4
|
+
require 'ruby/version'
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private_key: 'demoprivatekey',
|
|
12
|
-
upload_url_base: 'https://upload.uploadcare.com',
|
|
13
|
-
api_url_base: 'https://api.uploadcare.com',
|
|
14
|
-
static_url_base: 'https://ucarecdn.com',
|
|
15
|
-
api_version: '0.5',
|
|
16
|
-
cache_files: true,
|
|
17
|
-
autostore: :auto,
|
|
18
|
-
auth_scheme: :secure,
|
|
19
|
-
}
|
|
6
|
+
# Exceptions
|
|
7
|
+
require 'exception/throttle_error'
|
|
8
|
+
require 'exception/request_error'
|
|
20
9
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
# Entities
|
|
11
|
+
require 'entity/entity'
|
|
12
|
+
require 'entity/file'
|
|
13
|
+
require 'entity/file_list'
|
|
14
|
+
require 'entity/group'
|
|
15
|
+
require 'entity/group_list'
|
|
16
|
+
require 'entity/project'
|
|
17
|
+
require 'entity/uploader'
|
|
18
|
+
require 'entity/webhook'
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
UserAgent.new.call(options)
|
|
28
|
-
end
|
|
20
|
+
# General api
|
|
21
|
+
require 'api/api'
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
# Ruby wrapper for Uploadcare API
|
|
24
|
+
#
|
|
25
|
+
# @see https://uploadcare.com/docs/api_reference
|
|
26
|
+
module Uploadcare
|
|
27
|
+
extend Dry::Configurable
|
|
28
|
+
setting :public_key, ENV.fetch('UPLOADCARE_PUBLIC_KEY')
|
|
29
|
+
setting :secret_key, ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
30
|
+
setting :auth_type, 'Uploadcare'
|
|
31
|
+
setting :multipart_size_threshold, 100 * 1024 * 1024
|
|
32
|
+
setting :rest_api_root, 'https://api.uploadcare.com'
|
|
33
|
+
setting :upload_api_root, 'https://upload.uploadcare.com'
|
|
34
|
+
setting :max_request_tries, 100
|
|
35
|
+
setting :base_request_sleep, 1 # seconds
|
|
36
|
+
setting :max_request_sleep, 60.0 # seconds
|
|
37
|
+
setting :sign_uploads, false
|
|
38
|
+
setting :upload_signature_lifetime, 30 * 60 # seconds
|
|
39
|
+
setting :max_throttle_attempts, 5
|
|
40
|
+
setting :upload_threads, 2 # used for multiupload only ATM
|
|
41
|
+
setting :framework_data, ''
|
|
38
42
|
end
|
data/uploadcare-ruby.gemspec
CHANGED
|
@@ -1,38 +1,51 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
gem.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
gem.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'uploadcare/ruby/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'uploadcare-ruby'
|
|
9
|
+
spec.version = Uploadcare::VERSION
|
|
10
|
+
spec.authors = ['Stepan Redka']
|
|
11
|
+
spec.email = ['stepan.redka@railsmuffin.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Ruby wrapper for uploadcare API'
|
|
14
|
+
spec.description = spec.summary
|
|
15
|
+
spec.homepage = 'https://github.com/uploadcare/uploadcare-ruby'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
if spec.respond_to?(:metadata)
|
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
22
|
+
|
|
23
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
24
|
+
spec.metadata['source_code_uri'] = 'https://github.com/uploadcare/uploadcare-ruby'
|
|
25
|
+
spec.metadata['changelog_uri'] = 'https://github.com/uploadcare/uploadcare-ruby/CHANGELOG.md'
|
|
26
|
+
else
|
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
28
|
+
'public gem pushes.'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
33
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
35
|
+
end
|
|
36
|
+
spec.bindir = 'exe'
|
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
38
|
+
spec.require_paths = ['lib', 'lib/uploadcare', 'lib/uploadcare/rest']
|
|
39
|
+
|
|
40
|
+
spec.add_dependency 'api_struct', '~> 1.0.1'
|
|
41
|
+
spec.add_dependency 'dry-configurable', '~> 0.9.0'
|
|
42
|
+
spec.add_dependency 'parallel'
|
|
43
|
+
spec.add_dependency 'retries'
|
|
44
|
+
|
|
45
|
+
spec.add_development_dependency 'byebug'
|
|
46
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
47
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
48
|
+
spec.add_development_dependency 'rubocop'
|
|
49
|
+
spec.add_development_dependency 'vcr'
|
|
50
|
+
spec.add_development_dependency 'webmock'
|
|
38
51
|
end
|