summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/importer.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-12 02:58:55 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-12 02:58:55 (GMT)
commitaa4a870d1df23af1c26d5b675c278a08a1b8d2ec (patch)
treefaf509248b80446237e02e1484c8c2e4f1c855e5 /src/helsinki.at/rhimport/importer.go
parent2d85fe4239f7d1d4282250fed232f6cfdc381b70 (diff)
add_cart and add_cut now correctly parse the response
Diffstat (limited to 'src/helsinki.at/rhimport/importer.go')
-rw-r--r--src/helsinki.at/rhimport/importer.go46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go
index 749c895..7c85fdd 100644
--- a/src/helsinki.at/rhimport/importer.go
+++ b/src/helsinki.at/rhimport/importer.go
@@ -132,7 +132,7 @@ func NewImportResult(rdres *RDWebResult) *ImportResult {
return res
}
-func add_cart(ctx *ImportContext) (result *RDWebResult, err error) {
+func add_cart(ctx *ImportContext) (result interface{}, err error) {
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -157,11 +157,20 @@ func add_cart(ctx *ImportContext) (result *RDWebResult, err error) {
}
}
w.Close()
- return send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType())
- // TODO: on success this returns <cartAdd>...</cartAdd>
+
+ var res *http.Response
+ if res, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ return
+ }
+ defer res.Body.Close()
+
+ if res.StatusCode != http.StatusOK {
+ return NewRDWebResultFromXML(res.Body)
+ }
+ return NewRDCartAddFromXML(res.Body)
}
-func add_cut(ctx *ImportContext) (result *RDWebResult, err error) {
+func add_cut(ctx *ImportContext) (result interface{}, err error) {
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -178,8 +187,17 @@ func add_cut(ctx *ImportContext) (result *RDWebResult, err error) {
return
}
w.Close()
- return send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType())
- // TODO: on success this returns <cutAdd>...</cutAdd>
+
+ var res *http.Response
+ if res, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ return
+ }
+ defer res.Body.Close()
+
+ if res.StatusCode != http.StatusOK {
+ return NewRDWebResultFromXML(res.Body)
+ }
+ return NewRDCutAddFromXML(res.Body)
}
func remove_cart(ctx *ImportContext) (result *RDWebResult, err error) {
@@ -199,10 +217,16 @@ func remove_cart(ctx *ImportContext) (result *RDWebResult, err error) {
return
}
w.Close()
- return send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType())
+
+ var res *http.Response
+ if res, err = send_post_request(ctx.Config.RDXportEndpoint, &b, w.FormDataContentType()); err != nil {
+ return
+ }
+ defer res.Body.Close()
+ return NewRDWebResultFromXML(res.Body)
}
-func send_post_request(url string, b *bytes.Buffer, contenttype string) (result *RDWebResult, err error) {
+func send_post_request(url string, b *bytes.Buffer, contenttype string) (res *http.Response, err error) {
var req *http.Request
if req, err = http.NewRequest("POST", url, b); err != nil {
return
@@ -212,14 +236,10 @@ func send_post_request(url string, b *bytes.Buffer, contenttype string) (result
}
client := &http.Client{}
- var res *http.Response
if res, err = client.Do(req); err != nil {
return
}
- defer res.Body.Close()
-
- // TODO: some commands might return something else...
- return NewRDWebResultFromXML(res.Body)
+ return
}
func import_audio_create_request(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) {