Skip to content

Commit 6e5a28d

Browse files
committed
Progress on api/cross-sell.js
1 parent 2f9d0ac commit 6e5a28d

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

src/api/cross-sell.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// @class CrossSell
2+
// Accessible via [analytics](#foxapi-analytics) property of [FoxApi](#foxapi) instance.
3+
4+
import * as endpoints from '../endpoints';
5+
6+
export default class CrossSell {
7+
constructor(api) {
8+
this.api = api;
9+
}
10+
11+
/**
12+
* @method crossSellTrain(pointsObj: object): Promise
13+
* @param {Object} pointsObj
14+
*
15+
* Sends a collection of "points" to populate a sparse matrix for cross-sell
16+
* analytics and related product tracking. The POST body is an object with a "points" key
17+
* and value filled with an array of "Point" objects
18+
*
19+
* Example pointsObj
20+
*
21+
* ```
22+
* {
23+
* "points": [
24+
* {
25+
* "custID": 1,
26+
* "prodID": 4,
27+
* "chanID": 2,
28+
* }
29+
* ]
30+
* }
31+
* ```
32+
*/
33+
crossSellTrain(pointsObj) {
34+
return this.api.post(endpoints.crossSellTrain, pointsObj);
35+
}
36+
37+
/**
38+
* @method crossSellRelated(productId: Int, channelId: Int): Promise
39+
* @param {Int} productId
40+
* @param {Int} channelId
41+
*
42+
* Returns JSON of what products are similar to the productId in the query params.
43+
* { "products": [ RelatedProduct ] }
44+
*
45+
* Score == 1 means these products were purchased by the exact same set of customers.
46+
* Score == 0 means no customer has purchased both of these
47+
*
48+
* Example Request
49+
*
50+
* `/v1/public/recommend/prod-prod/3?channel=2
51+
*
52+
* Example Response
53+
*
54+
* ```
55+
* {
56+
* "products": [
57+
* {
58+
* "id": 2,
59+
* "score": 0
60+
* },
61+
* {
62+
* "id": 1,
63+
* "score": 1
64+
* },
65+
* {
66+
* "id": 0,
67+
* "score": 0
68+
* }
69+
* ]
70+
* }
71+
*/
72+
crossSellRelated(productId, channelId) {
73+
const query = `?channel=${channelId}`;
74+
const url = `${endpoints.crossSellRelated}${productId}${query}`;
75+
return this.api.get(url);
76+
}
77+
}
78+
79+
// @miniclass Point (CrossSell)
80+
// @field custID: Number
81+
// CustomerID number
82+
//
83+
// @field prodID: Number
84+
// ProductID number
85+
//
86+
// @field chanID: Number
87+
// Unique Channel ID number
88+
89+
// @miniclass RelatedProduct (CrossSell)
90+
// @field id: Number
91+
// RelatedProduct ID number
92+
//
93+
// @field score: Number
94+
// RelatedProduct Similarity score

src/endpoints.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ export const order = referenceNumber => `/v1/my/orders/${referenceNumber}`;
5757

5858
// analytics endpoints
5959
export const hal = '/v1/hal';
60+
61+
// cross-sell endpoints
62+
export const crossSellTrain = '/v1/public/recommend/prod-prod/train';
63+
export const crossSellRelated = '/v1/public/recommend/prod-prod/';

0 commit comments

Comments
 (0)