module DirectApi::Response

Yandex Direct response parser

Public Instance Methods

json_parse(response) click to toggle source
# File lib/direct_api/response.rb, line 23
def json_parse(response)
  JSON.parse(response)
end
lower_keys(h) click to toggle source
# File lib/direct_api/response.rb, line 27
def lower_keys(h)
  h.each_with_object({}) do |(key, value), memo|
    memo[key.underscore] = parse(value)
  end
end
parse(response) click to toggle source
# File lib/direct_api/response.rb, line 9
def parse(response)
  if response.is_a?(Hash)
    lower_keys(response)
  elsif response.is_a?(Array)
    response.map { |r| parse(r) }
  elsif response.is_a?(String)
    parse(json_parse(response))
  else
    response
  end
rescue JSON::ParserError
  response
end