Skip to content

Commit

Permalink
Updated currency/rates
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <vr@labstack.com>
  • Loading branch information
vishr committed Dec 10, 2019
1 parent c8f9648 commit d59b87b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 47 deletions.
95 changes: 72 additions & 23 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ func (c *CurrencyService) List(req *currency.ListRequest) (*currency.ListRespons
}
return res, nil
}

func (c *CurrencyService) Rates(req *currency.RatesRequest) (*currency.RatesResponse, error) {
res := new(currency.RatesResponse)
err := new(Error)
r, e := c.resty.R().
SetResult(res).
SetError(err).
Get("/rates")
if e != nil {
return nil, &Error{
Message: e.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}
57 changes: 33 additions & 24 deletions currency/currency.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package currency

import (
"time"
"time"
)

type (
Currency struct {
Name string `json:"name"`
Code string `json:"code"`
Symbol string `json:"symbol"`
}

ConvertRequest struct {
Amount float64
From string
To string
}

ConvertResponse struct {
Time time.Time `json:"time"`
Amount float64 `json:"amount"`
}

ListRequest struct {
}

ListResponse struct {
Currencies []*Currency `json:"currencies"`
}
Currency struct {
Name string `json:"name"`
Code string `json:"code"`
Symbol string `json:"symbol"`
}

ConvertRequest struct {
Amount float64
From string
To string
}

ConvertResponse struct {
Time time.Time `json:"time"`
Amount float64 `json:"amount"`
}

ListRequest struct {
}

ListResponse struct {
Currencies []*Currency `json:"currencies"`
}

RatesRequest struct {
}

RatesResponse struct {
Time time.Time `json:"time"`
Base string `json:"base"`
Rates map[string]float64 `json:"rates"`
}
)
7 changes: 7 additions & 0 deletions currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ func TestClient_List(t *testing.T) {
assert.NotZero(t, len(res.Currencies))
}
}

func TestClient_Rates(t *testing.T) {
res, err := cs.Rates(&currency.RatesRequest{})
if assert.Nil(t, err) {
assert.NotZero(t, len(res.Rates))
}
}

0 comments on commit d59b87b

Please sign in to comment.