uploadcare-rails 1.2.1 → 2.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.
Files changed (190) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +5 -16
  3. data/lib/generators/templates/uploadcare_config_template.erb +138 -0
  4. data/lib/generators/uploadcare_config_generator.rb +7 -4
  5. data/lib/uploadcare/errors/type_error.rb +7 -0
  6. data/lib/uploadcare/rails/action_view/uploadcare_include_tags.rb +48 -0
  7. data/lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb +57 -0
  8. data/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb +62 -0
  9. data/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb +58 -0
  10. data/lib/uploadcare/rails/api/rest/base.rb +14 -0
  11. data/lib/uploadcare/rails/api/rest/conversion_api.rb +42 -0
  12. data/lib/uploadcare/rails/api/rest/file_api.rb +69 -0
  13. data/lib/uploadcare/rails/api/rest/group_api.rb +48 -0
  14. data/lib/uploadcare/rails/api/rest/project_api.rb +27 -0
  15. data/lib/uploadcare/rails/api/rest/webhook_api.rb +45 -0
  16. data/lib/uploadcare/rails/api/upload/base.rb +13 -0
  17. data/lib/uploadcare/rails/api/upload/upload_api.rb +53 -0
  18. data/lib/uploadcare/rails/configuration.rb +57 -0
  19. data/lib/uploadcare/rails/engine.rb +13 -17
  20. data/lib/uploadcare/rails/jobs/delete_file_job.rb +14 -0
  21. data/lib/uploadcare/rails/jobs/store_file_job.rb +14 -0
  22. data/lib/uploadcare/rails/jobs/store_group_job.rb +14 -0
  23. data/lib/uploadcare/rails/objects/concerns/loadable.rb +46 -0
  24. data/lib/uploadcare/rails/objects/file.rb +40 -20
  25. data/lib/uploadcare/rails/objects/group.rb +51 -57
  26. data/lib/uploadcare/rails/services/files_count_extractor.rb +14 -0
  27. data/lib/uploadcare/rails/services/id_extractor.rb +15 -0
  28. data/lib/uploadcare/rails/transformations/image_transformations.rb +45 -0
  29. data/lib/uploadcare/rails/version.rb +3 -1
  30. data/lib/uploadcare/rails.rb +10 -0
  31. data/lib/uploadcare-rails.rb +27 -16
  32. data/spec/fixtures/kitten.jpeg +0 -0
  33. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +62 -0
  34. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +62 -0
  35. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +62 -0
  36. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +62 -0
  37. data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +59 -0
  38. data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +59 -0
  39. data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +60 -0
  40. data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +58 -0
  41. data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +58 -0
  42. data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +58 -0
  43. data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +61 -0
  44. data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +57 -0
  45. data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +58 -0
  46. data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +57 -0
  47. data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +57 -0
  48. data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +52 -0
  49. data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +57 -0
  50. data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +57 -0
  51. data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +59 -0
  52. data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +55 -0
  53. data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +105 -0
  54. data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +111 -0
  55. data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +59 -0
  56. data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +57 -0
  57. data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +59 -0
  58. data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +59 -0
  59. data/spec/generators/uploadcare_config_generator_spec.rb +18 -26
  60. data/spec/spec_helper.rb +17 -69
  61. data/spec/support/generators.rb +8 -5
  62. data/spec/support/vcr.rb +14 -0
  63. data/spec/tmp/config/initializers/uploadcare.rb +138 -0
  64. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +40 -0
  65. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +46 -0
  66. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +33 -0
  67. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +32 -0
  68. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +110 -0
  69. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +85 -0
  70. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +61 -0
  71. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +33 -0
  72. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +59 -0
  73. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +82 -0
  74. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +15 -0
  75. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +15 -0
  76. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +15 -0
  77. data/spec/uploadcare/rails/objects/file_spec.rb +77 -0
  78. data/spec/uploadcare/rails/objects/group_spec.rb +87 -0
  79. data/spec/uploadcare/rails/services/id_extractor_spec.rb +26 -0
  80. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +120 -0
  81. data/spec/uploadcare/rails_spec.rb +7 -0
  82. metadata +129 -351
  83. data/config/initializers/uploadcare.rb +0 -26
  84. data/config/uploadcare_defaults.yml +0 -12
  85. data/lib/generators/templates/uploadcare_config_template.yml +0 -67
  86. data/lib/tasks/uploadcare_rails_tasks.rake +0 -4
  87. data/lib/uploadcare/rails/action_view/include_tags.rb +0 -47
  88. data/lib/uploadcare/rails/action_view/uploader_tags.rb +0 -76
  89. data/lib/uploadcare/rails/active_record/has_file.rb +0 -92
  90. data/lib/uploadcare/rails/active_record/has_group.rb +0 -89
  91. data/lib/uploadcare/rails/active_record/has_object.rb +0 -9
  92. data/lib/uploadcare/rails/formtastic/formtastic.rb +0 -73
  93. data/lib/uploadcare/rails/operations.rb +0 -57
  94. data/lib/uploadcare/rails/settings.rb +0 -81
  95. data/lib/uploadcare/rails/simple_form/simple_form.rb +0 -63
  96. data/spec/caching/file_caching_spec.rb +0 -26
  97. data/spec/caching/group_caching_spec.rb +0 -40
  98. data/spec/dummy/README.rdoc +0 -28
  99. data/spec/dummy/Rakefile +0 -6
  100. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  101. data/spec/dummy/app/assets/javascripts/post_with_collections.js +0 -2
  102. data/spec/dummy/app/assets/javascripts/posts.js +0 -2
  103. data/spec/dummy/app/assets/javascripts/posts_with_collection_and_files.js +0 -2
  104. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  105. data/spec/dummy/app/assets/stylesheets/post_with_collections.css +0 -4
  106. data/spec/dummy/app/assets/stylesheets/posts.css +0 -4
  107. data/spec/dummy/app/assets/stylesheets/posts_with_collection_and_files.css +0 -4
  108. data/spec/dummy/app/assets/stylesheets/scaffold.css +0 -56
  109. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  110. data/spec/dummy/app/controllers/post_with_collections_controller.rb +0 -58
  111. data/spec/dummy/app/controllers/posts_controller.rb +0 -58
  112. data/spec/dummy/app/controllers/posts_with_collection_and_files_controller.rb +0 -58
  113. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  114. data/spec/dummy/app/helpers/post_with_collections_helper.rb +0 -2
  115. data/spec/dummy/app/helpers/posts_helper.rb +0 -2
  116. data/spec/dummy/app/helpers/posts_with_collection_and_files_helper.rb +0 -2
  117. data/spec/dummy/app/models/post.rb +0 -4
  118. data/spec/dummy/app/models/post_with_collection.rb +0 -4
  119. data/spec/dummy/app/models/posts_with_collection_and_file.rb +0 -4
  120. data/spec/dummy/app/views/layouts/application.html.erb +0 -16
  121. data/spec/dummy/app/views/post_with_collections/_form.html.erb +0 -25
  122. data/spec/dummy/app/views/post_with_collections/edit.html.erb +0 -6
  123. data/spec/dummy/app/views/post_with_collections/index.html.erb +0 -29
  124. data/spec/dummy/app/views/post_with_collections/new.html.erb +0 -5
  125. data/spec/dummy/app/views/post_with_collections/show.html.erb +0 -14
  126. data/spec/dummy/app/views/post_with_collections/show.json.jbuilder +0 -1
  127. data/spec/dummy/app/views/posts/_form.html.erb +0 -31
  128. data/spec/dummy/app/views/posts/edit.html.erb +0 -6
  129. data/spec/dummy/app/views/posts/index.html.erb +0 -37
  130. data/spec/dummy/app/views/posts/new.html.erb +0 -5
  131. data/spec/dummy/app/views/posts/post.json.builder +0 -1
  132. data/spec/dummy/app/views/posts/show.html.erb +0 -15
  133. data/spec/dummy/app/views/posts_with_collection_and_files/_form.html.erb +0 -27
  134. data/spec/dummy/app/views/posts_with_collection_and_files/edit.html.erb +0 -6
  135. data/spec/dummy/app/views/posts_with_collection_and_files/index.html.erb +0 -25
  136. data/spec/dummy/app/views/posts_with_collection_and_files/new.html.erb +0 -5
  137. data/spec/dummy/app/views/posts_with_collection_and_files/show.html.erb +0 -4
  138. data/spec/dummy/app/views/posts_with_collection_and_files/show.json.jbuilder +0 -1
  139. data/spec/dummy/bin/bundle +0 -3
  140. data/spec/dummy/bin/rails +0 -4
  141. data/spec/dummy/bin/rake +0 -4
  142. data/spec/dummy/config/application.rb +0 -23
  143. data/spec/dummy/config/boot.rb +0 -4
  144. data/spec/dummy/config/database.yml +0 -25
  145. data/spec/dummy/config/environment.rb +0 -5
  146. data/spec/dummy/config/environments/development.rb +0 -29
  147. data/spec/dummy/config/environments/production.rb +0 -80
  148. data/spec/dummy/config/environments/test.rb +0 -36
  149. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  150. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  151. data/spec/dummy/config/initializers/formtastic.rb +0 -111
  152. data/spec/dummy/config/initializers/inflections.rb +0 -16
  153. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  154. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  155. data/spec/dummy/config/initializers/session_store.rb +0 -3
  156. data/spec/dummy/config/initializers/simple_form.rb +0 -167
  157. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  158. data/spec/dummy/config/locales/en.yml +0 -23
  159. data/spec/dummy/config/locales/simple_form.en.yml +0 -31
  160. data/spec/dummy/config/routes.rb +0 -63
  161. data/spec/dummy/config/uploadcare.yml +0 -64
  162. data/spec/dummy/config.ru +0 -4
  163. data/spec/dummy/db/migrate/20171012001801_create_tables.rb +0 -27
  164. data/spec/dummy/db/migrate/20181001132710_add_other_file_to_post.rb +0 -8
  165. data/spec/dummy/db/migrate/20181001141434_add_other_file_to_post_with_collections.rb +0 -8
  166. data/spec/dummy/db/schema.rb +0 -39
  167. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +0 -13
  168. data/spec/dummy/public/404.html +0 -58
  169. data/spec/dummy/public/422.html +0 -58
  170. data/spec/dummy/public/500.html +0 -57
  171. data/spec/dummy/public/favicon.ico +0 -0
  172. data/spec/helpers/form_helpers_has_file_spec.rb +0 -30
  173. data/spec/helpers/form_helpers_has_group_spec.rb +0 -30
  174. data/spec/helpers/form_helpers_spec.rb +0 -33
  175. data/spec/helpers/formtastic_spec.rb +0 -25
  176. data/spec/helpers/include_tags_spec.rb +0 -54
  177. data/spec/helpers/simple_form_spec.rb +0 -25
  178. data/spec/helpers/uploader_tags_spec.rb +0 -21
  179. data/spec/models/has_both_file_and_group_spec.rb +0 -43
  180. data/spec/models/has_file_spec.rb +0 -46
  181. data/spec/models/has_group_spec.rb +0 -57
  182. data/spec/models/has_several_files_spec.rb +0 -55
  183. data/spec/models/has_several_groups_spec.rb +0 -62
  184. data/spec/objects/file_spec.rb +0 -27
  185. data/spec/objects/group_spec.rb +0 -51
  186. data/spec/operations_spec.rb +0 -28
  187. data/spec/uploadcare/rails/settings_spec.rb +0 -136
  188. data/spec/uploadcare_rails_settings_spec.rb +0 -56
  189. data/spec/view.png +0 -0
  190. data/spec/view2.jpg +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 51e5e1bed076e6d97a1ea78f70545bf4e6e1820f
4
- data.tar.gz: 8f50c72f63c5a8dfc7fed84861468868eb5477a3
2
+ SHA256:
3
+ metadata.gz: 350614c535917ec6a0e4967b6c1935520615f7c05f2dde048e2e71049acfb53e
4
+ data.tar.gz: d76147a67baf18cf174a28ba1a3f1351ecfae7d2b66efb2dbfa2705ea9ed1f47
5
5
  SHA512:
6
- metadata.gz: b7221fac254b9ff175acafcb165131fffc356520132a5dea2b76b62592e9ebe1995641ae126b758e04ab37059bc2abcec6109fc0a6ca682267d5029383df3cc7
7
- data.tar.gz: 0daf1d6084931be84f042650ff2f5fa4f9f948d631574bfc7cb32670cb79561bbdc28a7a3f69167b66de7c06296076543159e85298ac8537b04aa5d29b0ca25d
6
+ metadata.gz: 5c8da1247c066d6e6224d04ab9d38d59fd18aea135e24e927de0c515f32e7a1544952840bb1b11a44f812bf511fb0fe0c2eb0ff891c2aba3d88b899ed8a2cc7c
7
+ data.tar.gz: a1974745e61af0f76c8eda6e509db5677f153f6e59ad722463dfd3e1103b3710793eac34a1327e13e10658c0f21e198edf009abfe73898cfbe8cfb748c75e7f3
data/Rakefile CHANGED
@@ -1,19 +1,8 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
- Bundler::GemHelper.install_tasks
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
9
5
 
10
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
11
- load 'rails/tasks/engine.rake'
12
- require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec)
13
7
 
14
- task :default => :spec
15
-
16
- RSpec::Core::RakeTask.new(:spec) do |spec|
17
- spec.pattern = 'spec/**/*_spec.rb'
18
- # spec.rspec_opts = ['-cfs --backtrace']
19
- end
8
+ task default: :spec
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Uncomment this string in case of using locales for locale_translations parameter
4
+ # I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
5
+
6
+ Uploadcare::Rails.configure do |config|
7
+ # Sets your Uploadcare public key.
8
+ config.public_key = ENV.fetch('UPLOADCARE_PUBLIC_KEY', 'demopublickey')
9
+ # config.secret_key = ENV.fetch('UPLOADCARE_SECRET_KEY', 'demosecretkey')
10
+
11
+ # Stores files to Uploadcare servers after object save.
12
+ config.store_files_after_save = true
13
+
14
+ # Deletes files from Uploadcare servers after object destroy.
15
+ config.delete_files_after_destroy = true
16
+
17
+ # Sets caching for Uploadcare files
18
+ config.cache_namespace = 'uploadcare'
19
+ config.cache_files = true
20
+ config.cache_expires_in = 1.day
21
+
22
+ # These options enables ActiveJob background jobs to perform operations in background.
23
+ # Options work if only the option 'do_not_store' is disabled (false) and
24
+ # the option 'delete_files_after_destroy' is enabled (true).
25
+ config.store_files_async = true
26
+ config.delete_files_async = true
27
+
28
+ # If true, only image files are allowed to be uploaded.
29
+ # config.images_only = false
30
+
31
+ # If true, the preview step is present after selecting files.
32
+ # Otherwise, the file uploader dialog closes when the selection is complete.
33
+ # config.preview_step = false
34
+
35
+ # Defines the file uploader manual crop behavior (see https://uploadcare.com/docs/uploads/file-uploader/#crop-option).
36
+ # When uploading images, your users can select a crop area.
37
+ # This option does not force your file uploader to accept images only.
38
+ # The option also works in the multi-file mode since version 2.3.0.
39
+ # config.crop = 'disabled'
40
+
41
+ # Saves traffic and storage space by resizing images on a client before uploading.
42
+ # See the detailed option description for details. Using the client-side resize does not force the images only option.
43
+ # config.image_shrink = '800x600'
44
+
45
+ # Allows user to remove uploaded files from the file uploader.
46
+ # Please note that those files are not deleted from your account.
47
+ # config.clearable = true
48
+
49
+ # Allows you to define which upload sources you want to use with the file uploader.
50
+ # The value is represented by a space-separated ordered list of upload source names.
51
+ # See https://uploadcare.com/docs/uploads/file-uploader/#upload-sources for details.
52
+ # config.tabs = %w[url file facebook]
53
+
54
+ # Sets the accept attribute for the file uploader dialog.
55
+ # If the images only option is disabled, the value is empty.
56
+ # Otherwise, the default value is image/*.
57
+ # null means accept should be kept empty regardless of the images only value.
58
+ # For other possible values, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
59
+ # Note, this is not a replacement for
60
+ # our file validation (see https://uploadcare.com/docs/file-uploader-api/file-validation/)
61
+ # because your users will still be able to choose any file via drag&drop or from URL.
62
+ # config.input_accept_types = %w[image/*]
63
+
64
+ # Defines the list of preferred MIME types.
65
+ # The list should be ordered and contain space-separated MIME types.
66
+ # Common parts can be marked with asterisks: image/* application/vnd.openxmlformats-officedocument.*.
67
+ # If no MIME types match the criteria or preferred types are not set, default formats are used.
68
+ # Keep in mind that some cloud services can export data in different formats.
69
+ # For example, Google document can be exported as Word document, PDF or plain text.
70
+ # config.preferred_types = %w[image/* application/vnd.openxmlformats-officedocument.*]
71
+
72
+ # Forces a system-native file picking dialog to show up instead of our file uploader.
73
+ # That makes the file uploader behavior as close as possible to the generic <input type="file">.
74
+ # Native behavior is achieved at the expense of support for uploading content
75
+ # from social media and cloud storage, manual crop, and preview step.
76
+ # Multi-file selection would still work.
77
+ # The option does not work in old browser versions: the dialog falls back to the file uploader.
78
+ # config.system_dialog = false
79
+
80
+ # This option sets the file size threshold for multipart uploading.
81
+ # The value ranges from 10485760 (10 MB), which is default, up to 104857600 (100 MB).
82
+ # If a file size hits the threshold, it gets uploaded in four parallel chunks by 5 MB.
83
+ # Multipart upload makes large file uploading faster.
84
+ # Files go directly to a storage, bypassing our upload servers,
85
+ # and they're quickly available for further use. All files below the threshold get uploaded in one piece.
86
+ # Note: Multipart upload works with local sources only (files and camera).
87
+ # config.multipart_min_size = 10485760
88
+
89
+ # Available locales currently are:
90
+ # ar az ca cs da de el en es et fr he it ja ko lv nb nl pl pt ro ru sk sr sv tr uk vi zhTW zh
91
+ config.locale = 'en'
92
+
93
+ # Sets custom localization options. See https://uploadcare.com/docs/uploads/file-uploader/#localization
94
+ # config.locale_translations = {}
95
+
96
+ # Defines pluralization options. See https://uploadcare.com/docs/uploads/file-uploader/#pluralization
97
+ # config.locale_pluralize = {}
98
+
99
+ # The option can be used with Authenticated URLs. Defines your proxy backend URL.
100
+ # See https://uploadcare.com/docs/security/secure-delivery/#proxy-backend.
101
+ # config.preview_proxy = 'https://domain.com/preview?'
102
+
103
+ # If true, inputs on your page are initialized automatically, see the article for details -
104
+ # https://uploadcare.com/docs/file-uploader-api/widget-initialization/
105
+ config.live = true
106
+
107
+ # If true, input initialization is invoked manually.
108
+ # See https://uploadcare.com/docs/file-uploader-api/widget-initialization/).
109
+ config.manual_start = false
110
+
111
+ # Defines your schema and CDN domain.
112
+ # Can be changed to one of the predefined values (https://uploadcare.com/docs/delivery/cdn/) or your custom CNAME.
113
+ # config.cdn_base = 'https://ucarecdn.com/'
114
+ config.cdn_hostname = 'ucarecdn.com'
115
+
116
+ # Forces files uploaded with a file uploader not to be stored.
117
+ # See https://uploadcare.com/docs/uploads/storage/#storing-uploaded-files.
118
+ # For instance, you might want to turn this on when automatic file storing is enabled in your project,
119
+ # but you do not want to store files uploaded with a particular file uploader.
120
+ # config.do_not_store = false
121
+
122
+ # Allows you to adjust the quality of an audio recorded via the file uploader Camera Tab.
123
+ # Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
124
+ # config.audio_bits_per_second = 1
125
+
126
+ # Allows you to specify the MIME types.
127
+ # The first supported by the browser will be used as an option of
128
+ # video stream captured via the file uploader Camera Tab.
129
+ # Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
130
+ # config.video_preferred_mime_types = []
131
+
132
+ # Allows you to adjust the quality of a video stream captured via the file uploader Camera Tab.
133
+ # Refer the link to learn more - https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder.
134
+ # config.video_bits_per_second = 1
135
+
136
+ # Allows you to set the default state of image/video mirorring in the camera tab.
137
+ # config.camera_mirror_default = true
138
+ end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A generator that copies the config template to config directory
1
4
  class UploadcareConfigGenerator < Rails::Generators::Base
2
- desc "This generator creates an uploadcare config file your_app/config/uploadcare.yml"
5
+ desc 'This generator creates an uploadcare config file your_app/config/initializers/uploadcare.rb'
3
6
 
4
- source_root File.expand_path("../templates", __FILE__)
7
+ source_root File.expand_path('templates', __dir__)
5
8
 
6
9
  def create_config_file
7
- copy_file "uploadcare_config_template.yml", "config/uploadcare.yml"#create_file "config/uploadcare.yml", config_template
10
+ copy_file 'uploadcare_config_template.erb', 'config/initializers/uploadcare.rb'
8
11
  end
9
- end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uploadcare
4
+ module Errors
5
+ class TypeError < TypeError; end
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+ require 'uploadcare/rails/configuration'
5
+
6
+ module Uploadcare
7
+ module Rails
8
+ module ActionView
9
+ # A module containing a view include tags helper
10
+ module UploadcareWidgetTags
11
+ # A view helper to add a js script tag from CDN with just one string of code.
12
+ # See https://uploadcare.com/docs/uploads/file-uploader/#cdn for more info.
13
+ #
14
+ # Example:
15
+ # <%= uploadcare_include_tag %>
16
+ # => <script src="https://ucarecdn.com/libs/widget/3.x/uploadcare.full.min.js"></script>
17
+ # <script>
18
+ # UPLOADCARE_PUBLIC_KEY = 'demopublickey';
19
+ # UPLOADCARE_LOCALE = 'en';
20
+ # </script>
21
+ #
22
+ # Arguments:
23
+ # version: (String, default: '3.x') - version of the widget
24
+ # bundle: (String, default: 'full') - https://uploadcare.com/docs/uploads/file-uploader/#bundles
25
+ # valid options: 'full', 'default', 'ie8', 'api', 'lang.en'
26
+ # min: (true/false, default: true) - sets which version to get, minified or not
27
+
28
+ def uploadcare_include_tag(version: '3.x', bundle: 'full', min: true)
29
+ min = min == true ? '.min' : ''
30
+ bundle = bundle == 'default' ? '' : ".#{bundle}"
31
+ path = "/libs/widget/#{version}/uploadcare#{bundle}#{min}.js"
32
+ uri = URI::HTTPS.build(host: Uploadcare::Rails.configuration.cdn_hostname, path: path)
33
+
34
+ config_tag = javascript_tag(uploader_settings) if uploader_settings.present?
35
+ include_tag = javascript_include_tag(uri.to_s.squeeze('.'))
36
+
37
+ include_tag.concat(config_tag)
38
+ end
39
+
40
+ def uploader_settings
41
+ @uploader_settings ||= Uploadcare::Rails.configuration.uploader_parameters
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ ActionView::Base.include Uploadcare::Rails::ActionView::UploadcareWidgetTags
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+ require 'uploadcare/rails/configuration'
5
+
6
+ module Uploadcare
7
+ module Rails
8
+ module ActionView
9
+ # A module containing a view field helper
10
+ module UploadcareUploaderTags
11
+ # A view helper to add a uploader button to a html-page
12
+ # See https://uploadcare.com/docs/uploads/file-uploader/#using-on-page for more info.
13
+ #
14
+ # Example:
15
+ # <%= uploadcare_uploader_field :post, :title %>
16
+ # => <input role="uploadcare-uploader" data-multiple="true" type="hidden" name="post[file]" id="post_file">
17
+ # <div class="uploadcare--widget uploadcare--widget_status_ready" ...
18
+ #
19
+ # Arguments:
20
+ # object_name: (String/Symbol) - object name which a field belongs to
21
+ # method_name: (String/Symbol) - object method name
22
+ # options: (Hash, default: {}) - options for hidden_field
23
+
24
+ DEFAULT_FIELD_OPTIONS = { role: 'uploadcare-uploader' }.freeze
25
+
26
+ def uploadcare_uploader_field(object_name, method_name, options = {})
27
+ hidden_field(
28
+ object_name,
29
+ method_name,
30
+ uploadcare_uploader_options(
31
+ options.merge(multiple: uploadcare_uploader_multiple?(object_name, method_name).presence)
32
+ )
33
+ )
34
+ end
35
+
36
+ def uploadcare_uploader_field_tag(object_name, options = {})
37
+ hidden_field_tag(object_name, options[:value], uploadcare_uploader_options(options))
38
+ end
39
+
40
+ def uploadcare_uploader_options(options = {})
41
+ data_options = options.transform_keys { |key| "data-#{key.to_s.underscore.dasherize}" }
42
+ DEFAULT_FIELD_OPTIONS.merge(data_options)
43
+ end
44
+
45
+ private
46
+
47
+ def uploadcare_uploader_multiple?(object_name, method_name)
48
+ model = object_name.to_s.camelize.safe_constantize
49
+ method_name = "has_uploadcare_file_group_for_#{method_name}?"
50
+ model.respond_to?(method_name) && model.public_send(method_name)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ ActionView::Base.include Uploadcare::Rails::ActionView::UploadcareUploaderTags
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'active_support/concern'
5
+ require 'uploadcare/rails/services/id_extractor'
6
+ require 'uploadcare/rails/jobs/delete_file_job'
7
+ require 'uploadcare/rails/jobs/store_file_job'
8
+
9
+ module Uploadcare
10
+ module Rails
11
+ module ActiveRecord
12
+ # A module containing ActiveRecord extension. Allows to use uploadcare file methods in Rails models
13
+ module MountUploadcareFile
14
+ extend ActiveSupport::Concern
15
+
16
+ def build_uploadcare_file(attribute)
17
+ cdn_url = attributes[attribute.to_s].to_s
18
+ return if cdn_url.empty?
19
+
20
+ uuid = IdExtractor.call(cdn_url)
21
+ cache_key = File.build_cache_key(cdn_url)
22
+ default_attributes = { cdn_url: cdn_url, uuid: uuid.presence }
23
+ file_attributes = ::Rails.cache.read(cache_key).presence || default_attributes
24
+ Uploadcare::Rails::File.new(file_attributes)
25
+ end
26
+
27
+ class_methods do
28
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
29
+ def mount_uploadcare_file(attribute)
30
+ define_method attribute do
31
+ build_uploadcare_file attribute
32
+ end
33
+
34
+ define_method "uploadcare_store_#{attribute}!" do |store_job = StoreFileJob|
35
+ file_uuid = public_send(attribute)&.uuid
36
+ return unless file_uuid
37
+ return store_job.perform_later(file_uuid) if Uploadcare::Rails.configuration.store_files_async
38
+
39
+ Uploadcare::FileApi.store_file(file_uuid)
40
+ end
41
+
42
+ define_method "uploadcare_delete_#{attribute}!" do |delete_job = DeleteFileJob|
43
+ file_uuid = public_send(attribute)&.uuid
44
+ return unless file_uuid
45
+ return delete_job.perform_later(file_uuid) if Uploadcare::Rails.configuration.delete_files_async
46
+
47
+ Uploadcare::FileApi.delete_file(file_uuid)
48
+ end
49
+
50
+ after_save "uploadcare_store_#{attribute}!".to_sym unless Uploadcare::Rails.configuration.do_not_store
51
+ return unless Uploadcare::Rails.configuration.delete_files_after_destroy
52
+
53
+ after_destroy "uploadcare_delete_#{attribute}!".to_sym
54
+ end
55
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ ActiveRecord::Base.include Uploadcare::Rails::ActiveRecord::MountUploadcareFile
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'active_support/concern'
5
+ require 'uploadcare/rails/services/id_extractor'
6
+ require 'uploadcare/rails/services/files_count_extractor'
7
+ require 'uploadcare/rails/jobs/store_group_job'
8
+
9
+ module Uploadcare
10
+ module Rails
11
+ module ActiveRecord
12
+ # A module containing ActiveRecord extension. Allows to use uploadcare group methods in Rails models
13
+ module MountUploadcareFileGroup
14
+ extend ActiveSupport::Concern
15
+
16
+ GROUP_ID_REGEX = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b~\d/.freeze
17
+
18
+ def build_uploadcare_file_group(attribute)
19
+ cdn_url = attributes[attribute.to_s].to_s
20
+ return if cdn_url.empty?
21
+
22
+ group_id = IdExtractor.call(cdn_url, GROUP_ID_REGEX).presence
23
+ cache_key = File.build_cache_key(cdn_url)
24
+ files_count = FilesCountExtractor.call(group_id)
25
+ default_attributes = { cdn_url: cdn_url, id: group_id, files_count: files_count }
26
+ file_attributes = ::Rails.cache.read(cache_key).presence || default_attributes
27
+ Uploadcare::Rails::Group.new(file_attributes)
28
+ end
29
+
30
+ class_methods do
31
+ # rubocop:disable Metrics/MethodLength
32
+ def mount_uploadcare_file_group(attribute)
33
+ define_singleton_method "has_uploadcare_file_group_for_#{attribute}?" do
34
+ true
35
+ end
36
+
37
+ define_method attribute do
38
+ build_uploadcare_file_group attribute
39
+ end
40
+
41
+ define_method "uploadcare_store_#{attribute}!" do |store_job = StoreGroupJob|
42
+ group_id = public_send(attribute)&.id
43
+ return unless group_id
44
+ return store_job.perform_later(group_id) if Uploadcare::Rails.configuration.store_files_async
45
+
46
+ Uploadcare::GroupApi.store_group(group_id)
47
+ end
48
+
49
+ after_save "uploadcare_store_#{attribute}!".to_sym unless Uploadcare::Rails.configuration.do_not_store
50
+ end
51
+ # rubocop:enable Metrics/MethodLength
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ ActiveRecord::Base.include Uploadcare::Rails::ActiveRecord::MountUploadcareFileGroup
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uploadcare'
4
+
5
+ module Uploadcare
6
+ module Rails
7
+ module Api
8
+ module Rest
9
+ class Base
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uploadcare/rails/api/rest/base'
4
+
5
+ module Uploadcare
6
+ module Rails
7
+ module Api
8
+ module Rest
9
+ # A class that contains Conversion related methods for Uploadcare REST API
10
+ class ConversionApi < Base
11
+ class << self
12
+ # Converts video files
13
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/videoConvert
14
+ def convert_video(video_params, **options)
15
+ Uploadcare::VideoConverter.convert(video_params, **options)
16
+ end
17
+
18
+ # Returns a status of video conversion job
19
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/videoConvertStatus
20
+ def get_video_conversion_status(token)
21
+ Uploadcare::VideoConverter.status(token)
22
+ end
23
+
24
+ # Converts documents
25
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/documentConvert
26
+ def convert_document(document_params, **options)
27
+ Uploadcare::DocumentConverter.convert(document_params, **options)
28
+ end
29
+
30
+ # Returns a status of video conversion job
31
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/documentConvertStatus
32
+ def get_document_conversion_status(token)
33
+ Uploadcare::DocumentConverter.status(token)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Uploadcare::ConversionApi = Uploadcare::Rails::Api::Rest::ConversionApi
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uploadcare/rails/api/rest/base'
4
+
5
+ module Uploadcare
6
+ module Rails
7
+ module Api
8
+ module Rest
9
+ # A class that contains File related methods for Uploadcare REST API
10
+ class FileApi < Base
11
+ class << self
12
+ # Returns a pagination json of files stored in project
13
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesList
14
+ #
15
+ # valid options:
16
+ # removed: [true|false]
17
+ # stored: [true|false]
18
+ # limit: (1..1000)
19
+ # ordering: ["datetime_uploaded"|"-datetime_uploaded"|"size"|"-size"]
20
+ # from: A starting point for filtering files. The value depends on your ordering parameter value.
21
+ def get_files(**options)
22
+ Uploadcare::FileList.file_list(**options)
23
+ end
24
+
25
+ # Acquire file info
26
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/fileInfo
27
+ def get_file(uuid)
28
+ Uploadcare::File.info(uuid)
29
+ end
30
+
31
+ # 'copy' method is used to copy original files or their modified versions to default storage.
32
+ # Source files MAY either be stored or just uploaded and MUST NOT be deleted.
33
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/copyFile
34
+ def copy_file(source, **options)
35
+ Uploadcare::File.copy(source, **options)
36
+ end
37
+
38
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/deleteFile
39
+ def delete_file(uuid)
40
+ Uploadcare::File.delete(uuid)
41
+ end
42
+
43
+ # Store a single file, preventing it from being deleted in 2 weeks
44
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/storeFile
45
+ def store_file(uuid)
46
+ Uploadcare::File.store(uuid)
47
+ end
48
+
49
+ # Make a set of files "stored". This will prevent them from being deleted automatically
50
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesStoring
51
+ # uuids: Array
52
+ def store_files(uuids)
53
+ Uploadcare::FileList.batch_store(uuids)
54
+ end
55
+
56
+ # Delete several files by list of uids
57
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/filesDelete
58
+ # uuids: Array
59
+ def delete_files(uuids)
60
+ Uploadcare::FileList.batch_delete(uuids)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ Uploadcare::FileApi = Uploadcare::Rails::Api::Rest::FileApi
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uploadcare/rails/api/rest/base'
4
+
5
+ module Uploadcare
6
+ module Rails
7
+ module Api
8
+ module Rest
9
+ # A class that contains Group related methods for Uploadcare REST API
10
+ class GroupApi < Base
11
+ class << self
12
+ # Returns paginated list of groups
13
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#operation/groupsList
14
+ #
15
+ # valid options:
16
+ # limit: (1..1000)
17
+ # ordering: ["datetime_created"|"-datetime_created"]
18
+ # from: A starting point for filtering group lists. MUST be a datetime value with T used as a separator.
19
+ # example: '2015-01-02T10:00:00'
20
+ def get_groups(**options)
21
+ Uploadcare::GroupList.list(**options)
22
+ end
23
+
24
+ # Get group info
25
+ # @see https://uploadcare.com/api-refs/upload-api/#operation/filesGroupInfo
26
+ def get_group(uuid)
27
+ Uploadcare::Group.info(uuid)
28
+ end
29
+
30
+ # Stores all files in a group
31
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#tag/Group/paths/~1groups~1%3Cuuid%3E~1storage~1/put
32
+ def store_group(uuid)
33
+ Uploadcare::Group.store(uuid)
34
+ end
35
+
36
+ # Create files group from a set of files by using their UUIDs.
37
+ # @see https://uploadcare.com/api-refs/upload-api/#operation/createFilesGroup
38
+ def create_group(files, **options)
39
+ Uploadcare::Group.create(files, **options)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Uploadcare::GroupApi = Uploadcare::Rails::Api::Rest::GroupApi
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uploadcare/rails/api/rest/base'
4
+
5
+ module Uploadcare
6
+ module Rails
7
+ module Api
8
+ module Rest
9
+ # A class that contains Project related methods for Uploadcare REST API
10
+ class ProjectApi < Base
11
+ class << self
12
+ # Get information about the current project.
13
+ # Current project is determined by public and secret keys combination.
14
+ # @see https://uploadcare.com/api-refs/rest-api/v0.5.0/#tag/Project
15
+ # rubocop:disable Naming/AccessorMethodName
16
+ def get_project
17
+ Uploadcare::Project.show
18
+ end
19
+ # rubocop:enable Naming/AccessorMethodName
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Uploadcare::ProjectApi = Uploadcare::Rails::Api::Rest::ProjectApi