Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement batch operations for dictionary items #125

Merged
merged 10 commits into from
Jul 22, 2019
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ _testmain.go

bin/
pkg/

.envrc
43 changes: 43 additions & 0 deletions fastly/dictionary_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,49 @@ func (c *Client) UpdateDictionaryItem(i *UpdateDictionaryItemInput) (*Dictionary
return b, nil
}

type BatchModifyDictionaryItemsInput struct {
Service string `json:"-,"`
Dictionary string `json:"-,"`

Items []BatchDictionaryItem `json:"items"`
}

type BatchDictionaryItem struct {


Operation BatchOperation `json:"op"`
ItemKey string `json:"item_key"`
ItemValue string `json:"item_value"`
trentrosenbaum marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *Client) BatchModifyDictionaryItems(i *BatchModifyDictionaryItemsInput) error {

if i.Service == "" {
return ErrMissingService
}

if i.Dictionary == "" {
return ErrMissingDictionary
}

if len(i.Items) > BatchModifyMaximumItems {
return ErrBatchUpdateMaximumItemsExceeded
}

path := fmt.Sprintf("/service/%s/dictionary/%s/items", i.Service, i.Dictionary)
resp, err := c.PatchJSON(path, i, nil)
if err != nil {
return err
}

var batchModifyResult map[string]string
if err := decodeJSON(&batchModifyResult, resp.Body); err != nil {
return err
}

return nil
}

// DeleteDictionaryItemInput is the input parameter to DeleteDictionaryItem.
type DeleteDictionaryItemInput struct {
// Service is the ID of the service. Dictionary is the ID of the dictionary.
Expand Down
Loading