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

Modify ListOverrides and add ListOverridesResponse #185

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ type ListOverridesOptions struct {
Overflow bool `url:"overflow,omitempty"`
}

// ListOverridesResponse is the data structure returned from calling the ListOverrides API endpoint.
type ListOverridesResponse struct {
APIListObject
Overrides []Override `json:"overrides,omitempty"`
}

// Overrides are any schedule layers from the override layer.
type Override struct {
ID string `json:"id,omitempty"`
Expand All @@ -172,7 +178,7 @@ type Override struct {
}

// ListOverrides lists overrides for a given time range.
func (c *Client) ListOverrides(id string, o ListOverridesOptions) ([]Override, error) {
func (c *Client) ListOverrides(id string, o ListOverridesOptions) (*ListOverridesResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
Expand All @@ -181,15 +187,8 @@ func (c *Client) ListOverrides(id string, o ListOverridesOptions) ([]Override, e
if err != nil {
return nil, err
}
var result map[string][]Override
if err := c.decodeJSON(resp, &result); err != nil {
return nil, err
}
overrides, ok := result["overrides"]
if !ok {
return nil, fmt.Errorf("JSON response does not have overrides field")
}
return overrides, nil
var result ListOverridesResponse
return &result, c.decodeJSON(resp, &result)
}

// CreateOverride creates an override for a specific user covering the specified time range.
Expand Down