/
API.go
204 lines (170 loc) · 4.06 KB
/
API.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package gozaim
import (
"encoding/json"
"net/url"
"strconv"
)
// FetchMe 認証中ユーザ情報をフェッチ
func (c *Client) FetchMe() (Me, error) {
body, err := c.get("home/user/verify", nil)
if err != nil {
return Me{}, err
}
var raw struct {
Me Me
Requested string
}
json.Unmarshal(body, &raw)
return raw.Me, nil
}
// FetchMoney 収入、支出の一覧をフェッチ
func (c *Client) FetchMoney(params url.Values) (MoneySlice, error) {
body, err := c.get("home/money", params)
if err != nil {
return nil, err
}
var raw struct {
Money MoneySlice
}
json.Unmarshal(body, &raw)
return raw.Money, nil
}
// FetchCategories カテゴリ一覧をフェッチ
func (c *Client) FetchCategories() ([]Category, error) {
body, err := c.get("home/category", nil)
if err != nil {
return nil, err
}
var raw struct {
Categories []Category
Requested int
}
json.Unmarshal(body, &raw)
return raw.Categories, nil
}
// FetchDefaultCategories デフォルトのカテゴリ一覧をフェッチ
func (c *Client) FetchDefaultCategories() ([]Category, error) {
body, err := c.get("category", nil)
if err != nil {
return nil, err
}
var raw struct {
Categories []Category
Requested int
}
json.Unmarshal(body, &raw)
return raw.Categories, nil
}
// FetchGenres ジャンル一覧をフェッチ
func (c *Client) FetchGenres() ([]Genre, error) {
body, err := c.get("home/genre", nil)
if err != nil {
return nil, err
}
var raw struct {
Genres []Genre
Requested int
}
json.Unmarshal(body, &raw)
return raw.Genres, nil
}
// FetchDefaultGenres デフォルトのジャンル一覧をフェッチ
func (c *Client) FetchDefaultGenres() ([]Genre, error) {
body, err := c.get("genre", nil)
if err != nil {
return nil, err
}
var raw struct {
Genres []Genre
Requested int
}
json.Unmarshal(body, &raw)
return raw.Genres, nil
}
// FetchAccounts 口座一覧をフェッチ
func (c *Client) FetchAccounts() ([]Account, error) {
body, err := c.get("home/account", nil)
if err != nil {
return nil, err
}
var raw struct {
Accounts []Account
Requested int
}
json.Unmarshal(body, &raw)
return raw.Accounts, nil
}
// FetchDefaultAccounts デフォルトの口座一覧をフェッチ
func (c *Client) FetchDefaultAccounts() ([]Account, error) {
body, err := c.get("account", nil)
if err != nil {
return nil, err
}
var raw struct {
Accounts []Account
Requested int
}
json.Unmarshal(body, &raw)
return raw.Accounts, nil
}
// FetchCurrencies 通貨一覧をフェッチ
func (c *Client) FetchCurrencies() ([]Currency, error) {
body, err := c.get("currency", nil)
if err != nil {
return nil, err
}
var raw struct {
Currencies []Currency
Requested int
}
json.Unmarshal(body, &raw)
return raw.Currencies, nil
}
// CreatePayment 支払い情報をPOST
func (c *Client) CreatePayment(params url.Values) (bool, error) {
_, err := c.post("home/money/payment", params)
if err != nil {
return false, err
}
return true, nil
}
// CreateIncome 収入情報をPOST
func (c *Client) CreateIncome(params url.Values) (bool, error) {
_, err := c.post("home/money/income", params)
if err != nil {
return false, err
}
return true, nil
}
// UpdatePayment 支払情報をUPDATE
func (c *Client) UpdatePayment(id int, params url.Values) (bool, error) {
_, err := c.put("home/money/payment/"+strconv.Itoa(id), params)
if err != nil {
return false, err
}
return true, nil
}
// UpdateIncome 収入情報をUPDATE
func (c *Client) UpdateIncome(id int, params url.Values) (bool, error) {
_, err := c.put("home/money/income/"+strconv.Itoa(id), params)
if err != nil {
return false, err
}
return true, nil
}
// DeletePayment 支払情報DELETE
func (c *Client) DeletePayment(id int) (bool, error) {
_, err := c.put("home/money/payment/"+strconv.Itoa(id), nil)
if err != nil {
return false, err
}
return true, nil
}
// DeleteIncome 収入情報をDELETE
func (c *Client) DeleteIncome(id int) (bool, error) {
_, err := c.put("home/money/income/"+strconv.Itoa(id), nil)
if err != nil {
return false, err
}
return true, nil
}