From fabcf1865605fc518dc1302e00f7afb211ab02a1 Mon Sep 17 00:00:00 2001 From: Jae Hess Date: Sun, 12 Sep 2010 01:10:37 -0700 Subject: [PATCH] Adding Categories --- lib/remixr/client.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/remixr/client.rb b/lib/remixr/client.rb index 6fae475..24cc521 100644 --- a/lib/remixr/client.rb +++ b/lib/remixr/client.rb @@ -4,7 +4,7 @@ class Client base_uri 'api.remix.bestbuy.com/v1' format :json - attr_reader :api_key, :store_filters, :product_filters + attr_reader :api_key, :store_filters, :product_filters, :category_filters # Get your api_key found here http://remix.bestbuy.com/apps/register def initialize(api_key=nil) @@ -14,6 +14,7 @@ def initialize(api_key=nil) @api_path = '' @store_filters = {} @product_filters = {} + @category_filters = {} end # Example filters: @@ -61,6 +62,19 @@ def products(filters={}) self end + # Example filters: + # Products in Gift Center + # categories({:name => "Gift Center"}) + # GET /v1/categorie(name=”Gift Center”) + def categories(filters={}) + unless @api_path.include?('categories()') + @api_path += '+' unless @api_path.blank? + @api_path += "categories()" + end + @category_filters.merge!(filters) + self + end + # Executes the search # Possible options: @@ -73,6 +87,7 @@ def fetch(options={}) apply_store_filters apply_product_filters + apply_category_filters @api_path = URI.escape(@api_path) response = self.class.get("/" + @api_path, :query => opts) @api_path = '' @@ -96,6 +111,14 @@ def apply_product_filters end end + def apply_category_filters + if @category_filters.keys.blank? + @api_path.gsub!("categories()", "categories") + else + @api_path.gsub!("categories()", "categories(#{filter_params_string(@category_filters)})") + end + end + def filter_params_string(filters) return "" unless filters.is_a?(Hash)