Can this:
def self.prettify(x)
x.is_a?(Hash) ? Hash[ x.map{ |k, v| [k.underscore, prettify(v)]} ] : x
x.is_a?(Array) ? x.map{ |v| prettify(v) } : x
end
class MainController < ApplicationController | |
require 'hashie' | |
def index | |
@json_text = <<END | |
{ | |
"metadata": { | |
"category": { | |
"id": "women", | |
"name": "Women's Fashion" |
class MainController < ApplicationController | |
require 'hashie' | |
def index | |
@json_text = <<END | |
{ | |
"products": [] | |
} | |
END |
class MainController < ApplicationController | |
def index | |
@json_text = <<END | |
{ | |
"metadata": { | |
"category": { | |
"id": "women", | |
"name": "Women's Fashion" | |
}, | |
"showSizeFilter": false, |
require 'json' | |
require 'rash' | |
@json_text = <<END | |
{ | |
"productHeader": { | |
"totalHits": 147 | |
}, | |
"products": [{ | |
"name": "Morgan Sport", |
class GetFromJson | |
include ActiveModel::Serializers::JSON | |
attr_accessor :first_name, :last_name, :country # :street_address, :postal_code, :phone, :email | |
def attributes=(hash) | |
hash.each do |key, value| | |
send("#{key}=", value) | |
end | |
end |
{ | |
"productHeader": { | |
"totalHits": 29896 | |
}, | |
"products": [{ | |
"name": "Decadent Delights", | |
"productImage": { | |
"url": "http://nlyscandinavia.scene7.com/is/image/nlyscandinavia/productOverview2/218695-0130.jpg" | |
}, | |
"language": "no", |
class AddAttachmentColumnsToPhotos < ActiveRecord::Migration | |
def self.up | |
change_table :photos do |t| | |
t.has_attached_file :attachment | |
end | |
end | |
def self.down | |
drop_attached_file :photos, :attachment | |
end |
{ | |
"productHeader": { | |
"totalHits": 2315 | |
}, | |
"products": [ | |
{ | |
"name": "Symantec pcAnywhere Host & Remote - (versie 12.5 ) - volledig pakket - 5 gebruikers - CD - Linux, Win - International", | |
"productImage": { | |
"url": "http://snpi.dell.com/snp/images/products/mlrg/nl-nl~A6854908/A6854908.jpg" | |
}, |
# WORKING LIVE APP: http://runnable.com/U9RltBIJZFsY9s0O/amazon-api-old- | |
raw_products = request.item_search(query: params) | |
hashed_products = raw_products.to_h | |
@products = [] | |
hashed_products['ItemSearchResponse']['Items']['Item'].each do |item| | |
product = OpenStruct.new | |
product.name = item['ItemAttributes']['Title'] |