diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e7903..fc15c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [3.1.0] - 2026-02-22 + +### Changed +- OHLC endpoint: renamed `setCurrency()` to `setQuote()` and request parameter from `currency` to `quote` to align with API response field names. + ## [3.0.0] - 2026-02-19 ### Added diff --git a/Dockerfile b/Dockerfile index 7554951..fc64b96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,9 @@ RUN apk --no-cache add pcre-dev linux-headers ${PHPIZE_DEPS} \ && apk del pcre-dev linux-headers ${PHPIZE_DEPS} COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer -COPY composer.json $APP_DIR/ +COPY composer.json composer.lock $APP_DIR/ +RUN composer install --no-interaction -RUN composer install \ No newline at end of file +COPY . $APP_DIR/ + +CMD ["./vendor/bin/phpunit"] \ No newline at end of file diff --git a/Makefile b/Makefile index 8b23164..f7fcf6a 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,24 @@ .PHONY: help LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-php CONTAINER_NAME=currencyapi-php -WORKING_DIR=/application +WORKING_DIR=/app PORT=7005 -DOCKER_COMMAND=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 ?= composer:2 +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} php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-html build/logs/coverage.html +test: ## Run the tests (no build required) + ${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "composer install --no-interaction && ./vendor/bin/phpunit" install: ## Composer install - ${DOCKER_COMMAND} composer install + ${DOCKER_RUN} ${DOCKER_IMAGE} composer install --no-interaction -run: ## Run test file - ${DOCKER_COMMAND} php run.php +run: ## Run the run file (no build required) + ${DOCKER_RUN_IT} ${DOCKER_IMAGE} sh -c "composer install --no-interaction && php run.php" help: @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index b8e8931..bdff835 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ Returns candlestick data for a currency pair on a given date, useful for chartin ```php $result = $currencyApi - ->setCurrency('EUR') + ->setQuote('EUR') ->setDate('2023-12-25') ->ohlc(); ``` @@ -205,7 +205,7 @@ Example with all available methods: ```php $result = $currencyApi - ->setCurrency('EUR') + ->setQuote('EUR') ->setDate('2023-12-25') ->setBase('GBP') ->setInterval('1h') @@ -216,7 +216,7 @@ $result = $currencyApi | Methods | Description | | --- | --- | -| `setCurrency()` | The currency to retrieve OHLC data for. Three letter ISO 4217 currency code. **Required**. | +| `setQuote()` | The quote currency to retrieve OHLC data for. Three letter ISO 4217 currency code. **Required**. | | `setDate()` | The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. **Required**. | | `setBase()` | The base currency for the rates. **Default: USD**. | | `setInterval()` | The interval for the OHLC candles. One of: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. **Default: 1d**. | diff --git a/src/CurrencyApi.php b/src/CurrencyApi.php index 7e1ad3d..65a6e72 100644 --- a/src/CurrencyApi.php +++ b/src/CurrencyApi.php @@ -102,12 +102,12 @@ class CurrencyApi protected $end_date = ''; /** - * The currency to retrieve OHLC data for. + * The quote currency to retrieve OHLC data for. * This will be a three letter ISO 4217 currency code. * * @var string */ - protected $currency = ''; + protected $quote = ''; /** * The interval for OHLC data. @@ -231,15 +231,15 @@ public function setEndDate(string $end_date) : CurrencyApi } /** - * Sets the currency for the OHLC endpoint - * See currency property for description ^ + * Sets the quote currency for the OHLC endpoint + * See quote property for description ^ * - * @param string $currency + * @param string $quote * @return CurrencyApi */ - public function setCurrency(string $currency) : CurrencyApi + public function setQuote(string $quote) : CurrencyApi { - $this->currency = strtoupper($currency); + $this->quote = strtoupper($quote); return $this; } @@ -374,7 +374,7 @@ protected function getTimeFrameParams() : array protected function getOhlcParams() : array { $params = [ - 'currency' => $this->currency, + 'quote' => $this->quote, 'date' => $this->date, ]; if ($this->base !== self::DEFAULT_BASE) { diff --git a/tests/CurrencyApiTest.php b/tests/CurrencyApiTest.php index 4c53f0e..f5873aa 100644 --- a/tests/CurrencyApiTest.php +++ b/tests/CurrencyApiTest.php @@ -132,11 +132,11 @@ public function testSetEndDate() $this->assertEquals($date, $this->getProtectedProperty($this->currencyApi, 'end_date')); } - public function testSetCurrency() + public function testSetQuote() { - $currency = 'eur'; - $this->assertEquals($this->currencyApi, $this->currencyApi->setCurrency($currency)); - $this->assertEquals('EUR', $this->getProtectedProperty($this->currencyApi, 'currency')); + $quote = 'eur'; + $this->assertEquals($this->currencyApi, $this->currencyApi->setQuote($quote)); + $this->assertEquals('EUR', $this->getProtectedProperty($this->currencyApi, 'quote')); } public function testSetInterval() @@ -186,30 +186,30 @@ public function testGetTimeFrameParams() public function testGetOhlcParams() { - $currency = 'EUR'; + $quote = 'EUR'; $date = '2023-12-25'; - $this->currencyApi->setCurrency($currency); + $this->currencyApi->setQuote($quote); $this->currencyApi->setDate($date); $invokedMethod = $this->invokeMethod($this->currencyApi, 'getOhlcParams'); $this->assertEquals([ - 'currency' => $currency, + 'quote' => $quote, 'date' => $date, ], $invokedMethod); } public function testGetOhlcParamsWithBaseAndInterval() { - $currency = 'EUR'; + $quote = 'EUR'; $date = '2023-12-25'; $base = 'GBP'; $interval = '1h'; - $this->currencyApi->setCurrency($currency); + $this->currencyApi->setQuote($quote); $this->currencyApi->setDate($date); $this->currencyApi->setBase($base); $this->currencyApi->setInterval($interval); $invokedMethod = $this->invokeMethod($this->currencyApi, 'getOhlcParams'); $this->assertEquals([ - 'currency' => $currency, + 'quote' => $quote, 'date' => $date, 'base' => $base, 'interval' => $interval,