@vlourme/stockx-api
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,2 +0,2 @@ | ||
import { Product, SearchResults } from "./index.type"; | ||
import { MarketData, Product, SearchResults, VariantMarketData } from "./index.type"; | ||
declare enum StockXLocation { | ||
@@ -50,3 +50,16 @@ US = "us", | ||
getProduct(productId: string): Promise<Product>; | ||
/** | ||
* Get the market data for a product. | ||
* @param {string} productId - The ID of the product. | ||
* @returns {Promise<MarketData>} The market data. | ||
*/ | ||
getMarketData(productId: string): Promise<MarketData[]>; | ||
/** | ||
* Get the market data for a variant of a product. | ||
* @param {string} productId - The ID of the product. | ||
* @param {string} variantId - The ID of the variant. | ||
* @returns {Promise<VariantMarketData>} The market data. | ||
*/ | ||
getVariantMarketData(productId: string, variantId: string): Promise<VariantMarketData[]>; | ||
} | ||
export { StockXAPI, StockXLocation }; |
@@ -71,3 +71,22 @@ import axios from "axios"; | ||
} | ||
/** | ||
* Get the market data for a product. | ||
* @param {string} productId - The ID of the product. | ||
* @returns {Promise<MarketData>} The market data. | ||
*/ | ||
async getMarketData(productId) { | ||
const response = await axios.get(`${this.baseUrl}/product/${productId}/market`); | ||
return response.data; | ||
} | ||
/** | ||
* Get the market data for a variant of a product. | ||
* @param {string} productId - The ID of the product. | ||
* @param {string} variantId - The ID of the variant. | ||
* @returns {Promise<VariantMarketData>} The market data. | ||
*/ | ||
async getVariantMarketData(productId, variantId) { | ||
const response = await axios.get(`${this.baseUrl}/product/${productId}/market/${variantId}`); | ||
return response.data; | ||
} | ||
} | ||
export { StockXAPI, StockXLocation }; |
@@ -47,1 +47,14 @@ export interface SearchResults { | ||
} | ||
export interface MarketData { | ||
item_id: string; | ||
median_price: number; | ||
avg_price: number; | ||
date: string; | ||
} | ||
export interface VariantMarketData { | ||
item_id: string; | ||
variant_id: string; | ||
size: string; | ||
price: number; | ||
date: string; | ||
} |
{ | ||
"name": "@vlourme/stockx-api", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "An unofficial StockX API wrapper for Node.js", | ||
@@ -43,2 +43,2 @@ "main": "dist/index.js", | ||
} | ||
} | ||
} |
@@ -6,2 +6,4 @@ # StockX API | ||
Product IDs and variant IDs are same UUIDs used by StockX. | ||
## Installation | ||
@@ -35,2 +37,21 @@ | ||
### Getting the market data for a product | ||
```javascript | ||
const marketData = await api.getMarketData( | ||
"e46adad2-21e2-48b5-86ca-9f9ebdc01322" // productId | ||
); | ||
console.log(marketData); | ||
``` | ||
### Getting the market data for a variant of a product | ||
```javascript | ||
const variantMarketData = await api.getVariantMarketData( | ||
"aa7e8a4d-720f-4fe9-a0a9-f2b47b04bea7", // productId | ||
"8e2265bc-a210-494c-ba35-9e5d71e47b51" // variantId | ||
); | ||
console.log(variantMarketData); | ||
``` | ||
### Counting products | ||
@@ -37,0 +58,0 @@ |
@@ -33,4 +33,16 @@ import { StockXAPI, StockXLocation } from './index'; | ||
}); | ||
it('should return the market data for a product', async () => { | ||
const marketData = await api.getMarketData('e46adad2-21e2-48b5-86ca-9f9ebdc01322'); | ||
expect(marketData).toBeInstanceOf(Array); | ||
expect(marketData[0]).toHaveProperty('item_id', 'e46adad2-21e2-48b5-86ca-9f9ebdc01322'); | ||
}); | ||
it('should return the market data for a variant of a product', async () => { | ||
const variantMarketData = await api.getVariantMarketData('aa7e8a4d-720f-4fe9-a0a9-f2b47b04bea7', '8e2265bc-a210-494c-ba35-9e5d71e47b51'); | ||
expect(variantMarketData).toBeInstanceOf(Array); | ||
expect(variantMarketData[0]).toHaveProperty('item_id', 'aa7e8a4d-720f-4fe9-a0a9-f2b47b04bea7'); | ||
}); | ||
}); | ||
}); | ||
}); |
import axios from "axios"; | ||
import { Product, SearchResults } from "./index.type"; | ||
import { MarketData, Product, SearchResults, VariantMarketData } from "./index.type"; | ||
@@ -79,4 +79,25 @@ enum StockXLocation { | ||
} | ||
/** | ||
* Get the market data for a product. | ||
* @param {string} productId - The ID of the product. | ||
* @returns {Promise<MarketData>} The market data. | ||
*/ | ||
async getMarketData(productId: string): Promise<MarketData[]> { | ||
const response = await axios.get(`${this.baseUrl}/product/${productId}/market`); | ||
return response.data; | ||
} | ||
/** | ||
* Get the market data for a variant of a product. | ||
* @param {string} productId - The ID of the product. | ||
* @param {string} variantId - The ID of the variant. | ||
* @returns {Promise<VariantMarketData>} The market data. | ||
*/ | ||
async getVariantMarketData(productId: string, variantId: string): Promise<VariantMarketData[]> { | ||
const response = await axios.get(`${this.baseUrl}/product/${productId}/market/${variantId}`); | ||
return response.data; | ||
} | ||
} | ||
export { StockXAPI, StockXLocation }; |
@@ -49,1 +49,16 @@ export interface SearchResults { | ||
} | ||
export interface MarketData { | ||
item_id: string | ||
median_price: number | ||
avg_price: number | ||
date: string | ||
} | ||
export interface VariantMarketData { | ||
item_id: string | ||
variant_id: string | ||
size: string | ||
price: number | ||
date: string | ||
} |
15867
426
68