Skip to content

Commit

Permalink
BREAKING CHANGE: Standardize interval parameters
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Standardize interval parameters
  • Loading branch information
deimantas Jakovlevas committed Jan 25, 2022
1 parent 6986834 commit 9d539ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@ export const mapping = async (options: { useragent: string }): Promise<Types.Ful
* @param interval - (optional) Either "5m" or "60m". Defaults to "5m".
* @param useragent - (required) a User-Agent that describes what you're using it for,
* and if you're willing, some sort of contact info (like an email or Discord).
* @param timestamp - (optional) Timestep to return prices for.
* @param timestep - (optional) timestep to return prices for.
* If provided, will display 5-minute averages for all items we have data on for this time.
* The timestamp field represents the beginning of the 5-minute period being averaged
* @returns An associative array object.
* @see https://oldschool.runescape.wiki/w/RuneScape:Real-time_Prices
*/
export const prices = async (options: {
interval?: "5m" | "1h";
timestep?: "5m" | "1h";
timestamp?: number | string;
useragent: string;
}): Promise<Types.TimeSeriesData> => {
const { timestamp, useragent } = options || {};
let { interval } = options || {};
let { timestep } = options || {};
if (!useragent) throw new Error("useragent is required");
if (interval) interval.toLowerCase();
if (timestep) timestep.toLowerCase();

if (interval !== "5m" && interval !== "1h")
if (timestep !== "5m" && timestep !== "1h")
console.error("interval must be '5m' or '1h'. Falling back to 5min, in future, this will be an error.");
interval = interval ?? "5m";
timestep = timestep ?? "5m";

const url = timestamp
? `https://prices.runescape.wiki/api/v1/osrs/${interval}?timestamp=${timestamp}`
: `https://prices.runescape.wiki/api/v1/osrs/${interval}`;
? `https://prices.runescape.wiki/api/v1/osrs/${timestep}?timestamp=${timestamp}`
: `https://prices.runescape.wiki/api/v1/osrs/${timestep}`;

const response = (
await axios.get<{ data: any } & { timestamp: number }>(url, {
Expand Down
4 changes: 2 additions & 2 deletions tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ describe("/mapping endpoint", () => {

describe("prices /5m endpoint", () => {
it("resolves the 5min data", async () => {
const minData = await API.prices({ useragent, interval: "5m" });
const minData = await API.prices({ useragent, timestep: "5m" });
chai.expect(minData).to.have.property("4151");
});
});

describe("prices /1h endpoint", () => {
it("resolves the 1hour data", async () => {
const minData = await API.prices({ useragent, interval: "1h" });
const minData = await API.prices({ useragent, timestep: "1h" });
chai.expect(minData).to.have.property("4151");
});
});
Expand Down

0 comments on commit 9d539ee

Please sign in to comment.