cloudinary 1.9.1 → 1.20.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 (72) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  4. data/.github/pull_request_template.md +24 -0
  5. data/.gitignore +7 -1
  6. data/.travis.yml +15 -8
  7. data/CHANGELOG.md +261 -0
  8. data/README.md +3 -0
  9. data/Rakefile +3 -45
  10. data/cloudinary.gemspec +27 -20
  11. data/lib/active_storage/blob_key.rb +20 -0
  12. data/lib/active_storage/service/cloudinary_service.rb +249 -0
  13. data/lib/cloudinary.rb +53 -63
  14. data/lib/cloudinary/account_api.rb +231 -0
  15. data/lib/cloudinary/account_config.rb +30 -0
  16. data/lib/cloudinary/api.rb +228 -71
  17. data/lib/cloudinary/auth_token.rb +10 -4
  18. data/lib/cloudinary/base_api.rb +79 -0
  19. data/lib/cloudinary/base_config.rb +70 -0
  20. data/lib/cloudinary/cache.rb +38 -0
  21. data/lib/cloudinary/cache/breakpoints_cache.rb +31 -0
  22. data/lib/cloudinary/cache/key_value_cache_adapter.rb +25 -0
  23. data/lib/cloudinary/cache/rails_cache_adapter.rb +34 -0
  24. data/lib/cloudinary/cache/storage/rails_cache_storage.rb +5 -0
  25. data/lib/cloudinary/carrier_wave.rb +4 -2
  26. data/lib/cloudinary/carrier_wave/remote.rb +3 -2
  27. data/lib/cloudinary/carrier_wave/storage.rb +2 -1
  28. data/lib/cloudinary/{controller.rb → cloudinary_controller.rb} +3 -5
  29. data/lib/cloudinary/config.rb +43 -0
  30. data/lib/cloudinary/helper.rb +77 -7
  31. data/lib/cloudinary/migrator.rb +3 -1
  32. data/lib/cloudinary/railtie.rb +7 -3
  33. data/lib/cloudinary/responsive.rb +111 -0
  34. data/lib/cloudinary/uploader.rb +67 -15
  35. data/lib/cloudinary/utils.rb +324 -54
  36. data/lib/cloudinary/version.rb +1 -1
  37. data/lib/cloudinary/video_helper.rb +96 -22
  38. data/lib/tasks/cloudinary/fetch_assets.rake +48 -0
  39. data/lib/tasks/{cloudinary.rake → cloudinary/sync_static.rake} +0 -0
  40. data/tools/allocate_test_cloud.sh +9 -0
  41. data/tools/get_test_cloud.sh +9 -0
  42. data/tools/update_version +220 -0
  43. data/vendor/assets/javascripts/cloudinary/jquery.cloudinary.js +51 -13
  44. data/vendor/assets/javascripts/cloudinary/jquery.fileupload.js +24 -4
  45. data/vendor/assets/javascripts/cloudinary/jquery.ui.widget.js +741 -561
  46. data/vendor/assets/javascripts/cloudinary/load-image.all.min.js +1 -1
  47. metadata +92 -67
  48. data/spec/access_control_spec.rb +0 -99
  49. data/spec/api_spec.rb +0 -545
  50. data/spec/archive_spec.rb +0 -129
  51. data/spec/auth_token_spec.rb +0 -79
  52. data/spec/cloudinary_helper_spec.rb +0 -190
  53. data/spec/cloudinary_spec.rb +0 -32
  54. data/spec/data/sync_static/app/assets/javascripts/1.coffee +0 -1
  55. data/spec/data/sync_static/app/assets/javascripts/1.js +0 -1
  56. data/spec/data/sync_static/app/assets/stylesheets/1.css +0 -3
  57. data/spec/docx.docx +0 -0
  58. data/spec/favicon.ico +0 -0
  59. data/spec/logo.png +0 -0
  60. data/spec/rake_spec.rb +0 -160
  61. data/spec/sample_asset_file.tsv +0 -4
  62. data/spec/search_spec.rb +0 -109
  63. data/spec/spec_helper.rb +0 -245
  64. data/spec/storage_spec.rb +0 -44
  65. data/spec/streaminig_profiles_api_spec.rb +0 -74
  66. data/spec/support/helpers/temp_file_helpers.rb +0 -22
  67. data/spec/support/shared_contexts/rake.rb +0 -19
  68. data/spec/uploader_spec.rb +0 -363
  69. data/spec/utils_methods_spec.rb +0 -54
  70. data/spec/utils_spec.rb +0 -906
  71. data/spec/video_tag_spec.rb +0 -251
  72. data/spec/video_url_spec.rb +0 -164
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.9.1"
3
+ VERSION = "1.20.0"
4
4
  end
@@ -3,12 +3,33 @@ module CloudinaryHelper
3
3
  DEFAULT_POSTER_OPTIONS = { :format => 'jpg', :resource_type => 'video' }
4
4
  DEFAULT_SOURCE_TYPES = %w(webm mp4 ogv)
5
5
  DEFAULT_VIDEO_OPTIONS = { :resource_type => 'video' }
6
+ DEFAULT_SOURCES = [
7
+ {
8
+ :type => "mp4",
9
+ :codecs => "hev1",
10
+ :transformations => { :video_codec => "h265" }
11
+ },
12
+ {
13
+ :type => "webm",
14
+ :codecs => "vp9",
15
+ :transformations => { :video_codec => "vp9" }
16
+ },
17
+ {
18
+ :type => "mp4",
19
+ :transformations => { :video_codec => "auto" }
20
+ },
21
+ {
22
+ :type => "webm",
23
+ :transformations => { :video_codec => "auto" }
24
+ }
25
+ ]
6
26
 
7
27
  # Creates an HTML video tag for the provided +source+
8
28
  #
9
29
  # ==== Options
10
30
  # * <tt>:source_types</tt> - Specify which source type the tag should include. defaults to webm, mp4 and ogv.
11
31
  # * <tt>:source_transformation</tt> - specific transformations to use for a specific source type.
32
+ # * <tt>:sources</tt> - list of sources (overrides :source_types when present)
12
33
  # * <tt>:poster</tt> - override default thumbnail:
13
34
  # * url: provide an ad hoc url
14
35
  # * options: with specific poster transformations and/or Cloudinary +:public_id+
@@ -20,6 +41,17 @@ module CloudinaryHelper
20
41
  # cl_video_tag("mymovie.webm", :source_types => [:webm, :mp4], :poster => {:effect => 'sepia'}) do
21
42
  # content_tag( :span, "Cannot present video!")
22
43
  # end
44
+ # cl_video_tag("mymovie", :sources => [
45
+ # {
46
+ # :type => "mp4",
47
+ # :codecs => "hev1",
48
+ # :transformations => { :video_codec => "h265" }
49
+ # },
50
+ # {
51
+ # :type => "webm",
52
+ # :transformations => { :video_codec => "auto" }
53
+ # }
54
+ # ])
23
55
  def cl_video_tag(source, options = {}, &block)
24
56
  source = strip_known_ext(source)
25
57
  video_attributes = [:autoplay,:controls,:loop,:muted,:poster, :preload]
@@ -48,30 +80,12 @@ module CloudinaryHelper
48
80
  video_options[:poster] = cl_video_thumbnail_path(source, options)
49
81
  end
50
82
 
51
- source_transformation = options.delete(:source_transformation) || {}
52
- source_types = Array(options.delete(:source_types))
53
- fallback = (capture(&block) if block_given?) || options.delete(:fallback_content)
83
+ fallback = (capture(&block) if block_given?) || options.delete(:fallback_content)
54
84
 
55
- if source_types.size > 1
56
- cloudinary_tag(source, options) do |_source, tag_options|
57
- content_tag('video', tag_options.merge(video_options)) do
58
- source_tags = source_types.map do |type|
59
- transformation = source_transformation[type.to_sym] || {}
60
- cloudinary_tag("#{source}.#{type}", options.merge(transformation)) do |url, _tag_options|
61
- mime_type = "video/#{(type == 'ogv' ? 'ogg' : type)}"
62
- tag("source", :src => url, :type => mime_type)
63
- end
64
- end
65
- source_tags.push(fallback.html_safe) unless fallback.blank?
66
- safe_join(source_tags)
67
- end
68
- end
85
+ if options[:sources]
86
+ video_tag_from_sources(source, options, video_options, fallback)
69
87
  else
70
- transformation = source_transformation[source_types.first.to_sym] || {}
71
- video_options[:src] = cl_video_path("#{source}.#{source_types.first.to_sym}", transformation.merge(options))
72
- cloudinary_tag(source, options) do |_source, tag_options|
73
- content_tag('video', fallback, tag_options.merge(video_options))
74
- end
88
+ video_tag_from_source_types(source, options, video_options, fallback)
75
89
  end
76
90
  end
77
91
 
@@ -96,6 +110,66 @@ module CloudinaryHelper
96
110
  name.sub(/\.(#{DEFAULT_SOURCE_TYPES.join("|")})$/, '')
97
111
  end
98
112
 
113
+ private
114
+
115
+ def video_tag_from_source_types(source_name, options, video_options, fallback)
116
+ source_transformation = options.delete(:source_transformation) || {}
117
+ source_types = Array(options.delete(:source_types))
118
+
119
+ if source_types.size > 1
120
+ sources = source_types.map do |type|
121
+ {
122
+ :type => type,
123
+ :transformations => source_transformation[type.to_sym] || {}
124
+ }
125
+ end
126
+
127
+ generate_tag_from_sources(:source_name => source_name,
128
+ :sources => sources,
129
+ :options => options,
130
+ :video_options => video_options,
131
+ :fallback => fallback)
132
+ else
133
+ transformation = source_transformation[source_types.first.to_sym] || {}
134
+ video_options[:src] = cl_video_path("#{source_name}.#{source_types.first.to_sym}", transformation.merge(options))
135
+ cloudinary_tag(source_name, options) do |_source, tag_options|
136
+ content_tag('video', fallback, tag_options.merge(video_options))
137
+ end
138
+ end
139
+ end
140
+
141
+ def video_tag_from_sources(source_name, options, video_options, fallback)
142
+ sources = options.delete(:sources)
143
+
144
+ generate_tag_from_sources(:source_name => source_name,
145
+ :sources => sources,
146
+ :options => options,
147
+ :video_options => video_options,
148
+ :fallback => fallback)
149
+ end
150
+
151
+ def generate_tag_from_sources(params)
152
+ source_name, sources, options, video_options, fallback = params.values_at(:source_name, :sources, :options, :video_options, :fallback)
153
+
154
+ cloudinary_tag(source_name, options) do |_source, tag_options|
155
+ content_tag('video', tag_options.merge(video_options)) do
156
+ source_tags = sources.map do |source|
157
+ type = source[:type]
158
+ transformation = source[:transformations] || {}
159
+ cloudinary_tag("#{source_name}.#{type}", options.merge(transformation)) do |url, _tag_options|
160
+ mime_type = "video/#{(type == 'ogv' ? 'ogg' : type)}"
161
+ if source[:codecs]
162
+ codecs = source[:codecs].is_a?(Array) ? source[:codecs].join(", ") : source[:codecs]
163
+ mime_type = "#{mime_type}; codecs=#{codecs}"
164
+ end
165
+ tag("source", :src => url, :type => mime_type)
166
+ end
167
+ end
168
+ source_tags.push(fallback.html_safe) unless fallback.blank?
169
+ safe_join(source_tags)
170
+ end
171
+ end
172
+ end
99
173
  end
100
174
 
101
175
 
@@ -0,0 +1,48 @@
1
+ require 'tmpdir'
2
+ require 'rest_client'
3
+ require 'json'
4
+ require 'rubygems/package'
5
+
6
+ unless Rake::Task.task_defined?('cloudinary:fetch_assets') # prevent double-loading/execution
7
+ namespace :cloudinary do
8
+ desc "Fetch the latest JavaScript library files and create the JavaScript index files"
9
+ task :fetch_assets do
10
+ index_files = %w[jquery.ui.widget.js jquery.iframe-transport.js jquery.fileupload.js jquery.cloudinary.js]
11
+ processing_files = %w[canvas-to-blob.min.js load-image.all.min.js jquery.fileupload-process.js jquery.fileupload-image.js jquery.fileupload-validate.js]
12
+ files = index_files + processing_files
13
+
14
+ release = JSON(RestClient.get("https://api.github.com/repos/cloudinary/cloudinary_js/releases/latest"))
15
+
16
+ FileUtils.rm_rf 'vendor/assets'
17
+ html_folder = 'vendor/assets/html'
18
+ FileUtils.mkdir_p html_folder
19
+ js_folder = 'vendor/assets/javascripts/cloudinary'
20
+ FileUtils.mkdir_p js_folder
21
+
22
+ puts "Fetching cloudinary_js version #{release["tag_name"]}\n\n"
23
+ sio = StringIO.new(RestClient.get(release["tarball_url"]).body)
24
+ file = Zlib::GzipReader.new(sio)
25
+ tar = Gem::Package::TarReader.new(file)
26
+ tar.each_entry do |entry|
27
+ name = File.basename(entry.full_name)
28
+ if files.include? name
29
+ js_full_name = File.join(js_folder, name)
30
+ puts "Adding #{js_full_name}"
31
+ File.write js_full_name, entry.read
32
+ elsif name == 'cloudinary_cors.html'
33
+ html_full_name = File.join(html_folder, name)
34
+ puts "Adding #{html_full_name}"
35
+ File.write html_full_name, entry.read
36
+ end
37
+ end
38
+ puts "Creating 'index.js' and 'processing.js' files"
39
+ File.open("vendor/assets/javascripts/cloudinary/index.js", "w") do |f|
40
+ index_files.each { |name| f.puts "//= require ./#{name}" }
41
+ end
42
+ File.open("vendor/assets/javascripts/cloudinary/processing.js", "w") do |f|
43
+ processing_files.each { |name| f.puts "//= require ./#{name}" }
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ API_ENDPOINT="https://sub-account-testing.cloudinary.com/create_sub_account"
4
+
5
+ SDK_NAME="${1}"
6
+
7
+ CLOUD_DETAILS=$(curl -sS -d "{\"prefix\" : \"${SDK_NAME}\"}" "${API_ENDPOINT}")
8
+
9
+ echo "${CLOUD_DETAILS}" | ruby -e "require 'json'; c=JSON.parse(ARGF.read)['payload']; puts 'cloudinary://' + c['cloudApiKey'] + ':'+ c['cloudApiSecret'] + '@' + c['cloudName']"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4
+
5
+ RUBY_VER=$(ruby -v | head -n 1 | cut -d ' ' -f 2);
6
+ SDK_VER=$(grep -oiP '(?<=VERSION = ")([a-zA-Z0-9\-.]+)(?=")' lib/cloudinary/version.rb)
7
+
8
+
9
+ bash "${DIR}"/allocate_test_cloud.sh "Ruby ${RUBY_VER} SDK ${SDK_VER}"
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Update version number and prepare for publishing the new version
4
+
5
+ set -e
6
+
7
+ # Empty to run the rest of the line and "echo" for a dry run
8
+ CMD_PREFIX=
9
+
10
+ # Add a quote if this is a dry run
11
+ QUOTE=
12
+
13
+ NEW_VERSION=
14
+
15
+ UPDATE_ONLY=false
16
+
17
+ function echo_err
18
+ {
19
+ echo "$@" 1>&2;
20
+ }
21
+
22
+ function usage
23
+ {
24
+ echo "Usage: $0 [parameters]"
25
+ echo " -v | --version <version> set a new version"
26
+ echo " -c | --current show current version"
27
+ echo " -d | --dry-run print the commands without executing them"
28
+ echo " -u | --update-only only update the version"
29
+ echo " -h | --help print this information and exit"
30
+ echo
31
+ echo "For example: $0 -v 1.2.3"
32
+ }
33
+
34
+ function process_arguments
35
+ {
36
+ while [[ "$1" != "" ]]; do
37
+ case $1 in
38
+ -v | --version )
39
+ shift
40
+ NEW_VERSION=${1:-}
41
+ if ! [[ "${NEW_VERSION}" =~ [0-9]+\.[0-9]+\.[0-9]+(\-.+)? ]]; then
42
+ echo_err "You must supply a new version after -v or --version"
43
+ echo_err "For example:"
44
+ echo_err " 1.2.3"
45
+ echo_err " 1.2.3-rc1"
46
+ echo_err ""
47
+ usage; return 1
48
+ fi
49
+ ;;
50
+ -c | --current )
51
+ echo `current_version`
52
+ exit
53
+ ;;
54
+ -d | --dry-run )
55
+ CMD_PREFIX=echo
56
+ echo "Dry Run"
57
+ echo ""
58
+ ;;
59
+ -u | --update-only )
60
+ UPDATE_ONLY=true
61
+ echo "Only update version"
62
+ echo ""
63
+ ;;
64
+ -h | --help )
65
+ usage; return 0
66
+ ;;
67
+ * )
68
+ usage; return 1
69
+ esac
70
+ shift || true
71
+ done
72
+ }
73
+
74
+ # Intentionally make pushd silent
75
+ function pushd
76
+ {
77
+ command pushd "$@" > /dev/null
78
+ }
79
+
80
+ # Intentionally make popd silent
81
+ function popd
82
+ {
83
+ command popd > /dev/null
84
+ }
85
+
86
+ # Check if one version is less than or equal than other
87
+ # Example:
88
+ # ver_lte 1.2.3 1.2.3 && echo "yes" || echo "no" # yes
89
+ # ver_lte 1.2.3 1.2.4 && echo "yes" || echo "no" # yes
90
+ # ver_lte 1.2.4 1.2.3 && echo "yes" || echo "no" # no
91
+ function ver_lte
92
+ {
93
+ [[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]]
94
+ }
95
+
96
+ # Extract the last entry or entry for a given version
97
+ # The function is not currently used in this file.
98
+ # Examples:
99
+ # changelog_last_entry
100
+ # changelog_last_entry 1.10.0
101
+ #
102
+ function changelog_last_entry
103
+ {
104
+ sed -e "1,/^${1}/d" -e '/^=/d' -e '/^$/d' -e '/^[0-9]/,$d' CHANGELOG.md
105
+ }
106
+
107
+ function verify_dependencies
108
+ {
109
+ # Test if the gnu grep is installed
110
+ if ! grep --version | grep -q GNU
111
+ then
112
+ echo_err "GNU grep is required for this script"
113
+ echo_err "You can install it using the following command:"
114
+ echo_err ""
115
+ echo_err "brew install grep --with-default-names"
116
+ return 1
117
+ fi
118
+
119
+ if [[ "${UPDATE_ONLY}" = true ]]; then
120
+ return 0;
121
+ fi
122
+
123
+ if [[ -z "$(type -t git-changelog)" ]]
124
+ then
125
+ echo_err "git-extras packages is not installed."
126
+ echo_err "You can install it using the following command:"
127
+ echo_err ""
128
+ echo_err "brew install git-extras"
129
+ return 1
130
+ fi
131
+ }
132
+
133
+ # Replace old string only if it is present in the file, otherwise return 1
134
+ function safe_replace
135
+ {
136
+ local old=$1
137
+ local new=$2
138
+ local file=$3
139
+
140
+ grep -q "${old}" "${file}" || { echo_err "${old} was not found in ${file}"; return 1; }
141
+
142
+ ${CMD_PREFIX} sed -i.bak -e "${QUOTE}s/${old}/${new}/${QUOTE}" -- "${file}" && rm -- "${file}.bak"
143
+ }
144
+
145
+ function current_version
146
+ {
147
+ grep -oiP '(?<=VERSION = ")([a-zA-Z0-9\-.]+)(?=")' lib/cloudinary/version.rb
148
+ }
149
+
150
+ function update_version
151
+ {
152
+ if [[ -z "${NEW_VERSION}" ]]; then
153
+ usage; return 1
154
+ fi
155
+
156
+ # Enter git root
157
+ pushd $(git rev-parse --show-toplevel)
158
+
159
+ local current_version=$(current_version)
160
+
161
+ if [[ -z "${current_version}" ]]; then
162
+ echo_err "Failed getting current version, please check directory structure and/or contact developer"
163
+ return 1
164
+ fi
165
+
166
+ # Use literal dot character in regular expression
167
+ local current_version_re=${current_version//./\\.}
168
+
169
+ echo "# Current version is: ${current_version}"
170
+ echo "# New version is: ${NEW_VERSION}"
171
+
172
+ ver_lte "${NEW_VERSION}" "${current_version}" && { echo_err "New version is not greater than current version"; return 1; }
173
+
174
+ # Add a quote if this is a dry run
175
+ QUOTE=${CMD_PREFIX:+"'"}
176
+
177
+ safe_replace "VERSION = \"${current_version_re}\""\
178
+ "VERSION = \"${NEW_VERSION}\""\
179
+ lib/cloudinary/version.rb\
180
+ || return 1
181
+
182
+ if [[ "${UPDATE_ONLY}" = true ]]; then
183
+ popd;
184
+ return 0;
185
+ fi
186
+
187
+ ${CMD_PREFIX} git changelog -t "${NEW_VERSION}" || true
188
+
189
+ echo ""
190
+ echo "# After editing CHANGELOG.md, optionally review changes and issue these commands:"
191
+ echo git add lib/cloudinary/version.rb CHANGELOG.md
192
+ echo git commit -m "\"Version ${NEW_VERSION}\""
193
+ echo sed -e "'1,/^${NEW_VERSION//./\\.}/d'" \
194
+ -e "'/^=/d'" \
195
+ -e "'/^$/d'" \
196
+ -e "'/^[0-9]/,\$d'" \
197
+ CHANGELOG.md \
198
+ \| git tag -a "'${NEW_VERSION}'" --file=-
199
+
200
+ # Don't run those commands on dry run
201
+ [[ -n "${CMD_PREFIX}" ]] && { popd; return 0; }
202
+
203
+ echo ""
204
+ read -p "Run the above commands automatically? (y/N): " confirm && [[ ${confirm} == [yY] || ${confirm} == [yY][eE][sS] ]] || { popd; return 0; }
205
+
206
+ git add lib/cloudinary/version.rb CHANGELOG.md
207
+ git commit -m "Version ${NEW_VERSION}"
208
+ sed -e "1,/^${NEW_VERSION//./\\.}/d" \
209
+ -e "/^=/d" \
210
+ -e "/^$/d" \
211
+ -e "/^[0-9]/,\$d" \
212
+ CHANGELOG.md \
213
+ | git tag -a "${NEW_VERSION}" --file=-
214
+
215
+ popd
216
+ }
217
+
218
+ process_arguments "$@"
219
+ verify_dependencies
220
+ update_version