-
Notifications
You must be signed in to change notification settings - Fork 10
/
data.go
113 lines (95 loc) · 2.37 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package woocommerce
import (
"fmt"
"github.com/hiscaler/woocommerce-go/entity"
jsoniter "github.com/json-iterator/go"
)
type dataService service
// All list all data
func (s dataService) All() (items []entity.Data, err error) {
resp, err := s.httpClient.R().Get("/data")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &items)
}
return
}
// Continents list all continents
func (s dataService) Continents() (items []entity.Continent, err error) {
resp, err := s.httpClient.R().Get("/data/continents")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &items)
}
return
}
// Continent retrieve continent data
func (s dataService) Continent(code string) (item entity.Continent, err error) {
resp, err := s.httpClient.R().Get(fmt.Sprintf("/data/continents/%s", code))
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}
// Countries list all countries
func (s dataService) Countries() (items []entity.Country, err error) {
resp, err := s.httpClient.R().Get("/data/countries")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &items)
}
return
}
// Country retrieve country data
func (s dataService) Country(code string) (item entity.Country, err error) {
resp, err := s.httpClient.R().Get(fmt.Sprintf("/data/countries/%s", code))
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}
// Currencies list all currencies
func (s dataService) Currencies() (items []entity.Currency, err error) {
resp, err := s.httpClient.R().Get("/data/currencies")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &items)
}
return
}
// Currency retrieve currency data
func (s dataService) Currency(code string) (item entity.Currency, err error) {
resp, err := s.httpClient.R().Get(fmt.Sprintf("/data/currencies/%s", code))
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}
// CurrentCurrency retrieve current currency
func (s dataService) CurrentCurrency() (item entity.Currency, err error) {
resp, err := s.httpClient.R().Get("/data/currencies/current")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}