Class: Shopsense::API

Inherits:
Client
  • Object
show all
Defined in:
lib/shopsense/api.rb

Instance Method Summary collapse

Methods inherited from Client

#initialize

Constructor Details

This class inherits a constructor from Shopsense::Client

Instance Method Details

#get_brandsString

This method returns a list of brands that have live products. Brands that have very few products will be omitted.

Returns:

  • (String)

    A list of all Brands, with id, name, url, and synonyms of each.



62
63
64
# File 'lib/shopsense/api.rb', line 62

def get_brands
  return call_api( __method__)
end

#get_category_histogram(search_string = nil) ⇒ String

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.

Parameters:

  • search_string (String) (defaults to: nil)

    The string to be in the query.

Returns:

  • (String)

    A list of Category objects. Each Category has an id, name, and count of the number of query results in that category.



32
33
34
35
36
37
38
# File 'lib/shopsense/api.rb', line 32

def get_category_histogram( search_string = nil)
  raise "no search string provieded!" if( search_string === nil)

  fts = "fts=" + search_string.split().join( '+').to_s

  return call_api( __method__, fts)
end

#get_filter_histogram(filter_type = nil, search_string = nil) ⇒ String

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.

Parameters:

  • filter_type (String) (defaults to: nil)

    The type of filter data to return. Possible values are Brand, Retailer, Price, Discount, Size and Color.

  • search_string (String) (defaults to: nil)

    The string to be in the query.

Returns:

  • (String)

    A list of Category objects. Each Category has an id, name, and count of the number of query results in that category.



48
49
50
51
52
53
54
55
56
57
# File 'lib/shopsense/api.rb', line 48

def get_filter_histogram( filter_type = nil, search_string = nil)
  raise "no search string provieded!" if( search_string === nil)
  raise "invalid filter type" if( !self.filter_types.include?( filter_type))

  filterType = "filterType=" + filter_type.to_s
  fts = "fts=" + search_string.split().join( '+').to_s
  args  = [filterType, fts].join( '&')

  return call_api( __method__, args)
end

#get_look(look_id = nil) ⇒ String

This method returns information about a particular look and its products.

Parameters:

  • look_id (Integer) (defaults to: nil)

    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.

Returns:

  • (String)

    single look, with title, description, a set of tags, and a list of products. The products have the fields listed (see #search)



75
76
77
78
79
80
81
# File 'lib/shopsense/api.rb', line 75

def get_look( look_id = nil)
  raise "no look_id provieded!" if( look_id === nil)

  look = "look=" + look_id.to_s

  return call_api( __method__, look)
end

#get_looks(look_type = nil, index = 0, num_results = 10) ⇒ String

This method returns information about looks that match different kinds of searches.

Parameters:

  • look_type (Integer) (defaults to: nil)

    The type of search to perform. Supported values are: New - Recently created looks. TopRated - Recently created looks that are highly rated. Celebrities - Looks owned by celebrity users. Featured - Looks from featured stylebooks.

  • username (String)

    The username of the Stylebook owner.

  • index (Integer) (defaults to: 0)

    The start index of results returned.

  • num_results (Integer) (defaults to: 10)

    The number of results to be returned.

Returns:

  • (String)

    A list of looks of the given type.



126
127
128
129
130
131
132
133
134
135
# File 'lib/shopsense/api.rb', line 126

def get_looks( look_type = nil, index = 0, num_results = 10)
  raise "invalid filter type must be one of the following: #{self.look_types}" if( !self.look_types.include?( look_type))

  type    = "type="   + look_type.to_s
  min     = "min="    + index.to_s
  count   = "count="  + num_results.to_s
  args    = [type, min, count].join( '&')

  return call_api( __method__, args)
end

#get_retailersSting

This method returns a list of retailers that have live products.

Returns:

  • (Sting)

    A list of all Retailers, with id, name, and url of each.



85
86
87
# File 'lib/shopsense/api.rb', line 85

def get_retailers
  return call_api( __method__)
end

#get_stylebook(user_name = nil, index = 0, num_results = 10) ⇒ String

This method returns information about a particular user’s Stylebook, the looks within that Stylebook, and the title and description associated with each look.

Parameters:

  • username (String)

    The username of the Stylebook owner.

  • index (Integer) (defaults to: 0)

    The start index of results returned.

  • num_results (Integer) (defaults to: 10)

    The number of results to be returned.

Returns:

  • (String)

    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.



100
101
102
103
104
105
106
107
108
109
# File 'lib/shopsense/api.rb', line 100

def get_stylebook(  user_name = nil, index = 0, num_results = 10)
  raise "no user_name provieded!" if( user_name === nil)
  
  handle  = "handle=" + user_name.to_s
  min     = "min="    + index.to_s
  count   = "count="  + num_results.to_s
  args    = [handle, min, count].join( '&')

  return call_api( __method__, args)
end

This method returns the popular brands for a given category along with a sample product for the brand-category combination.

Parameters:

  • category (String) (defaults to: "")

    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.

Returns:

  • (String)

    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.



160
161
162
163
164
165
166
# File 'lib/shopsense/api.rb', line 160

def get_trends( category = "", products = 0)
  cat = "cat=" + category.to_s
  products = "products=" + products.to_s
  args    = [cat, products].join( '&')

  return call_api( __method__, args)
end

#search(search_string = nil, index = 0, num_results = 10) ⇒ Object

Searches the shopsense API

Parameters:

  • search_string (String) (defaults to: nil)

    The string to be in the query.

  • index (Integer) (defaults to: 0)

    The start index of results returned.

  • num_results (Integer) (defaults to: 10)

    The number of results to be returned.

Returns:

  • 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.



15
16
17
18
19
20
21
22
23
24
# File 'lib/shopsense/api.rb', line 15

def search( search_string = nil, index = 0, num_results = 10)
  raise "no search string provieded!" if( search_string === nil)

  fts   = "fts="    + search_string.split().join( '+').to_s
  min   = "min="    + index.to_s
  count = "count="  + num_results.to_s
  args  = [fts, min, count].join( '&')

  return call_api( __method__, args)
end

#visit_retailer(id) ⇒ String

TODO: 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.

Parameters:

  • The (Integer)

    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.

Returns:

  • (String)

    A web link to the retailer. $1 of the $0



149
150
151
# File 'lib/shopsense/api.rb', line 149

def visit_retailer( id)

end