Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty array to be used as a params in get requests. #34

Merged
merged 1 commit into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 7 additions & 1 deletion lib/teamlab/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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