Module: Cb::ResponseValidator

Defined in:
lib/cb/utils/validator.rb

Class Method Summary collapse

Class Method Details

.validate(response) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cb/utils/validator.rb', line 6

def self.validate(response)
  if response.blank? || response.response.body.blank?
    return false
  end

  if response.code != 200
    return false
  end

  begin
    json = JSON.parse(response.response.body)
    if json.keys.any? && json[json.keys[0]].empty?
      return false
    end
  rescue JSON::ParserError
    return false
  end

  return true

end