From 01fd83950b5d9b37ff65faf0055188e2e1fe60db Mon Sep 17 00:00:00 2001 From: Stamatis Katsaounis Date: Thu, 2 May 2024 16:35:13 +0300 Subject: [PATCH] feat: add methods to put and update with files --- client.go | 5 +++++ maasobject.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/client.go b/client.go index d90c010..a43f478 100644 --- a/client.go +++ b/client.go @@ -252,6 +252,11 @@ func (client Client) Put(uri *url.URL, parameters url.Values) ([]byte, error) { return client.nonIdempotentRequest("PUT", uri, parameters) } +// PutFiles updates an object on the API, using an HTTP "PUT" request. +func (client Client) PutFiles(uri *url.URL, parameters url.Values, files map[string][]byte) ([]byte, error) { + return client.nonIdempotentRequestFiles("PUT", uri, parameters, files) +} + // Delete deletes an object on the API, using an HTTP "DELETE" request. func (client Client) Delete(uri *url.URL) error { url := client.GetURL(uri) diff --git a/maasobject.go b/maasobject.go index 3978252..55ac593 100644 --- a/maasobject.go +++ b/maasobject.go @@ -163,6 +163,21 @@ func (obj MAASObject) Update(params url.Values) (MAASObject, error) { return jsonObj.GetMAASObject() } +// UpdateFiles modifies this object on the API, based on the values given in +// "params." It returns the object's new value as received from the API. +func (obj MAASObject) UpdateFiles(params url.Values, files map[string][]byte) (MAASObject, error) { + uri := obj.URI() + result, err := obj.client.PutFiles(uri, params, files) + if err != nil { + return MAASObject{}, err + } + jsonObj, err := Parse(obj.client, result) + if err != nil { + return MAASObject{}, err + } + return jsonObj.GetMAASObject() +} + // Delete removes this object on the API. func (obj MAASObject) Delete() error { uri := obj.URI()