From 7797f910d6a0cf179e6a070d5c414e37e121afb4 Mon Sep 17 00:00:00 2001 From: Oleg Nazarov Date: Mon, 8 Aug 2016 15:46:13 +0300 Subject: [PATCH] Allow empty array to be used as param in get requests. --- Changelog.md | 3 +++ lib/teamlab/request.rb | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 83aa52c3..9f58d72d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ # Change log +## master (unreleased) +* [#34](https://github.com/ONLYOFFICE/onlyoffice_api_gem/pull/34): Allow empty array to be used as param in get requests. + ## 0.6 ### New features * Support of keepConvertStatus for insert methods (from OnlyOffice > 8.9.1) diff --git a/lib/teamlab/request.rb b/lib/teamlab/request.rb index d53af2b5..a7199898 100644 --- a/lib/teamlab/request.rb +++ b/lib/teamlab/request.rb @@ -44,7 +44,7 @@ def request(type, args) rescue Exception => e raise e end - fail "Error #{response.code}: #{response.error}" unless response.success + raise "Error #{response.code}: #{response.error}" unless response.success response end @@ -56,6 +56,7 @@ def parse_args(args, type) command = args.first.instance_of?(Array) ? '/' + args.shift.join('/') : args.shift.to_s opts = {} opts[:body] = args.last.instance_of?(Hash) ? args.pop : {} + remove_empty_array(opts, type) opts[:headers] = Teamlab.config.headers if opts[:body].key?(:somefile) opts[:query] = opts.delete(:body) @@ -64,5 +65,10 @@ def parse_args(args, type) opts[:query] = opts.delete(:body) if type == :get [command, opts] end + + def remove_empty_array(opts, type) + return if type == :get + opts[:body].delete_if { |_key, value| value == [] } + end end end