Skip to content

Commit

Permalink
(refactoring): comments and documenation
Browse files Browse the repository at this point in the history
  • Loading branch information
meabed committed Sep 30, 2018
1 parent 65b0589 commit ece808e
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {
Build()
euroToUsdRate := SwapTest.Latest("EUR/USD")
fmt.Println(euroToUsdRate.GetValue())
fmt.Println(euroToUsdRate.GetRateValue())
}
```
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ var ConvertPost = func(w http.ResponseWriter, r *http.Request) {

convertRes.From = convertReq.From
convertRes.To = convertReq.To
convertRes.ExchangeValue = rate.GetValue()
convertRes.RateDateTime = rate.GetDateTime()
convertRes.ExchangeValue = rate.GetRateValue()
convertRes.RateDateTime = rate.GetRateDateTime()
convertRes.ExchangerName = rate.GetExchangerName()
convertRes.RateFromCache = false

Expand Down
4 changes: 2 additions & 2 deletions examples/main_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
Build()

euroToUsdRate := SwapTest.Latest("EUR/USD")
fmt.Println(euroToUsdRate.GetValue())
fmt.Println(euroToUsdRate.GetDateTime())
fmt.Println(euroToUsdRate.GetRateValue())
fmt.Println(euroToUsdRate.GetRateDateTime())
fmt.Println(euroToUsdRate.GetExchangerName())
}
2 changes: 1 addition & 1 deletion pkg/cache/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestStorage_Memory_GetEmpty(t *testing.T) {
assert.EqualValues(t, []byte(""), content)
}

func TestStorage_Memory_GetValue(t *testing.T) {
func TestStorage_Memory_GetRateValue(t *testing.T) {
storage := NewStorage()
storage.Set("MY_KEY", []byte("123456"), parse("5s"))
content := storage.Get("MY_KEY")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestStorage_Redis_GetEmpty(t *testing.T) {
assert.EqualValues(t, []byte(""), content)
}

func TestStorage_Redis_GetValue(t *testing.T) {
func TestStorage_Redis_GetRateValue(t *testing.T) {
storage, _ := NewStorage(redisURL)
storage.Set("MY_KEY", []byte("123456"), parse("5s"))
content := storage.Get("MY_KEY")
Expand Down
9 changes: 7 additions & 2 deletions pkg/exchanger/1forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ func (c *oneForgeApi) requestRate(from string, to string, opt ...interface{}) (*
return c, nil
}

func (c *oneForgeApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *oneForgeApi) GetRateValue() float64 {
return c.rateValue
}

func (c *oneForgeApi) GetDateTime() string {
// GetExchangerName ... return exchanger name
func (c *oneForgeApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *oneForgeApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *oneForgeApi) Latest(from string, to string, opt ...interface{}) error {

_, err := c.requestRate(from, to, opt)
Expand Down Expand Up @@ -95,6 +99,7 @@ func (c *oneForgeApi) Latest(from string, to string, opt ...interface{}) error {
return nil
}

// NewOneForgeApi ... return new instance of oneForgeApi
func NewOneForgeApi(opt map[string]string) *oneForgeApi {
keepAliveTimeout := 600 * time.Second
timeout := 5 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/1forge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestOneForgeApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`USD`, `AED`)
assert.Equal(t, float64(3.675), rate.GetValue())
assert.Equal(t, float64(3.675), rate.GetRateValue())
}
9 changes: 7 additions & 2 deletions pkg/exchanger/currencylayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ func (c *currencyLayerApi) requestRate(from string, to string, opt ...interface{
return c, nil
}

func (c *currencyLayerApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *currencyLayerApi) GetRateValue() float64 {
return c.rateValue
}

func (c *currencyLayerApi) GetDateTime() string {
// GetExchangerName ... return exchanger name
func (c *currencyLayerApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *currencyLayerApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *currencyLayerApi) Latest(from string, to string, opt ...interface{}) error {

_, err := c.requestRate(from, to, opt)
Expand Down Expand Up @@ -95,6 +99,7 @@ func (c *currencyLayerApi) Latest(from string, to string, opt ...interface{}) er
return nil
}

// NewCurrencyLayerApi ... return new instance of currencyLayerApi
func NewCurrencyLayerApi(opt map[string]string) *currencyLayerApi {
keepAliveTimeout := 600 * time.Second
timeout := 5 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/currencylayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestCurrencyLayerApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`EUR`, `USD`)
assert.Equal(t, float64(6.8064), rate.GetValue())
assert.Equal(t, float64(6.8064), rate.GetRateValue())
}
9 changes: 7 additions & 2 deletions pkg/exchanger/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ func (c *fixerApi) requestRate(from string, to string, opt ...interface{}) (*fix
return c, nil
}

func (c *fixerApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *fixerApi) GetRateValue() float64 {
return c.rateValue
}

func (c *fixerApi) GetDateTime() string {
// GetRateDateTime ... return rate datetime
func (c *fixerApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *fixerApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *fixerApi) Latest(from string, to string, opt ...interface{}) error {

// todo cache layer
Expand Down Expand Up @@ -95,6 +99,7 @@ func (c *fixerApi) Latest(from string, to string, opt ...interface{}) error {
return nil
}

// NewFixerApi ... return new instance of fixerApi
func NewFixerApi(opt map[string]string) *fixerApi {
keepAliveTimeout := 600 * time.Second
timeout := 5 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/fixer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestFixerApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`EUR`, `USD`)
assert.Equal(t, float64(3724.305775), rate.GetValue())
assert.Equal(t, float64(3724.305775), rate.GetRateValue())
}
9 changes: 7 additions & 2 deletions pkg/exchanger/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ func (c *googleApi) requestRate(from string, to string, opt ...interface{}) (*go
return c, nil
}

func (c *googleApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *googleApi) GetRateValue() float64 {
return c.rateValue
}

func (c *googleApi) GetDateTime() string {
// GetRateDateTime ... return rate datetime
func (c *googleApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *googleApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *googleApi) Latest(from string, to string, opt ...interface{}) error {

// todo cache layer
Expand Down Expand Up @@ -100,6 +104,7 @@ func (c *googleApi) Latest(from string, to string, opt ...interface{}) error {
return nil
}

// NewGoogleApi ... return new instance of googleApi
func NewGoogleApi(opt map[string]string) *googleApi {

keepAliveTimeout := 600 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestGoogleApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`EUR`, `USD`)
assert.Equal(t, float64(3.67), rate.GetValue())
assert.Equal(t, float64(3.67), rate.GetRateValue())
}
9 changes: 7 additions & 2 deletions pkg/exchanger/openexchangerates.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ func (c *openExchangeRatesApi) requestRate(from string, to string, opt ...interf
return c, nil
}

func (c *openExchangeRatesApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *openExchangeRatesApi) GetRateValue() float64 {
return c.rateValue
}

func (c *openExchangeRatesApi) GetDateTime() string {
// GetRateDateTime ... return rate datetime
func (c *openExchangeRatesApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *openExchangeRatesApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *openExchangeRatesApi) Latest(from string, to string, opt ...interface{}) error {

_, err := c.requestRate(from, to, opt)
Expand Down Expand Up @@ -95,6 +99,7 @@ func (c *openExchangeRatesApi) Latest(from string, to string, opt ...interface{}
return nil
}

// NewOpenExchangeRatesApi ... return new instance of openExchangeRatesApi
func NewOpenExchangeRatesApi(opt map[string]string) *openExchangeRatesApi {
keepAliveTimeout := 600 * time.Second
timeout := 5 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/openexchangerates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestOpenExchangeRatesApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`USD`, `AED`)
assert.Equal(t, float64(3.6571), rate.GetValue())
assert.Equal(t, float64(3.6571), rate.GetRateValue())
}
9 changes: 7 additions & 2 deletions pkg/exchanger/themoneyconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ func (c *theMoneyConverterApi) requestRate(from string, to string, opt ...interf
return c, nil
}

func (c *theMoneyConverterApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *theMoneyConverterApi) GetRateValue() float64 {
return c.rateValue
}

func (c *theMoneyConverterApi) GetDateTime() string {
// GetRateDateTime ... return rate datetime
func (c *theMoneyConverterApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *theMoneyConverterApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *theMoneyConverterApi) Latest(from string, to string, opt ...interface{}) error {

// todo cache layer
Expand Down Expand Up @@ -103,6 +107,7 @@ func (c *theMoneyConverterApi) Latest(from string, to string, opt ...interface{}
return nil
}

// NewTheMoneyConverterApi ... return new instance of theMoneyConverterApi
func NewTheMoneyConverterApi(opt map[string]string) *theMoneyConverterApi {

keepAliveTimeout := 600 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchanger/themoneyconverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestTheMoneyConverterApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`EUR`, `EUR`)
assert.Equal(t, float64(1), rate.GetValue())
assert.Equal(t, float64(1), rate.GetRateValue())

rate.Latest(`USD`, `AED`)
assert.Equal(t, float64(3.6725), rate.GetValue())
assert.Equal(t, float64(3.6725), rate.GetRateValue())
}
4 changes: 2 additions & 2 deletions pkg/exchanger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

type Rate interface {
GetValue() float64
GetDateTime() string
GetRateValue() float64
GetRateDateTime() string
GetExchangerName() string
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/exchanger/yahoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ func (c *yahooApi) requestRate(from string, to string, opt ...interface{}) (*yah
return c, nil
}

func (c *yahooApi) GetValue() float64 {
// GetRateValue ... get exchange rate value
func (c *yahooApi) GetRateValue() float64 {
return c.rateValue
}

func (c *yahooApi) GetDateTime() string {
// GetRateDateTime ... return rate datetime
func (c *yahooApi) GetRateDateTime() string {
return c.rateDate.Format(time.RFC3339)
}

// GetExchangerName ... return exchanger name
func (c *yahooApi) GetExchangerName() string {
return c.name
}

// Latest ... populate latest exchange rate
func (c *yahooApi) Latest(from string, to string, opt ...interface{}) error {

_, err := c.requestRate(from, to, opt)
Expand Down Expand Up @@ -99,6 +103,7 @@ func (c *yahooApi) Latest(from string, to string, opt ...interface{}) error {
return nil
}

// NewYahooApi ... return new instance of yahooApi
func NewYahooApi(opt map[string]string) *yahooApi {
keepAliveTimeout := 600 * time.Second
timeout := 5 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion pkg/exchanger/yahoo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func TestYahooApi_Latest(t *testing.T) {
rate.Client.Transport = staticMock.NewTestMT()

rate.Latest(`USD`, `EUR`)
assert.Equal(t, float64(0.272272), rate.GetValue())
assert.Equal(t, float64(0.272272), rate.GetRateValue())
}
8 changes: 4 additions & 4 deletions pkg/swap/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func TestSwap_Build_Google(t *testing.T) {
Build()

euroToUsdRate := SwapTest.Latest("EUR/USD")
assert.Equal(t, float64(3.67), euroToUsdRate.GetValue())
assert.Equal(t, float64(3.67), euroToUsdRate.GetRateValue())
assert.Equal(t, `google`, euroToUsdRate.GetExchangerName())

usdToUsdRate := SwapTest.Latest("USD/USD")
assert.Equal(t, float64(1), usdToUsdRate.GetValue())
assert.Equal(t, float64(1), usdToUsdRate.GetRateValue())
assert.Equal(t, `google`, euroToUsdRate.GetExchangerName())
}

Expand All @@ -65,7 +65,7 @@ func TestSwap_Build_Yahoo(t *testing.T) {
Build()

euroToUsdRate := SwapTest.Latest("EUR/USD")
assert.Equal(t, float64(0.272272), euroToUsdRate.GetValue())
assert.Equal(t, float64(0.272272), euroToUsdRate.GetRateValue())
assert.Equal(t, `yahoo`, euroToUsdRate.GetExchangerName())
}

Expand All @@ -82,6 +82,6 @@ func TestSwap_Build_Stack_Google_Yahoo(t *testing.T) {
Build()

euroToUsdRate := SwapTest.Latest("EUR/USD")
assert.Equal(t, float64(3.67), euroToUsdRate.GetValue())
assert.Equal(t, float64(3.67), euroToUsdRate.GetRateValue())
assert.Equal(t, `google`, euroToUsdRate.GetExchangerName())
}

0 comments on commit ece808e

Please sign in to comment.