116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/huginn_http_request_agent/http_request_agent.rb', line 116
def validate_options
unless options['endpoint'].present?
errors.add(:base, "endpoint is a required field")
end
if options['payload'].present? && %w[get delete].include?(method) && !(options['payload'].is_a?(Hash) || options['payload'].is_a?(Array))
errors.add(:base, "if provided, payload must be a hash or an array")
end
if options['payload'].present? && %w[post put patch].include?(method)
if !(options['payload'].is_a?(Hash) || options['payload'].is_a?(Array)) && options['content_type'] !~ MIME_RE
errors.add(:base, "if provided, payload must be a hash or an array")
end
end
if options['content_type'] =~ MIME_RE && options['payload'].is_a?(String) && boolify(options['no_merge']) != true
errors.add(:base, "when the payload is a string, `no_merge` has to be set to `true`")
end
if options['content_type'] == 'form' && options['payload'].present? && options['payload'].is_a?(Array)
errors.add(:base, "when content_type is a form, if provided, payload must be a hash")
end
if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
errors.add(:base, "if provided, emit_events must be true or false")
end
if options.has_key?('log_requests') && boolify(options['log_requests']).nil?
errors.add(:base, "If provided, log_requests must be true or false")
end
unless %w[post get put delete patch].include?(method)
errors.add(:base, "method must be 'post', 'get', 'put', 'delete', or 'patch'")
end
if options['no_merge'].present? && !%[true false].include?(options['no_merge'].to_s)
errors.add(:base, "if provided, no_merge must be 'true' or 'false'")
end
if options['output_mode'].present? && !options['output_mode'].to_s.include?('{') && !%[clean merge].include?(options['output_mode'].to_s)
errors.add(:base, "if provided, output_mode must be 'clean' or 'merge'")
end
unless .is_a?(Hash)
errors.add(:base, "if provided, headers must be a hash")
end
validate_web_request_options!
end
|