Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Categories Support #1

Open
wants to merge 1 commit into from

1 participant

Jae Hess
Jae Hess

Added Support for the categories API in remix. Tests and docs coming soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 12, 2010
Jae Hess jaehess Adding Categories fabcf18
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 24 additions and 1 deletion. Show diff stats Hide diff stats

  1. +24 1 lib/remixr/client.rb
25 lib/remixr/client.rb
@@ -4,7 +4,7 @@ class Client
4 4 base_uri 'api.remix.bestbuy.com/v1'
5 5 format :json
6 6
7   - attr_reader :api_key, :store_filters, :product_filters
  7 + attr_reader :api_key, :store_filters, :product_filters, :category_filters
8 8
9 9 # Get your api_key found here http://remix.bestbuy.com/apps/register
10 10 def initialize(api_key=nil)
@@ -14,6 +14,7 @@ def initialize(api_key=nil)
14 14 @api_path = ''
15 15 @store_filters = {}
16 16 @product_filters = {}
  17 + @category_filters = {}
17 18 end
18 19
19 20 # Example filters:
@@ -61,6 +62,19 @@ def products(filters={})
61 62 self
62 63 end
63 64
  65 + # Example filters:
  66 + # Products in Gift Center
  67 + # categories({:name => "Gift Center"})
  68 + # GET /v1/categorie(name=”Gift Center”)
  69 + def categories(filters={})
  70 + unless @api_path.include?('categories()')
  71 + @api_path += '+' unless @api_path.blank?
  72 + @api_path += "categories()"
  73 + end
  74 + @category_filters.merge!(filters)
  75 + self
  76 + end
  77 +
64 78
65 79 # Executes the search
66 80 # Possible options:
@@ -73,6 +87,7 @@ def fetch(options={})
73 87
74 88 apply_store_filters
75 89 apply_product_filters
  90 + apply_category_filters
76 91 @api_path = URI.escape(@api_path)
77 92 response = self.class.get("/" + @api_path, :query => opts)
78 93 @api_path = ''
@@ -96,6 +111,14 @@ def apply_product_filters
96 111 end
97 112 end
98 113
  114 + def apply_category_filters
  115 + if @category_filters.keys.blank?
  116 + @api_path.gsub!("categories()", "categories")
  117 + else
  118 + @api_path.gsub!("categories()", "categories(#{filter_params_string(@category_filters)})")
  119 + end
  120 + end
  121 +
99 122 def filter_params_string(filters)
100 123 return "" unless filters.is_a?(Hash)
101 124

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.