Skip to content

Commit

Permalink
use new RELEASE statusChangeCommand type instead of hardcoded FREE st…
Browse files Browse the repository at this point in the history
…atus, when releasing objects (#63)

* instead of passing in FREE as a status, we now use RELEASE as statusChangeCommand type.

* refactoring - rename
  • Loading branch information
bverbeken committed Oct 4, 2024
1 parent a0e25f6 commit 8447494
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const (
)

type StatusChanges struct {
Status ObjectStatus `json:"status"`
Type string `json:"type,omitempty"`
Status ObjectStatus `json:"status,omitempty"`
Objects []ObjectProperties `json:"objects"`
HoldToken string `json:"holdToken,omitempty"`
OrderId string `json:"orderId,omitempty"`
Expand Down Expand Up @@ -382,18 +383,32 @@ func (events *Events) PutUpForResale(eventKey string, objectIds ...string) (*Cha
}

func (events *Events) Release(eventKey string, objectIds ...string) (*ChangeObjectStatusResult, error) {
return events.changeStatus(FREE, eventKey, events.toObjectProperties(objectIds), nil)
return events.releaseObjects(eventKey, events.toObjectProperties(objectIds), nil)
}

func (events *Events) ReleaseWithHoldToken(eventKey string, objectIds []string, holdToken *string) (*ChangeObjectStatusResult, error) {
return events.changeStatus(FREE, eventKey, events.toObjectProperties(objectIds), holdToken)
return events.releaseObjects(eventKey, events.toObjectProperties(objectIds), holdToken)
}

func (events *Events) ReleaseWithOptions(statusChangeParams *StatusChangeParams) (*ChangeObjectStatusResult, error) {
statusChangeParams.Status = FREE
statusChangeParams.Type = "RELEASE"
return events.ChangeObjectStatusWithOptions(statusChangeParams)
}

func (events *Events) releaseObjects(eventKey string, objectProperties []ObjectProperties, holdToken *string) (*ChangeObjectStatusResult, error) {
params := StatusChangeParams{
Events: []string{eventKey},
StatusChanges: StatusChanges{
Type: "RELEASE",
Objects: objectProperties,
},
}
if holdToken != nil {
params.HoldToken = *holdToken
}
return events.ChangeObjectStatusWithOptions(&params)
}

func (events *Events) changeStatus(status ObjectStatus, eventKey string, objectProperties []ObjectProperties, holdToken *string) (*ChangeObjectStatusResult, error) {
params := StatusChangeParams{
Events: []string{eventKey},
Expand Down

0 comments on commit 8447494

Please sign in to comment.