Skip to content

Commit d59b87b

Browse files
committed
Updated currency/rates
Signed-off-by: Vishal Rana <[email protected]>
1 parent c8f9648 commit d59b87b

File tree

4 files changed

+130
-47
lines changed

4 files changed

+130
-47
lines changed

.idea/workspace.xml

+72-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

currency.go

+18
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ func (c *CurrencyService) List(req *currency.ListRequest) (*currency.ListRespons
5252
}
5353
return res, nil
5454
}
55+
56+
func (c *CurrencyService) Rates(req *currency.RatesRequest) (*currency.RatesResponse, error) {
57+
res := new(currency.RatesResponse)
58+
err := new(Error)
59+
r, e := c.resty.R().
60+
SetResult(res).
61+
SetError(err).
62+
Get("/rates")
63+
if e != nil {
64+
return nil, &Error{
65+
Message: e.Error(),
66+
}
67+
}
68+
if isError(r.StatusCode()) {
69+
return nil, err
70+
}
71+
return res, nil
72+
}

currency/currency.go

+33-24
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
package currency
22

33
import (
4-
"time"
4+
"time"
55
)
66

77
type (
8-
Currency struct {
9-
Name string `json:"name"`
10-
Code string `json:"code"`
11-
Symbol string `json:"symbol"`
12-
}
13-
14-
ConvertRequest struct {
15-
Amount float64
16-
From string
17-
To string
18-
}
19-
20-
ConvertResponse struct {
21-
Time time.Time `json:"time"`
22-
Amount float64 `json:"amount"`
23-
}
24-
25-
ListRequest struct {
26-
}
27-
28-
ListResponse struct {
29-
Currencies []*Currency `json:"currencies"`
30-
}
8+
Currency struct {
9+
Name string `json:"name"`
10+
Code string `json:"code"`
11+
Symbol string `json:"symbol"`
12+
}
13+
14+
ConvertRequest struct {
15+
Amount float64
16+
From string
17+
To string
18+
}
19+
20+
ConvertResponse struct {
21+
Time time.Time `json:"time"`
22+
Amount float64 `json:"amount"`
23+
}
24+
25+
ListRequest struct {
26+
}
27+
28+
ListResponse struct {
29+
Currencies []*Currency `json:"currencies"`
30+
}
31+
32+
RatesRequest struct {
33+
}
34+
35+
RatesResponse struct {
36+
Time time.Time `json:"time"`
37+
Base string `json:"base"`
38+
Rates map[string]float64 `json:"rates"`
39+
}
3140
)

currency_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ func TestClient_List(t *testing.T) {
2323
assert.NotZero(t, len(res.Currencies))
2424
}
2525
}
26+
27+
func TestClient_Rates(t *testing.T) {
28+
res, err := cs.Rates(&currency.RatesRequest{})
29+
if assert.Nil(t, err) {
30+
assert.NotZero(t, len(res.Rates))
31+
}
32+
}

0 commit comments

Comments
 (0)