Kiln » gitkiln Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

refactor the API...erm...API...so that I can pass multiple values

Changeset fbdf62764ba0

Parent f8151ea4ffc6

by Profile picture of User 12Benjamin Pollack <benjamin@fogcreek.com>

Changes to one file · Browse files at fbdf62764ba0 Showing diff from parent f8151ea4ffc6 Diff from another changeset...

Change 1 of 2 Show Entire File kiln/​kiln.go Stacked
 
34
35
36
 
 
 
 
 
 
 
 
37
38
39
 
229
230
231
232
 
233
234
235
236
237
238
239
240
241
242
243
244
 
 
 
 
245
246
 
247
248
249
250
251
252
 
253
254
 
255
256
257
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
237
238
239
 
240
241
242
243
244
 
 
 
 
 
 
 
 
245
246
247
248
249
 
250
251
252
253
254
255
 
256
257
 
258
259
260
261
@@ -34,6 +34,14 @@
   type apiParams map[string]string   +func (p *apiParams) Values() url.Values { + v := url.Values{} + for key, value := range *p { + v.Set(key, value) + } + return v +} +  type Credentials map[string]map[string]string    func NewClient(kilnUrl *url.URL) *Client { @@ -229,29 +237,25 @@
   // Returns the body from an API call via HTTP GET  func (k *Client) apiGet(route string, params apiParams) ([]byte, error) { - return k.apiRequest(route, params, "GET") + return k.apiRequest(route, params.Values(), "GET")  }    // Returns the body from an API call via HTTP POST  func (k *Client) apiPost(route string, params apiParams) ([]byte, error) { - return k.apiRequest(route, params, "POST") -} - -func (k *Client) apiRequest(route string, params apiParams, method string) ([]byte, error) { - v := url.Values{} - for key, value := range params { - v.Set(key, value) - } + return k.apiRequest(route, params.Values(), "POST") +} + +func (k *Client) apiRequest(route string, values url.Values, method string) ([]byte, error) {   if k.credentials.Token != "" { - v.Set("token", k.credentials.Token) + values.Set("token", k.credentials.Token)   }     var resp *http.Response   var err error   if method == "GET" { - resp, err = http.Get(k.apiRoute(route) + "?" + v.Encode()) + resp, err = http.Get(k.apiRoute(route) + "?" + values.Encode())   } else if method == "POST" { - resp, err = http.PostForm(k.apiRoute(route), v) + resp, err = http.PostForm(k.apiRoute(route), values)   }     if err != nil {