Commit 153f3d43 by Francis Zhou

reject nil args when sending request

parent 04d34fee
...@@ -11,7 +11,9 @@ require 'dingtalk_sdk' ...@@ -11,7 +11,9 @@ require 'dingtalk_sdk'
module DingtalkSdk module DingtalkSdk
module Core module Core
class RequestBuilder class RequestBuilder
attr_reader :query_args, :body_args, :query_const, :body_const, :required_args attr_reader :query_args, :body_args, \
:query_const, :body_const, \
:required_args, :allow_nil_args
def initialize def initialize
@format = nil @format = nil
...@@ -19,6 +21,7 @@ module DingtalkSdk ...@@ -19,6 +21,7 @@ module DingtalkSdk
@body_args = [] @body_args = []
@query_args = [] @query_args = []
@required_args = [] @required_args = []
@allow_nil_args = []
@body_const = {} @body_const = {}
@query_const = {} @query_const = {}
...@@ -69,6 +72,7 @@ module DingtalkSdk ...@@ -69,6 +72,7 @@ module DingtalkSdk
end end
@required_args << arg_name if option[:required] @required_args << arg_name if option[:required]
@allow_nil_args << arg_name if option[:allow_nil]
end end
def add_const(arg_name, value, option) def add_const(arg_name, value, option)
...@@ -103,10 +107,12 @@ module DingtalkSdk ...@@ -103,10 +107,12 @@ module DingtalkSdk
builder.send(:"#{arg_pos}_args").each do |arg_name| builder.send(:"#{arg_pos}_args").each do |arg_name|
arg_value = method_args[arg_name] arg_value = method_args[arg_name]
next if arg_pos == :query && arg_value.nil? if arg_value.nil?
h[arg_pos][arg_name] = arg_value if builder.allow_nil_args.include?(arg_name)
else
h[arg_pos][arg_name] = arg_value h[arg_pos][arg_name] = arg_value
end end
end
builder.send(:"#{arg_pos}_const").each do |arg_name, arg_value| builder.send(:"#{arg_pos}_const").each do |arg_name, arg_value|
h[arg_pos][arg_name] = if arg_value.respond_to?(:call) h[arg_pos][arg_name] = if arg_value.respond_to?(:call)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment