mcnijman/go-exactonline

Missing $expand in api.ListOptions

Opened this issue · 1 comments

api.ListOptions is missing the $expand system query.

Added exand type and methods.

// Expand causes related entities to be included inline in the response.
type Expand struct {
	v []string
}

// Set sets the expand query options
func (e *Expand) Set(fields []string) {
	e.v = fields
}

// Add a field to the Expand query
func (e *Expand) Add(field string) {
	for _, key := range e.v {
		if key == field {
			return
		}
	}
	e.v = append(e.v, field)
}

// Remove a field from the Expand query
func (e *Expand) Remove(field string) {
	for i, v := range e.v {
		if v == field {
			e.v = append(e.v[:i], e.v[i+1:]...)
			break
		}
	}
}

// MarshalSchema marshals the options in a query string
func (e *Expand) MarshalSchema() string {
	if len(e.v) == 0 {
		return ""
	}
	return strings.Join(e.v, ",")
}