Module: DirectApi::Response
- Defined in:
- lib/direct_api/response.rb
Overview
Yandex Direct response parser
Class Method Summary collapse
Class Method Details
.json_parse(response) ⇒ Object
23 24 25 |
# File 'lib/direct_api/response.rb', line 23 def json_parse(response) JSON.parse(response) end |
.lower_keys(h) ⇒ Object
27 28 29 30 31 |
# 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) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |