Module: Adzerk::Util
- Extended by:
- Util
- Included in:
- ApiEndpoint, Category, ChannelSiteMap, Client, CreativeMap, GeoTargeting, Invitation, Reporting, SiteZoneTargeting, Util
- Defined in:
- lib/adzerk/util.rb
Instance Method Summary collapse
Instance Method Details
#camelize_data(data) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/adzerk/util.rb', line 5 def camelize_data(data) return data unless data.respond_to?(:reduce) data.reduce({}) do |acc, (sym, val)| sym = sym.to_s.camelize if sym.class == Symbol acc[sym] = case val when Hash then camelize_data(val) when Array then val.map { |elem| camelize_data(elem) } else val end acc end end |
#parse_response(response) ⇒ Object
31 32 33 |
# File 'lib/adzerk/util.rb', line 31 def parse_response(response) uncamelize_data(JSON.parse(response.body)) end |
#uncamelize_data(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/adzerk/util.rb', line 18 def uncamelize_data(data) # stop condition for the recursion return data unless data.respond_to?(:reduce) data.reduce({}) do |acc, (key, val)| acc[key.underscore.to_sym] = case val when Hash then uncamelize_data(val) when Array then val.map {|elem| uncamelize_data(elem) } else val end acc end end |