From 674f7f2bde2ff472812016222d11f2b59fce3355 Mon Sep 17 00:00:00 2001 From: oligirling Date: Sun, 22 Feb 2026 11:34:13 +0000 Subject: [PATCH] =?UTF-8?q?Makefile:=20test/run=20without=20build;=20OHLC:?= =?UTF-8?q?=20currency()=20=E2=86=92=20quote()=20(align=20with=20API)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- CHANGELOG.md | 5 +++++ Makefile | 18 ++++++++++-------- README.md | 6 +++--- src/classes/Ohlc.js | 6 +++--- tests/ohlc.test.js | 20 ++++++++++---------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2d24b..f9ce091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [2.1.0] - 2026-02-22 + +### Changed +- OHLC endpoint: renamed `currency()` to `quote()` and request parameter from `currency` to `quote` to align with API response field names. + ## [2.0.0] - 2026-02-19 ### Added diff --git a/Makefile b/Makefile index 8070ce9..95f79ff 100644 --- a/Makefile +++ b/Makefile @@ -2,22 +2,24 @@ .PHONY: help LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-node CONTAINER_NAME=currencyapi-node-sdk -WORKING_DIR=/application +WORKING_DIR=/app PORT=7003 -DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} ${LOCAL_DOCKER_IMAGE} -DOCKER_COMMAND_INTERACTIVE=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it ${LOCAL_DOCKER_IMAGE} +# Use official image so test/run work without building +DOCKER_IMAGE ?= node:24-slim +DOCKER_RUN = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} +DOCKER_RUN_IT = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it build: ## Build docker image docker build -t ${LOCAL_DOCKER_IMAGE} . --no-cache -test: ## Run the tests - ${DOCKER_COMMAND} npm test +test: ## Run the tests (no build required) + ${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "npm ci 2>/dev/null || npm install && npm test" install: ## Npm install - ${DOCKER_COMMAND} npm i + ${DOCKER_RUN} ${DOCKER_IMAGE} npm ci 2>/dev/null || ${DOCKER_RUN} ${DOCKER_IMAGE} npm install -run: ## Run test file - ${DOCKER_COMMAND_INTERACTIVE} node run.js +run: ## Run the run file (no build required) + ${DOCKER_RUN_IT} ${DOCKER_IMAGE} sh -c "npm ci 2>/dev/null || npm install && node run.js" publish: ## Publish version (use: make publish OTP=123456 if 2FA enabled) docker run --rm -v ${PWD}:${WORKING_DIR} -v ${HOME}/.npmrc:/home/node/.npmrc:ro -w ${WORKING_DIR} --name ${CONTAINER_NAME} ${LOCAL_DOCKER_IMAGE} npm publish $(if ${OTP},--otp=${OTP}) diff --git a/README.md b/README.md index 4a86f30..2c99ae6 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ const result = await currency ```javascript const result = await currency .ohlc() - .currency('GBP') + .quote('GBP') .date('2024-01-13') .get() ``` @@ -204,7 +204,7 @@ Example with all available methods: ```javascript const result = await currency .ohlc() - .currency('GBP') + .quote('GBP') .date('2024-01-13') .interval('1h') .base('USD') @@ -216,7 +216,7 @@ const result = await currency | Methods | Description | | --- | --- | -| `currency()` | The quote currency to retrieve OHLC data for. This will be a three letter ISO 4217 currency code. **Required**. | +| `quote()` | The quote currency to retrieve OHLC data for. This will be a three letter ISO 4217 currency code. **Required**. | | `date()` | The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. **Required**. | | `interval()` | The time interval for each candle. Allowed values: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. **Default: 1d**. | | `base()` | The base currency. **Default: USD**. | diff --git a/src/classes/Ohlc.js b/src/classes/Ohlc.js index 467c1f6..04e58bf 100644 --- a/src/classes/Ohlc.js +++ b/src/classes/Ohlc.js @@ -23,11 +23,11 @@ class Ohlc extends Endpoint { /** * Set the quote currency * - * @param {string} currency eg. 'GBP' + * @param {string} quote eg. 'GBP' * @returns {Ohlc} */ - currency(currency) { - this.addParam('currency', currency.toUpperCase()) + quote(quote) { + this.addParam('quote', quote.toUpperCase()) return this } diff --git a/tests/ohlc.test.js b/tests/ohlc.test.js index 2d2db60..ae8a28a 100644 --- a/tests/ohlc.test.js +++ b/tests/ohlc.test.js @@ -22,11 +22,11 @@ describe("Setting Ohlc", () => { expect(params).toHaveProperty('interval', '1d') }) - test('Set currency works and returns object', () => { - const setCurrency = ohlc.currency('gBp') + test('Set quote works and returns object', () => { + const setQuote = ohlc.quote('gBp') let params = ohlc.getParams() - expect(params).toHaveProperty('currency', 'GBP') - expect(setCurrency).toBeInstanceOf(Ohlc) + expect(params).toHaveProperty('quote', 'GBP') + expect(setQuote).toBeInstanceOf(Ohlc) }) test('Set date works and returns object', () => { @@ -66,10 +66,10 @@ describe("Setting Ohlc", () => { }) test('Methods can be chained', () => { - const result = ohlc.currency('GBP').date('2024-01-13').interval('1h').base('USD') + const result = ohlc.quote('GBP').date('2024-01-13').interval('1h').base('USD') expect(result).toBeInstanceOf(Ohlc) let params = ohlc.getParams() - expect(params).toHaveProperty('currency', 'GBP') + expect(params).toHaveProperty('quote', 'GBP') expect(params).toHaveProperty('date', '2024-01-13') expect(params).toHaveProperty('interval', '1h') expect(params).toHaveProperty('base', 'USD') @@ -103,9 +103,9 @@ describe("Fetching ohlc works as expected", () => { Promise.resolve(mockData) }) ) - ohlc.currency('GBP').date('2024-01-13').interval('1h') + ohlc.quote('GBP').date('2024-01-13').interval('1h') const response = await ohlc.get() - const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=JSON&interval=1h¤cy=GBP&date=2024-01-13' + const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=JSON&interval=1h"e=GBP&date=2024-01-13' expect(fetch).toHaveBeenLastCalledWith(expectedUrl, { headers: { @@ -126,10 +126,10 @@ describe("Fetching ohlc works as expected", () => { Promise.resolve(mockData) }) ) - ohlc.output('XmL').currency('GBP').date('2024-01-13') + ohlc.output('XmL').quote('GBP').date('2024-01-13') const response = await ohlc.get() - const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=XML&interval=1d¤cy=GBP&date=2024-01-13' + const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=XML&interval=1d"e=GBP&date=2024-01-13' expect(fetch).toHaveBeenLastCalledWith(expectedUrl, { headers: { "Content-Type": "application/xml",