lib/cloudinary/uploader.rb in cloudinary-1.21.0 vs lib/cloudinary/uploader.rb in cloudinary-1.22.0

- old
+ new

@@ -19,10 +19,11 @@ params = { :access_control => Cloudinary::Utils.json_array_param(options[:access_control]), :access_mode => options[:access_mode], :allowed_formats => Cloudinary::Utils.build_array(options[:allowed_formats]).join(","), + :asset_folder => options[:asset_folder], :async => Cloudinary::Utils.as_safe_bool(options[:async]), :auto_tagging => options[:auto_tagging] && options[:auto_tagging].to_f, :background_removal => options[:background_removal], :backup => Cloudinary::Utils.as_safe_bool(options[:backup]), :callback => options[:callback], @@ -31,10 +32,11 @@ :colors => Cloudinary::Utils.as_safe_bool(options[:colors]), :context => Cloudinary::Utils.encode_context(options[:context]), :custom_coordinates => Cloudinary::Utils.encode_double_array(options[:custom_coordinates]), :detection => options[:detection], :discard_original_filename => Cloudinary::Utils.as_safe_bool(options[:discard_original_filename]), + :display_name => options[:display_name], :eager => Cloudinary::Utils.build_eager(options[:eager]), :eager_async => Cloudinary::Utils.as_safe_bool(options[:eager_async]), :eager_notification_url => options[:eager_notification_url], :exif => Cloudinary::Utils.as_safe_bool(options[:exif]), :eval => options[:eval], @@ -51,10 +53,11 @@ :ocr => options[:ocr], :overwrite => Cloudinary::Utils.as_safe_bool(options[:overwrite]), :phash => Cloudinary::Utils.as_safe_bool(options[:phash]), :proxy => options[:proxy], :public_id => options[:public_id], + :public_id_prefix => options[:public_id_prefix], :quality_analysis => Cloudinary::Utils.as_safe_bool(options[:quality_analysis]), :quality_override => options[:quality_override], :raw_convert => options[:raw_convert], :responsive_breakpoints => Cloudinary::Utils.generate_responsive_breakpoints_string(options[:responsive_breakpoints]), :return_delete_token => Cloudinary::Utils.as_safe_bool(options[:return_delete_token]), @@ -64,10 +67,11 @@ :transformation => Cloudinary::Utils.generate_transformation_string(options.clone), :type => options[:type], :unique_filename => Cloudinary::Utils.as_safe_bool(options[:unique_filename]), :upload_preset => options[:upload_preset], :use_filename => Cloudinary::Utils.as_safe_bool(options[:use_filename]), + :use_filename_as_display_name => Cloudinary::Utils.as_safe_bool(options[:use_filename_as_display_name]), :accessibility_analysis => Cloudinary::Utils.as_safe_bool(options[:accessibility_analysis]), :metadata => Cloudinary::Utils.encode_context(options[:metadata]) } params end @@ -361,15 +365,23 @@ def self.call_api(action, options) options = options.clone return_error = options.delete(:return_error) use_cache = options[:use_cache] || Cloudinary.config.use_cache - params, non_signable = yield non_signable ||= [] - unless options[:unsigned] + headers = { "User-Agent" => Cloudinary::USER_AGENT } + headers['Content-Range'] = options[:content_range] if options[:content_range] + headers['X-Unique-Upload-Id'] = options[:unique_upload_id] if options[:unique_upload_id] + headers.merge!(options[:extra_headers]) if options[:extra_headers] + + oauth_token = options[:oauth_token] || Cloudinary.config.oauth_token + + if oauth_token + headers["Authorization"] = "Bearer #{oauth_token}" + elsif !options[:unsigned] api_key = options[:api_key] || Cloudinary.config.api_key || raise(CloudinaryException, "Must supply api_key") api_secret = options[:api_secret] || Cloudinary.config.api_secret || raise(CloudinaryException, "Must supply api_secret") signature_algorithm = options[:signature_algorithm] params[:signature] = Cloudinary::Utils.api_sign_request(params.reject { |k, v| non_signable.include?(k) }, api_secret, signature_algorithm) params[:api_key] = api_key @@ -377,14 +389,10 @@ proxy = options[:api_proxy] || Cloudinary.config.api_proxy timeout = options.fetch(:timeout) { Cloudinary.config.to_h.fetch(:timeout, 60) } result = nil - api_url = Cloudinary::Utils.cloudinary_api_url(action, options) - headers = { "User-Agent" => Cloudinary::USER_AGENT } - headers['Content-Range'] = options[:content_range] if options[:content_range] - headers['X-Unique-Upload-Id'] = options[:unique_upload_id] if options[:unique_upload_id] - headers.merge!(options[:extra_headers]) if options[:extra_headers] + api_url = Cloudinary::Utils.cloudinary_api_url(action, options) RestClient::Request.execute(:method => :post, :url => api_url, :payload => params.reject { |k, v| v.nil? || v=="" }, :timeout => timeout, :headers => headers, :proxy => proxy) do |response, request, tmpresult| raise CloudinaryException, "Server returned unexpected status code - #{response.code} - #{response.body}" unless [200, 400, 401, 403, 404, 500].include?(response.code) begin result = Cloudinary::Utils.json_decode(response.body)