Changeset ecc7c507cff2…
Parent a21d9c6381f0…
by Benjamin Pollack <benjamin@fogcreek.com>
Changes to one file · Browse files at ecc7c507cff2 Showing diff from parent a21d9c6381f0 Diff from another changeset...
@@ -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
}
|
Loading...