Skip to content

Commit

Permalink
feat: add methods to put and update with files
Browse files Browse the repository at this point in the history
  • Loading branch information
skatsaounis committed May 2, 2024
1 parent 39eac57 commit 01fd839
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions maasobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 01fd839

Please sign in to comment.