From 88dfed6c94de38323b41b334c5c796950a4ea97b Mon Sep 17 00:00:00 2001 From: Konstantin Rafalskii Date: Tue, 19 Sep 2023 00:07:43 +0200 Subject: [PATCH 1/3] Don't translate unknown values into nil --- CHANGELOG.md | 7 +++++++ lib/uploadcare/client/uploader_client.rb | 15 +++++++++------ .../param/upload/upload_params_generator.rb | 9 +++++---- lib/uploadcare/ruby/version.rb | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbf1ac7..0fdbf8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 4.3.5 — 2023-09-19 + +### Changed + +* Don't send blank values in the `store` param. + + ## 4.3.4 — 2023-05-16 ### Changed diff --git a/lib/uploadcare/client/uploader_client.rb b/lib/uploadcare/client/uploader_client.rb index f8b64d0..ada9bc5 100644 --- a/lib/uploadcare/client/uploader_client.rb +++ b/lib/uploadcare/client/uploader_client.rb @@ -94,21 +94,24 @@ def upload_many_body(arr, options = {}) ) end - STORE_VALUES_MAP = { - true => '1', - false => '0' - }.freeze - # Prepare upload_from_url initial request body def upload_from_url_body(url, options = {}) HTTP::FormData::Multipart.new( options.merge( 'pub_key' => Uploadcare.config.public_key, 'source_url' => url, - 'store' => STORE_VALUES_MAP[options[:store]] + 'store' => store_value(options[:store]) ) ) end + + def store_value(store) + case store + when true then '1' + when false then '0' + else 'auto' + end + end end end end diff --git a/lib/uploadcare/param/upload/upload_params_generator.rb b/lib/uploadcare/param/upload/upload_params_generator.rb index 6709ebd..c27598d 100644 --- a/lib/uploadcare/param/upload/upload_params_generator.rb +++ b/lib/uploadcare/param/upload/upload_params_generator.rb @@ -20,10 +20,11 @@ def call(options = {}) private def store(store) - store = 'auto' if store.nil? - store = '0' if store == false - store = '1' if store == true - store + case store + when true then '1' + when false then '0' + else 'auto' + end end def metadata(options = {}) diff --git a/lib/uploadcare/ruby/version.rb b/lib/uploadcare/ruby/version.rb index 19c95ae..393d11e 100644 --- a/lib/uploadcare/ruby/version.rb +++ b/lib/uploadcare/ruby/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Uploadcare - VERSION = '4.3.4' + VERSION = '4.3.5' end From 334458328446b9f7751fc6ed09d10b4fb159b64c Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 19 Sep 2023 01:19:40 +0300 Subject: [PATCH 2/3] Update CHANGELOG.md Co-authored-by: Roman Sedykh --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fdbf8f..1b5c2d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -* Don't send blank values in the `store` param. +* Updated behavior to exclude sending blank values in the `store` param. ## 4.3.4 — 2023-05-16 From d46e6149bb54025a8077b89a19a3da6afba47d36 Mon Sep 17 00:00:00 2001 From: Konstantin Rafalskii Date: Tue, 19 Sep 2023 13:58:29 +0200 Subject: [PATCH 3/3] Convert more values --- lib/uploadcare/client/uploader_client.rb | 4 ++-- lib/uploadcare/param/upload/upload_params_generator.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/uploadcare/client/uploader_client.rb b/lib/uploadcare/client/uploader_client.rb index ada9bc5..e7a7424 100644 --- a/lib/uploadcare/client/uploader_client.rb +++ b/lib/uploadcare/client/uploader_client.rb @@ -107,8 +107,8 @@ def upload_from_url_body(url, options = {}) def store_value(store) case store - when true then '1' - when false then '0' + when true, '1', 1 then '1' + when false, '0', 0 then '0' else 'auto' end end diff --git a/lib/uploadcare/param/upload/upload_params_generator.rb b/lib/uploadcare/param/upload/upload_params_generator.rb index c27598d..01a0128 100644 --- a/lib/uploadcare/param/upload/upload_params_generator.rb +++ b/lib/uploadcare/param/upload/upload_params_generator.rb @@ -12,17 +12,17 @@ class << self def call(options = {}) { 'UPLOADCARE_PUB_KEY' => Uploadcare.config.public_key, - 'UPLOADCARE_STORE' => store(options[:store]), + 'UPLOADCARE_STORE' => store_value(options[:store]), 'signature' => (Upload::SignatureGenerator.call if Uploadcare.config.sign_uploads) }.merge(metadata(options)).compact end private - def store(store) + def store_value(store) case store - when true then '1' - when false then '0' + when true, '1', 1 then '1' + when false, '0', 0 then '0' else 'auto' end end