diff --git a/src/exchange/engines/currencyapi/exchange.go b/src/exchange/engines/currencyapi/exchange.go index af0fc246..b2e70abf 100644 --- a/src/exchange/engines/currencyapi/exchange.go +++ b/src/exchange/engines/currencyapi/exchange.go @@ -25,7 +25,7 @@ func (e Exchange) Exchange(base currency.Currency) (currency.Currencies, error) } // Unmarshal the response. - dataRates, err := extractRatesFromResp(string(body), base) + dataRates, err := e.extractRates(string(body), base) if err != nil { return nil, fmt.Errorf("failed to extract rates from response: %w", err) } diff --git a/src/exchange/engines/currencyapi/json.go b/src/exchange/engines/currencyapi/json.go index 8b7a4b4f..fc21e8c4 100644 --- a/src/exchange/engines/currencyapi/json.go +++ b/src/exchange/engines/currencyapi/json.go @@ -10,7 +10,7 @@ import ( ) // Rates field is named the same as base currency. -func extractRatesFromResp(resp string, base currency.Currency) (map[string]float64, error) { +func (e Exchange) extractRates(resp string, base currency.Currency) (map[string]float64, error) { pattern := `"` + base.Lower() + `":\s*{[^}]*}` regexp := regexp.MustCompile(pattern) match := regexp.FindString(resp) diff --git a/src/exchange/engines/currencyapi/new.go b/src/exchange/engines/currencyapi/new.go index dd7b7a3a..23e62ff7 100644 --- a/src/exchange/engines/currencyapi/new.go +++ b/src/exchange/engines/currencyapi/new.go @@ -4,14 +4,12 @@ import ( "github.com/hearchco/agent/src/exchange/currency" ) -type Exchange struct { - apiUrl string -} +type Exchange struct{} func New() Exchange { - return Exchange{apiUrl} + return Exchange{} } func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string { - return e.apiUrl + "/" + base.Lower() + ".json" + return apiUrl + "/" + base.Lower() + ".json" } diff --git a/src/exchange/engines/exchangerateapi/new.go b/src/exchange/engines/exchangerateapi/new.go index 585abb25..e699fab8 100644 --- a/src/exchange/engines/exchangerateapi/new.go +++ b/src/exchange/engines/exchangerateapi/new.go @@ -4,14 +4,12 @@ import ( "github.com/hearchco/agent/src/exchange/currency" ) -type Exchange struct { - apiUrl string -} +type Exchange struct{} func New() Exchange { - return Exchange{apiUrl} + return Exchange{} } func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string { - return e.apiUrl + "/" + base.String() + return apiUrl + "/" + base.String() } diff --git a/src/exchange/engines/frankfurter/new.go b/src/exchange/engines/frankfurter/new.go index 3fb51268..9cd21476 100644 --- a/src/exchange/engines/frankfurter/new.go +++ b/src/exchange/engines/frankfurter/new.go @@ -4,12 +4,10 @@ import ( "github.com/hearchco/agent/src/exchange/currency" ) -type Exchange struct { - apiUrl string -} +type Exchange struct{} func New() Exchange { - return Exchange{apiUrl} + return Exchange{} } func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string {