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

add ability to use Kiln APIs via HTTP POST

Changeset ecc7c507cff2

Parent a21d9c6381f0

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

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

Change 1 of 2 Show Entire File kiln/​kiln.go Stacked
 
219
220
221
222
 
223
 
 
 
 
 
 
 
 
 
224
225
226
 
228
229
230
231
 
 
 
 
 
 
 
 
 
232
233
234
 
219
220
221
 
222
223
224
225
226
227
228
229
230
231
232
233
234
235
 
237
238
239
 
240
241
242
243
244
245
246
247
248
249
250
251
@@ -219,8 +219,17 @@
  return k.kilnRoute(fmt.Sprintf("Code/%v/%v", repo, action))  }   -// Returns the body from a Get API call +// Returns the body from an API call via HTTP GET  func (k *KilnClient) apiGet(route string, params apiParams) ([]byte, error) { + return k.apiRequest(route, params, "GET") +} + +// Returns the body from an API call via HTTP POST +func (k *KilnClient) apiPost(route string, params apiParams) ([]byte, error) { + return k.apiRequest(route, params, "POST") +} + +func (k *KilnClient) apiRequest(route string, params apiParams, method string) ([]byte, error) {   v := url.Values{}   for key, value := range params {   v.Set(key, value) @@ -228,7 +237,15 @@
  if k.credentials.Token != "" {   v.Set("token", k.credentials.Token)   } - resp, err := http.Get(k.apiRoute(route) + "?" + v.Encode()) + + var resp *http.Response + var err error + if method == "GET" { + resp, err = http.Get(k.apiRoute(route) + "?" + v.Encode()) + } else if method == "POST" { + resp, err = http.PostForm(k.apiRoute(route), v) + } +   if err != nil {   return nil, err   }