add some adjument around filtering out response when given OS is not found in response data

This commit is contained in:
kenna-bmcdevitt 2020-10-27 00:31:37 -05:00
parent 84ac80289a
commit 0d7cf0761d

View file

@ -89,7 +89,11 @@ class MicrosoftKbChecker
response = make_request
json = parse_json(response)
os_results = select_os(json)
kbs_for_os(os_results) if os_results
if os_results.nil?
'Product not found in response data.'
else
kbs_for_os(os_results)
end
else
'Operating system not found.'
end
@ -102,12 +106,12 @@ class MicrosoftKbChecker
end
def kbs_for_os(os_json)
supersedence = os_json.values_at('supersedence')
supersedence = os_json.dig('supersedence')
articles = article_title_keys(os_json)
kbs = articles.map do |article_info|
num = article_info[:article_num]
os_json.values_at("articleTitle#{num}")
end
end.flatten.reject! { |kb| kb == '' }
{
os_name: os_json['name'],
kbs: kbs,