Created
August 8, 2014 23:18
-
-
Save frankie-loves-jesus/c367f86570a2f6cf7a92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainController < ApplicationController | |
| require 'hashie' | |
| def index | |
| @json_text = <<END | |
| { | |
| "metadata": { | |
| "category": { | |
| "id": "women", | |
| "name": "Women's Fashion" | |
| }, | |
| "showSizeFilter": false, | |
| "showColorFilter": true, | |
| "offset": 0, | |
| "limit": 20, | |
| "total": 974184 | |
| }, | |
| "products": [ | |
| { | |
| "id": 377083005, | |
| "name": "BCBGeneration Women's Contrast Sleeve Trench", | |
| "currency": "USD", | |
| "price": 168, | |
| "priceLabel": "$168.00", | |
| "salePrice": 106.43, | |
| "salePriceLabel": "$106.43", | |
| "inStock": true, | |
| "retailer": { | |
| "id": "849", | |
| "name": "Amazon.com", | |
| "url": "http://www.shopstyle.com/browse/Amazon.com-US?pid=uid9616-726296-93" | |
| }, | |
| "locale": "en_US", | |
| "description": "This jacket features contrasting leather sleeves", | |
| "brand": { | |
| "id": "51", | |
| "name": "BCBG MAX AZRIA", | |
| "url": "http://www.shopstyle.com/browse/BCBG-MAX-AZRIA?pid=uid9616-726296-93" | |
| }, | |
| "clickUrl": "http://api.shopstyle.com/action/apiVisitRetailer?id=377083005&pid=uid9616-726296-93", | |
| "images": [ | |
| { | |
| "sizeName": "Small", | |
| "width": 32, | |
| "height": 40, | |
| "url": "http://resources.shopstyle.com/pim/7b/28/7b2894c203529b0956cdd6b760629d4a_small.jpg" | |
| }, | |
| { | |
| "sizeName": "Medium", | |
| "width": 112, | |
| "height": 140, | |
| "url": "http://resources.shopstyle.com/pim/7b/28/7b2894c203529b0956cdd6b760629d4a_medium.jpg" | |
| }, | |
| { | |
| "sizeName": "Large", | |
| "width": 164, | |
| "height": 205, | |
| "url": "http://resources.shopstyle.com/pim/7b/28/7b2894c203529b0956cdd6b760629d4a.jpg" | |
| } | |
| ], | |
| "colors": [ | |
| { | |
| "name": "Chino" | |
| } | |
| ], | |
| "sizes": [ | |
| { | |
| "name": "XX-Small" | |
| }, | |
| { | |
| "name": "X-Small" | |
| } | |
| ], | |
| "categories": [ | |
| { | |
| "id": "raincoats-and-trenchcoats", | |
| "name": "Raincoats & Trenchcoats" | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| END | |
| def self.prettify(x) | |
| x.is_a?(Hash) ? Hash[ x.map{|k,v| [k.underscore, prettify(v)]} ] : | |
| x.is_a?(Array) ? x.map{|v| prettify(v) } : x | |
| end | |
| response = prettify(JSON.parse(@json_text)) | |
| mashie = Hashie::Mash.new(response) | |
| @products = [] | |
| mashie.products.each do |product| | |
| @products << product['sale_price'] | |
| # @products << product['salePrice'] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment