Shopsense 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README +53 -0
- data/ShopSense-API.README +157 -0
- data/lib/shopsense.rb +344 -0
- data/test/test_shopsense.rb +14 -0
- metadata +83 -0
data/LICENSE
ADDED
data/README
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
== Shopsense
|
2
|
+
|
3
|
+
Installation
|
4
|
+
================
|
5
|
+
sudo gem install Shopsense
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
API Overview
|
10
|
+
============
|
11
|
+
|
12
|
+
# Set your API key in the shopsense.yml file
|
13
|
+
pid: <uid_for_your_api_key>
|
14
|
+
|
15
|
+
|
16
|
+
# Example
|
17
|
+
require 'rubygems'
|
18
|
+
require 'Shopsense'
|
19
|
+
|
20
|
+
# Instantiate the ShopsenseAPI class
|
21
|
+
shopsense= Shopsense::ShopsenseAPI.new('uid0000-0000000-00');
|
22
|
+
|
23
|
+
# Loads the YAML configuration file
|
24
|
+
yml= shopsense.load_config();
|
25
|
+
|
26
|
+
|
27
|
+
# Search
|
28
|
+
puts shopsense.do_search({:format => 'json', :term =>'red dress', :min=> 0, :count => 10 });
|
29
|
+
|
30
|
+
# Get Trends for category_id 109
|
31
|
+
puts shopsense.get_trends( :category => 109)
|
32
|
+
|
33
|
+
# Get a particular look
|
34
|
+
puts shopsense.get_look( :look => 548347 )
|
35
|
+
|
36
|
+
# Get looks by category type eg. New, Celebrities, TopRated, Featured
|
37
|
+
puts shopsense.get_looks(:type => "Celebrities")
|
38
|
+
|
39
|
+
# Get a stylebook by user handle
|
40
|
+
puts shopsense.get_stylebook( {:handle => 'FabSugar'} )
|
41
|
+
|
42
|
+
# Get all brands
|
43
|
+
puts shopsense.get_brands({})
|
44
|
+
|
45
|
+
# Get all retailers
|
46
|
+
puts shopsense.get_retailers({})
|
47
|
+
|
48
|
+
# Get Category histogram by search term etc
|
49
|
+
puts shopsense.get_category_histogram({:term => 'red dress'})
|
50
|
+
|
51
|
+
# Get filtered histogram by filterType
|
52
|
+
puts shopsense.get_filter_histogram({:filter_type => 'Retailer', :term => 'red dress'})
|
53
|
+
|
@@ -0,0 +1,157 @@
|
|
1
|
+
API
|
2
|
+
|
3
|
+
API Overview
|
4
|
+
Methods
|
5
|
+
Sample PHP Client
|
6
|
+
API Overview
|
7
|
+
The ShopStyle API allows client applications to retrieve the underlying data for all the basic elements of the ShopStyle websites, including products, brands, retailers, categories, and looks. For ease of development, the API is a REST-style web service, composed of simple HTTP GET requests. Data is returned to the client in either XML or JSON formats. The API is client-language independent and easy to use from PHP, Java, JavaScript, or any other modern development context.
|
8
|
+
|
9
|
+
To use the ShopStyle API, you need to first sign up here to get your unique API key. Once you have this key, you can start making the API calls described below.
|
10
|
+
|
11
|
+
Intended Audience
|
12
|
+
This document is intended for programmers who would like to develop a client application that will use the ShopStyle API. The client will need to know how to invoke an HTTP request with a particular URL and process the body of the response as either XML or JSON.
|
13
|
+
|
14
|
+
How to Use the API
|
15
|
+
Here are the basic steps for using the API, regardless of the client language you are using:
|
16
|
+
|
17
|
+
Choose the method that returns the data your application needs. For example, the apiSearch method is used to get products that match a given category or brand.
|
18
|
+
Construct a URL for that method with the appropriate host, method name, and query parameters.
|
19
|
+
Invoke the URL as an HTTP GET.
|
20
|
+
When the HTTP response arrives, extract the required data elements from the response's body.
|
21
|
+
The rest of this document describes the details of constructing the right URL for each of the API's methods. The XML format of the responses may be seen by clicking on the sample URLs shown for each method. The responses in JSON format contain identical information, just in a different language.
|
22
|
+
|
23
|
+
There is also a sample client application written in PHP.
|
24
|
+
|
25
|
+
ShopStyle API URLs
|
26
|
+
All ShopStyle API URLs have the following form:
|
27
|
+
|
28
|
+
http://api.shopstyle.com/action/METHOD_NAME?pid=uid9316-2194146-60&format=FORMAT&site=SITE&...
|
29
|
+
The METHOD_NAME is taken from the list of methods in the API shown at left.
|
30
|
+
|
31
|
+
Common API Parameters
|
32
|
+
All methods in the API accept these parameters:
|
33
|
+
|
34
|
+
pid Unique API_KEY string that is assigned to the caller. Sign up here to get your Shopstyle API key. This parameter must be present.
|
35
|
+
format
|
36
|
+
|
37
|
+
The format of the response. Supported values are:
|
38
|
+
xml - The response is in XML format with UTF-8 encoding. This is the default if the parameter is absent.
|
39
|
+
json - The response is in JSON format with UTF-8 encoding.
|
40
|
+
json2 - Same as json, but numbers and booleans are returned as JSON numbers and booleans instead of strings.
|
41
|
+
jsonvar - The response is in JSON format with UTF-8 encoding and includes a JavaScript assignment statement. This is useful when the API URL is the src attribute of a script tag, as the result is stored in a variable that can be used by subsequent JavaScript code.
|
42
|
+
jsonvar2 - Same as jsonvar, but numbers and booleans are returned as JSON numbers and booleans instead of strings.
|
43
|
+
jsonp - The response is in JSON format with UTF-8 encoding wrapped in a JavaScript method called padding. The padding must be specified with the query parameter 'callback'. Only single expressions (function reference, or object property function reference) are accepted as valid paddings.
|
44
|
+
rss - The response is an RSS feed (beta).
|
45
|
+
site Specifies the ShopStyle website to be searched or queried (optional; defaults to US fashion).
|
46
|
+
www.shopstyle.com — provides access to US fashion and home products.
|
47
|
+
www.shopstyle.co.uk — provides access to UK fashion products.
|
48
|
+
Product Query Parameters
|
49
|
+
Many of the methods listed in the next section accept this set of optional product query parameters, which are similar to query parameters used by the ShopStyle websites:
|
50
|
+
|
51
|
+
fts Text search terms, as a user would enter in a Search: field.
|
52
|
+
cat A product category. Only products within the category will be returned. The easiest way to find values for this parameter is to browse to a category on the ShopStyle website and take the last element of the URL path, e.g., from http://www.shopstyle.com/browse/dresses, use "dresses." Another way is to look at the categories of the products returned by the apiSearch or to look at the list of categories from apiGetCategoryHistogram.
|
53
|
+
fl
|
54
|
+
Specify one or more filters on the query for brand, retailer, price, discount, and/or size. Each filter value has an initial letter and a numeric id. The easiest way to construct a filter list is to do a search on ShopStyle, select one or more filters in the UI, and copy the resulting URL. To convert brand or retailer names to ids, use the apiGetBrands and apiGetRetailers calls. Here is a sample URL showing sale clothing from two brands and one retailer:
|
55
|
+
|
56
|
+
http://www.shopstyle.com/browse/womens-clothes?fl=d0&fl=b3510&fl=b689&fl=r21
|
57
|
+
|
58
|
+
Filter prefixes are:
|
59
|
+
|
60
|
+
b - brand
|
61
|
+
r - retailer
|
62
|
+
p - price
|
63
|
+
d - sale
|
64
|
+
s - size
|
65
|
+
c - color
|
66
|
+
pdd A "price drop date" expressed as a number of milliseconds since Jan 1, 1970. If present, limits the results to products whose price has dropped since the given date.
|
67
|
+
prodid The id of a specific product to return. This may be specified multiple times to get many products in one response.
|
68
|
+
|
69
|
+
##########
|
70
|
+
apiSearch
|
71
|
+
This method returns a set of products that match a query, specified using the product query parameters and those listed below.
|
72
|
+
http://api.shopstyle.com/action/apiSearch?pid=uid9316-2194146-60&fts=red+dress&min=0&count=10
|
73
|
+
min The index of the first product to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
74
|
+
count The maximum number of results to return, or 20 if not specified. The maximum value is 250. Combine with the min parameter to implement paging.
|
75
|
+
Response
|
76
|
+
A list of Product objects. Each Product has an id, name, description, price, retailer, brand name, categories, images in small/medium/large, and a URL that forwards to the retailer's site.
|
77
|
+
Note: To view the response xml or json, copy an API link and paste it in your browser after replacing YOUR_API_KEY with the api key assigned to you.
|
78
|
+
|
79
|
+
########
|
80
|
+
apiGetCategoryHistogram
|
81
|
+
This method returns a list of categories and product counts that describe the results of a given product query. The query is specified using the product query parameters.
|
82
|
+
http://api.shopstyle.com/action/apiGetCategoryHistogram?pid=uid9316-2194146-60&fts=tunic
|
83
|
+
Response
|
84
|
+
A list of Category objects. Each Category has an id, name, and count of the number of query results in that category.
|
85
|
+
|
86
|
+
########
|
87
|
+
apiGetFilterHistogram
|
88
|
+
This method returns a list of filters and product counts that describe the results of a given product query. The query is specified using the product query parameters.
|
89
|
+
http://api.shopstyle.com/action/apiGetFilterHistogram?pid=uid9316-2194146-60&filterType=Retailer&fts=red+dress
|
90
|
+
filterType The type of filter data to return. Possible values are Brand, Retailer, Price, Discount, Size and Color.
|
91
|
+
Response
|
92
|
+
A list of Filter objects of the given type. Each Filter has an id, name, and count of the number of results that apply to that filter.
|
93
|
+
|
94
|
+
|
95
|
+
##############
|
96
|
+
apiGetBrands
|
97
|
+
This method returns a list of brands that have live products. Brands that have very few products will be omitted.
|
98
|
+
http://api.shopstyle.com/action/apiGetBrands?pid=uid9316-2194146-60
|
99
|
+
Response
|
100
|
+
A list of all Brands, with id, name, url, and synonyms of each.
|
101
|
+
|
102
|
+
##############
|
103
|
+
apiGetLook
|
104
|
+
This method returns information about a particular look and its products.
|
105
|
+
http://api.shopstyle.com/action/apiGetLook?pid=uid9316-2194146-60&look=548347
|
106
|
+
look The ID number of the look. An easy way to get a look's ID is to go to the Stylebook page that contains the look at the ShopStyle website and right-click on the button that you use to edit the look. From the popup menu, select "Copy Link" and paste that into any text editor. The "lookId" query parameter of that URL is the value to use for this API method.
|
107
|
+
Response
|
108
|
+
A single look, with title, description, a set of tags, and a list of products. The products have the fields listed above (see apiSearch).
|
109
|
+
|
110
|
+
|
111
|
+
##############
|
112
|
+
apiGetRetailers
|
113
|
+
This method returns a list of retailers that have live products.
|
114
|
+
http://api.shopstyle.com/action/apiGetRetailers?pid=uid9316-2194146-60
|
115
|
+
Response
|
116
|
+
A list of all Retailers, with id, name, and url of each.
|
117
|
+
|
118
|
+
###############
|
119
|
+
apiGetStylebook
|
120
|
+
This method returns information about a particular user's Stylebook, the looks within that Stylebook, and the title and description associated with each look.
|
121
|
+
http://api.shopstyle.com/action/apiGetStylebook?pid=uid9316-2194146-60&handle=FabSugar
|
122
|
+
handle The username of the Stylebook owner.
|
123
|
+
min The index of the first look to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
124
|
+
count The maximum number of results to return, or 20 if not specified. Requesting too many results may impact performance. Combine with the min parameter to implement paging.
|
125
|
+
Response
|
126
|
+
A look id of the user's Stylebook, the look id of each individual look within that Stylebook, and the title and description associated with each look.
|
127
|
+
|
128
|
+
|
129
|
+
###############
|
130
|
+
apiGetLooks
|
131
|
+
This method returns information about looks that match different kinds of searches.
|
132
|
+
http://api.shopstyle.com/action/apiGetLooks?pid=uid9316-2194146-60&type=New&min=0&count=2
|
133
|
+
type The type of search to perform. Supported values are:
|
134
|
+
New - Recently created looks.
|
135
|
+
TopRated - Recently created looks that are highly rated.
|
136
|
+
Celebrities - Looks owned by celebrity users.
|
137
|
+
Featured - Looks from featured stylebooks.
|
138
|
+
min The index of the first product to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
139
|
+
count The maximum number of results to return, or 10 if not specified. The maximum value is 50. Combine with the min parameter to implement paging.
|
140
|
+
Response
|
141
|
+
A list of looks of the given type. Each look has the fields listed above (see apiGetLook).
|
142
|
+
|
143
|
+
##############
|
144
|
+
apiVisitRetailer
|
145
|
+
This method does not return a reponse of XML or JSON data like the other elements of the API. Instead, it forwards the user to the retailer's product page for a given product. It is the typical behavior to offer when the user clicks on a product. The apiSearch method returns URLs that call this method for each of the products it returns.
|
146
|
+
http://www.shopstyle.com/action/apiVisitRetailer?pid=uid9316-2194146-60&id=27500798
|
147
|
+
id The ID number of the product. An easy way to get a product's ID is to find the product somewhere in the ShopStyle UI and right-click on the product image. From the popup menu, select "Copy Link" ("Copy link location" or "Copy shortcut" depending on your browser) and paste that into any text editor. The "id" query parameter of that URL is the value to use for this API method.
|
148
|
+
|
149
|
+
##############
|
150
|
+
apiGetTrends
|
151
|
+
This method returns the popular brands for a given category along with a sample product for the brand-category combination.
|
152
|
+
http://www.shopstyle.com/action/apiGetTrends?pid=uid9316-2194146-60&cat=109
|
153
|
+
cat Category you want to restrict the popularity search for. This is an optional parameter. If category is not supplied, all the popular brands regardless of category will be returned.
|
154
|
+
products To skip sample products, just pass value 0 for this attribute. This is an optional attribute as well.
|
155
|
+
Response
|
156
|
+
A list of trends in the given category. Each trend has a brand, category, url, and optionally the top-ranked product for each brand/category.
|
157
|
+
|
data/lib/shopsense.rb
ADDED
@@ -0,0 +1,344 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module Shopsense
|
7
|
+
|
8
|
+
class ShopsenseAPI
|
9
|
+
|
10
|
+
@has_load_config= false
|
11
|
+
|
12
|
+
def initialize( api_key )
|
13
|
+
@pid= "pid=" + api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
=begin
|
18
|
+
Loads the YAML configuration file
|
19
|
+
=end
|
20
|
+
def load_config( yml_config= {} )
|
21
|
+
@yml= yml_config
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
=begin
|
26
|
+
apiSearch
|
27
|
+
This method returns a set of products that match a query, specified using the product query parameters and those listed below.
|
28
|
+
http://api.shopstyle.com/action/apiSearch?pid=uid9316-2194146-60&fts=red+dress&min=0&count=10
|
29
|
+
min The index of the first product to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
30
|
+
count The maximum number of results to return, or 20 if not specified. The maximum value is 250. Combine with the min parameter to implement paging.
|
31
|
+
Response
|
32
|
+
A list of Product objects. Each Product has an id, name, description, price, retailer, brand name, categories, images in small/medium/large, and a URL that forwards to the retailer's site.
|
33
|
+
Note: To view the response xml or json, copy an API link and paste it in your browser after replacing YOUR_API_KEY with the api key assigned to you.
|
34
|
+
|
35
|
+
|
36
|
+
The format of the response. Supported values are:
|
37
|
+
xml - The response is in XML format with UTF-8 encoding. This is the default if the parameter is absent.
|
38
|
+
json - The response is in JSON format with UTF-8 encoding.
|
39
|
+
json2 - Same as json, but numbers and booleans are returned as JSON numbers and booleans instead of strings.
|
40
|
+
jsonvar - The response is in JSON format with UTF-8 encoding and includes a JavaScript assignment statement. This is useful when the API URL is the src attribute of a script tag, as the result is stored in a variable that can be used by subsequent JavaScript code.
|
41
|
+
jsonvar2 - Same as jsonvar, but numbers and booleans are returned as JSON numbers and booleans instead of strings.
|
42
|
+
jsonp - The response is in JSON format with UTF-8 encoding wrapped in a JavaScript method called padding. The padding must be specified with the query parameter 'callback'. Only single expressions (function reference, or object property function reference) are accepted as valid paddings.
|
43
|
+
rss - The response is an RSS feed (beta).
|
44
|
+
|
45
|
+
|
46
|
+
fts Text search terms, as a user would enter in a Search: field.
|
47
|
+
cat A product category. Only products within the category will be returned. The easiest way to find values for this parameter is to browse to a category on the ShopStyle website and take the last element of the URL path, e.g., from http://www.shopstyle.com/browse/dresses, use "dresses." Another way is to look at the categories of the products returned by the apiSearch or to look at the list of categories from apiGetCategoryHistogram.
|
48
|
+
fl
|
49
|
+
Specify one or more filters on the query for brand, retailer, price, discount, and/or size. Each filter value has an initial letter and a numeric id. The easiest way to construct a filter list is to do a search on ShopStyle, select one or more filters in the UI, and copy the resulting URL. To convert brand or retailer names to ids, use the apiGetBrands and apiGetRetailers calls. Here is a sample URL showing sale clothing from two brands and one retailer:
|
50
|
+
|
51
|
+
http://www.shopstyle.com/browse/womens-clothes?fl=d0&fl=b3510&fl=b689&fl=r21
|
52
|
+
|
53
|
+
Filter prefixes are:
|
54
|
+
|
55
|
+
b - brand
|
56
|
+
r - retailer
|
57
|
+
p - price
|
58
|
+
d - sale
|
59
|
+
s - size
|
60
|
+
c - color
|
61
|
+
pdd A "price drop date" expressed as a number of milliseconds since Jan 1, 1970. If present, limits the results to products whose price has dropped since the given date.
|
62
|
+
prodid The id of a specific product to return. This may be specified multiple times to get many products in one response.
|
63
|
+
|
64
|
+
=end
|
65
|
+
def do_search( params= {} )
|
66
|
+
url= @yml[ 'base_url'].to_s
|
67
|
+
search_url= @yml['search_url'].to_s
|
68
|
+
#pid= "pid=" + @yml['pid'].to_s
|
69
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
70
|
+
min_result= "min=" + ( params.include?(:min ) ? params[:min].to_s : 0.to_s )
|
71
|
+
count="count=" + ( params.include?(:count) ? params[:count].to_s : 10.to_s)
|
72
|
+
|
73
|
+
if params.include?(:term)
|
74
|
+
search_term= "fts=" + params[:term].split().join('+').to_s
|
75
|
+
uri= URI.parse( url + search_url + [@pid, format, search_term, min_result, count].join('&') )
|
76
|
+
return Net::HTTP.get_response( uri )
|
77
|
+
else
|
78
|
+
raise "No search term provided!"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
=begin
|
85
|
+
apiGetTrends
|
86
|
+
This method returns the popular brands for a given category along with a sample product for the brand-category combination.
|
87
|
+
http://www.shopstyle.com/action/apiGetTrends?pid=uid9316-2194146-60&cat=109
|
88
|
+
cat Category you want to restrict the popularity search for. This is an optional parameter. If category is not supplied, all the popular brands regardless of category will be returned.
|
89
|
+
products To skip sample products, just pass value 0 for this attribute. This is an optional attribute as well.
|
90
|
+
Response
|
91
|
+
A list of trends in the given category. Each trend has a brand, category, url, and optionally the top-ranked product for each brand/category.ÏÍ
|
92
|
+
=end
|
93
|
+
def get_trends( params= {})
|
94
|
+
url= @yml[ 'base_url'].to_s
|
95
|
+
trends_url= @yml['trends_url'].to_s
|
96
|
+
#pid= "pid=" + @yml['pid'].to_s
|
97
|
+
|
98
|
+
format= "format=" + (params.include?( :format) ? params[:format] : "json")
|
99
|
+
|
100
|
+
uri=""
|
101
|
+
if params.include?( :category)
|
102
|
+
category_id= "cat=" +params[:category].to_s
|
103
|
+
uri= URI.parse( url + trends_url + [pid, format, category_id].join('&') )
|
104
|
+
end
|
105
|
+
|
106
|
+
if params.include?( :products)
|
107
|
+
product_id= "products=" +params[:products].to_s
|
108
|
+
uri= URI.parse( url + trends_url + [@pid, format, product_id].join('&') )
|
109
|
+
end
|
110
|
+
|
111
|
+
return Net::HTTP.get_response( uri )
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
=begin
|
116
|
+
This method does not return a reponse of XML or JSON data like the other elements of the API. Instead, it forwards the user to the retailer's product page for a given product. It is the typical behavior to offer when the user clicks on a product. The apiSearch method returns URLs that call this method for each of the products it returns.
|
117
|
+
http://www.shopstyle.com/action/apiVisitRetailer?pid=uid9316-2194146-60&id=27500798
|
118
|
+
id The ID number of the product. An easy way to get a product's ID is to find the product somewhere in the ShopStyle UI and right-click on the product image. From the popup menu, select "Copy Link" ("Copy link location" or "Copy shortcut" depending on your browser) and paste that into any text editor. The "id" query parameter of that URL is the value to use for this API method.
|
119
|
+
=end
|
120
|
+
def visit_retailer( params= {} )
|
121
|
+
url= @yml[ 'base_url'].to_s
|
122
|
+
visit_retailers_url= @yml['visit_retailers_url'].to_s
|
123
|
+
#pid= "pid=" + @yml['pid'].to_s
|
124
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
125
|
+
retailer_id= params[:retailer_id].to_s
|
126
|
+
|
127
|
+
uri= URI.parse( url + visit_retailers_url + [@id, format, retailer_id].join('&') )
|
128
|
+
return Net::HTTP.get_response( uri )
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
=begin
|
133
|
+
This method returns information about a particular look and its products.
|
134
|
+
http://api.shopstyle.com/action/apiGetLook?pid=uid9316-2194146-60&look=548347
|
135
|
+
look The ID number of the look. An easy way to get a look's ID is to go to the Stylebook page that contains the look at the ShopStyle website and right-click on the button that you use to edit the look. From the popup menu, select "Copy Link" and paste that into any text editor. The "lookId" query parameter of that URL is the value to use for this API method.
|
136
|
+
Response
|
137
|
+
A single look, with title, description, a set of tags, and a list of products. The products have the fields listed above (see apiSearch).
|
138
|
+
=end
|
139
|
+
def get_look( params= {} )
|
140
|
+
url= @yml[ 'base_url'].to_s
|
141
|
+
look_url= @yml['look_url'].to_s
|
142
|
+
#pid= "pid=" + @yml['pid'].to_s
|
143
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
144
|
+
|
145
|
+
if params.include?( :look )
|
146
|
+
look= "look=" + params[ :look].to_s
|
147
|
+
uri= URI.parse( url + look_url + [@pid, format, look].join( '&') )
|
148
|
+
return Net::HTTP.get_response( uri )
|
149
|
+
else
|
150
|
+
raise "No look type provided!"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
=begin
|
155
|
+
This method returns information about looks that match different kinds of searches.
|
156
|
+
http://api.shopstyle.com/action/apiGetLooks?pid=uid9316-2194146-60&type=New&min=0&count=2
|
157
|
+
type The type of search to perform. Supported values are:
|
158
|
+
New - Recently created looks.
|
159
|
+
TopRated - Recently created looks that are highly rated.
|
160
|
+
Celebrities - Looks owned by celebrity users.
|
161
|
+
Featured - Looks from featured stylebooks.
|
162
|
+
min The index of the first product to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
163
|
+
count The maximum number of results to return, or 10 if not specified. The maximum value is 50. Combine with the min parameter to implement paging.
|
164
|
+
Response
|
165
|
+
A list of looks of the given type. Each look has the fields listed above (see apiGetLook).
|
166
|
+
=end
|
167
|
+
def get_looks( params= {})
|
168
|
+
url= @yml[ 'base_url'].to_s
|
169
|
+
looks_url= @yml['looks_url'].to_s
|
170
|
+
#pid= "pid=" + @yml['pid'].to_s
|
171
|
+
|
172
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
173
|
+
min_result= "min=" + ( params.include?(:min ) ? params[:min].to_s : 0.to_s )
|
174
|
+
count="count=" + ( params.include?(:count) ? params[:count].to_s : 10.to_s)
|
175
|
+
|
176
|
+
if params.include?( :type )
|
177
|
+
look_type= "type=" + params[ :type].to_s
|
178
|
+
uri= URI.parse( url + looks_url + [@pid, format, look_type, min_result, count].join('&') )
|
179
|
+
return Net::HTTP.get_response( uri )
|
180
|
+
else
|
181
|
+
raise "No look type provided!"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
=begin
|
187
|
+
This method returns information about a particular user's Stylebook, the looks within that Stylebook, and the title and description associated with each look.
|
188
|
+
http://api.shopstyle.com/action/apiGetStylebook?pid=uid9316-2194146-60&handle=FabSugar
|
189
|
+
handle The username of the Stylebook owner.
|
190
|
+
min The index of the first look to return, or 0 (zero) if not specified. A client can use this to implement paging through large result sets.
|
191
|
+
count The maximum number of results to return, or 20 if not specified. Requesting too many results may impact performance. Combine with the min parameter to implement paging.
|
192
|
+
Response
|
193
|
+
A look id of the user's Stylebook, the look id of each individual look within that Stylebook, and the title and description associated with each look.
|
194
|
+
=end
|
195
|
+
def get_stylebook( params= {} )
|
196
|
+
url= @yml[ 'base_url'].to_s
|
197
|
+
stylebook_url= @yml['stylebook_url'].to_s
|
198
|
+
#pid= "pid=" + @yml['pid'].to_s
|
199
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
200
|
+
min_result= "min=" + ( params.include?(:min ) ? params[:min].to_s : 0.to_s )
|
201
|
+
count="count=" + ( params.include?(:count) ? params[:count].to_s : 10.to_s)
|
202
|
+
|
203
|
+
if params.include?( :handle)
|
204
|
+
handle= "handle=" + params[:handle].to_s
|
205
|
+
uri= URI.parse( url + stylebook_url + [@pid, format, handle].join('&') )
|
206
|
+
return Net::HTTP.get_response( uri )
|
207
|
+
else
|
208
|
+
raise "No handle provided!"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
=begin
|
213
|
+
This method returns a list of brands that have live products. Brands that have very few products will be omitted.
|
214
|
+
http://api.shopstyle.com/action/apiGetBrands?pid=uid9316-2194146-60
|
215
|
+
Response
|
216
|
+
A list of all Brands, with id, name, url, and synonyms of each.
|
217
|
+
=end
|
218
|
+
def get_brands(params= {})
|
219
|
+
url= @yml[ 'base_url'].to_s
|
220
|
+
brands_url= @yml[ 'brands_url'].to_s
|
221
|
+
#pid= "pid=" + @yml['pid'].to_s
|
222
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
223
|
+
uri= URI.parse( url + brands_url + [@pid, format].join('&') )
|
224
|
+
return Net::HTTP.get_response( uri )
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
=begin
|
229
|
+
This method returns a list of retailers that have live products.
|
230
|
+
http://api.shopstyle.com/action/apiGetRetailers?pid=uid9316-2194146-60
|
231
|
+
Response
|
232
|
+
A list of all Retailers, with id, name, and url of each.
|
233
|
+
=end
|
234
|
+
def get_retailers( params= {} )
|
235
|
+
url= @yml[ 'base_url'].to_s
|
236
|
+
retailers_url= @yml['retailers_url'].to_s
|
237
|
+
#pid= "pid=" + @yml['pid'].to_s
|
238
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
239
|
+
|
240
|
+
uri= URI.parse( url + retailers_url + [@pid, format].join('&') )
|
241
|
+
return Net::HTTP.get_response( uri )
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
=begin
|
246
|
+
This method returns a list of categories and product counts that describe the results of a given product query. The query is specified using the product query parameters.
|
247
|
+
http://api.shopstyle.com/action/apiGetCategoryHistogram?pid=uid9316-2194146-60&fts=tunic
|
248
|
+
Response
|
249
|
+
A list of Category objects. Each Category has an id, name, and count of the number of query results in that category.
|
250
|
+
=end
|
251
|
+
def get_category_histogram( params= {})
|
252
|
+
url= @yml[ 'base_url'].to_s
|
253
|
+
category_histogram_url= @yml['category_histogram_url'].to_s
|
254
|
+
#pid= "pid=" + @yml['pid'].to_s
|
255
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
256
|
+
|
257
|
+
|
258
|
+
if params.include?( :term)
|
259
|
+
search_term= "fts=" + params[:term].split().join('+').to_s
|
260
|
+
uri= URI.parse( url + category_histogram_url + [@pid, format,search_term].join('&') )
|
261
|
+
end
|
262
|
+
|
263
|
+
if params.include?( :cat)
|
264
|
+
category_id= "cat=" +params[:category].to_s
|
265
|
+
uri= URI.parse( url + category_histogram_url + [@pid, format, category_id].join('&') )
|
266
|
+
end
|
267
|
+
|
268
|
+
if params.include?( :filter)
|
269
|
+
filter= "fl=" + params[:filter].to_s
|
270
|
+
uri= URI.parse( url + category_histogram_url + [@pid, format, filter].join('&') )
|
271
|
+
end
|
272
|
+
|
273
|
+
if params.include?( :price_drop_date)
|
274
|
+
price_drop_date= "pdd=" + params[:price_drop_date].to_s
|
275
|
+
uri= URI.parse( url + category_histogram_url + [@pid, format,price_drop_date].join('&') )
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
if params.include?( :product_id )
|
280
|
+
product_id= "prodic" + params[:product_id].to_s
|
281
|
+
uri= URI.parse( url + category_histogram_url + [@pid, format,product_id].join('&') )
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
return Net::HTTP.get_response( uri )
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
=begin
|
290
|
+
This method returns a list of filters and product counts that describe the results of a given product query. The query is specified using the product query parameters.
|
291
|
+
http://api.shopstyle.com/action/apiGetFilterHistogram?pid=2254&filterType=Retailer&fts=red+dress
|
292
|
+
filterType The type of filter data to return. Possible values are Brand, Retailer, Price, Discount, Size and Color.
|
293
|
+
Response
|
294
|
+
A list of Filter objects of the given type. Each Filter has an id, name, and count of the number of results that apply to that filter.
|
295
|
+
=end
|
296
|
+
def get_filter_histogram( params= {})
|
297
|
+
url= @yml[ 'base_url'].to_s
|
298
|
+
filter_histogram_url= @yml['filter_histogram_url'].to_s
|
299
|
+
#pid= "pid=" + @yml['pid'].to_s
|
300
|
+
format= "format=" + ( params.include?( :format) ? params[:format].to_s : "json")
|
301
|
+
|
302
|
+
if params.include?(:filter_type )
|
303
|
+
filter_type="filterType=" + params[:filter_type].to_s
|
304
|
+
else
|
305
|
+
raise "No filter type provided"
|
306
|
+
end
|
307
|
+
|
308
|
+
|
309
|
+
if params.include?( :term)
|
310
|
+
search_term= "fts=" + params[:term].split().join('+').to_s
|
311
|
+
uri= URI.parse( url + filter_histogram_url + [@pid, format,filter_type,search_term].join('&') )
|
312
|
+
end
|
313
|
+
|
314
|
+
if params.include?( :cat)
|
315
|
+
category_id= "cat=" +params[:category].to_s
|
316
|
+
uri= URI.parse( url + filter_histogram_url + [@pid, format, filter_type,category_id].join('&') )
|
317
|
+
end
|
318
|
+
|
319
|
+
if params.include?( :filter)
|
320
|
+
filter= "fl=" + params[:filter].to_s
|
321
|
+
uri= URI.parse( url + filter_histogram_url + [@pid, format, filter_type ,filter].join('&') )
|
322
|
+
end
|
323
|
+
|
324
|
+
if params.include?( :price_drop_date)
|
325
|
+
price_drop_date= "pdd=" + params[:price_drop_date].to_s
|
326
|
+
uri= URI.parse( url + filter_histogram_url + [@pid, format,filter_type, price_drop_date].join('&') )
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
if params.include?( :product_id )
|
331
|
+
product_id= "prodic" + params[:product_id].to_s
|
332
|
+
uri= URI.parse( url + filter_histogram_url + [@pid, format,filter_type, product_id].join('&') )
|
333
|
+
end
|
334
|
+
|
335
|
+
return Net::HTTP.get_response( uri )
|
336
|
+
end
|
337
|
+
|
338
|
+
end #class
|
339
|
+
end #module
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'Shopsense'
|
3
|
+
|
4
|
+
shopsense= Shopsense::ShopsenseAPI.new('uid9316-2194146-60');
|
5
|
+
yml= shopsense.load_config();
|
6
|
+
#puts shopsense.do_search({:format => 'json', :term =>'red dress', :min=> 0, :count => 10 });
|
7
|
+
#puts shopsense.get_trends( :category => 109)
|
8
|
+
#puts shopsense.get_look( :look => 548347 )
|
9
|
+
#puts shopsense.get_looks(:type => "Celebrities")
|
10
|
+
#puts shopsense.get_stylebook( {:handle => 'FabSugar'} )
|
11
|
+
#puts shopsense.get_brands({})
|
12
|
+
#puts shopsense.get_retailers({})
|
13
|
+
#puts shopsense.get_category_histogram({:term => 'red dress'})
|
14
|
+
puts shopsense.get_filter_histogram({:filter_type => 'Retailer', :term => 'red dress'})
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Shopsense
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Wagied Davids
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-28 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description:
|
35
|
+
email: w2davids@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README
|
42
|
+
files:
|
43
|
+
- LICENSE
|
44
|
+
- README
|
45
|
+
- ShopSense-API.README
|
46
|
+
- test/test_shopsense.rb
|
47
|
+
- lib/shopsense.rb
|
48
|
+
homepage: http://yoursite.example.com
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --main
|
54
|
+
- README
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.9
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Ruby API for Shopsense
|
82
|
+
test_files: []
|
83
|
+
|