Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func Float64(v float64) *float64
- func Int32(v int32) *int32
- func String(v string) *string
- type AggregatedPayload
- type CalculatedForecast
- type CalculatedPayload
- type Client
- type Coordinate
- type CustomField
- type DataProvider
- type DataProviderInput
- type DataProviderInputList
- type DynamicRule
- type EditCalculatedRequest
- type Error
- type ErrorResponse
- type ForecastPrediction
- type ForecastService
- func (s *ForecastService) CreateDynamicRule(ctx context.Context, rule *DynamicRule, RequestOptions *RequestOptions) (*DynamicRule, *Response, error)
- func (s *ForecastService) CreateStaticRule(ctx context.Context, rule *StaticRule, RequestOptions *RequestOptions) (*StaticRule, *Response, error)
- func (s *ForecastService) DeleteDynamicRule(ctx context.Context, dynamicRuleID string, RequestOptions *RequestOptions) (*Response, error)
- func (s *ForecastService) DeleteForecastData(ctx context.Context, externalForecastVariableID string, ...) (*Response, error)
- func (s *ForecastService) DeleteStaticRule(ctx context.Context, staticRuleID string, RequestOptions *RequestOptions) (*Response, error)
- func (s *ForecastService) EditCalculatedForecast(ctx context.Context, externalForecastVariableID string, ...) (*Response, error)
- func (s *ForecastService) GetActualDataStream(ctx context.Context, externalForecastVariableID string, ...) ([]*DataProvider, *Response, error)
- func (s *ForecastService) GetAggregatedData(ctx context.Context, externalForecastVariableID string, ...) ([]*AggregatedPayload, *Response, error)
- func (s *ForecastService) GetCalculatedForecast(ctx context.Context, externalForecastVariableID string, ...) ([]*CalculatedForecast, *Response, error)
- func (s *ForecastService) GetDynamicRules(ctx context.Context, RequestOptions *RequestOptions) ([]*DynamicRule, *Response, error)
- func (s *ForecastService) GetForecastData(ctx context.Context, externalForecastVariableID string, ...) ([]*DataProvider, *Response, error)
- func (s *ForecastService) GetStaticRules(ctx context.Context, RequestOptions *RequestOptions) ([]*StaticRule, *Response, error)
- func (s *ForecastService) UpdateDynamicRule(ctx context.Context, rule *DynamicRule, RequestOptions *RequestOptions) (*Response, error)
- func (s *ForecastService) UpdateStaticRule(ctx context.Context, rule *StaticRule, RequestOptions *RequestOptions) (*Response, error)
- func (s *ForecastService) UploadBudgetData(ctx context.Context, appendData bool, dil *DataProviderInputList) (*Response, error)
- func (s *ForecastService) UploadPredictedData(ctx context.Context, inlist *PredictedDataInputList) (*Response, error)
- type LocalTime
- type Payload
- type Period
- type PeriodType
- type PredictedDataInputList
- type RequestOptions
- type RequestRangeOptions
- type Response
- type ShiftType
- type StaticRule
- type Tag
- type TagCategory
- type TagType
- type TagsService
- func (s *TagsService) CreateTag(ctx context.Context, categoryExternalID string, tag *Tag) (*Tag, *Response, error)
- func (s *TagsService) DeleteTag(ctx context.Context, categoryExternalID string, tagExternalID string) (*Response, error)
- func (s *TagsService) GetAllCategories(ctx context.Context) ([]*TagCategory, *Response, error)
- func (s *TagsService) GetAllTags(ctx context.Context, categoryExternalID string) (*Tag, *Response, error)
- func (s *TagsService) GetCategory(ctx context.Context, categoryExternalID string) (*TagCategory, *Response, error)
- func (s *TagsService) GetTag(ctx context.Context, categoryExternalID string, tagExternalID string) (*Tag, *Response, error)
- func (s *TagsService) UpdateTag(ctx context.Context, categoryExternalID string, tagExternalID string, tag *Tag) (*Tag, *Response, error)
- type Timestamp
- type Weekday
Examples ¶
Constants ¶
const ( Monday Weekday = "0" Tuesday = "1" Wednesday = "2" Thursday = "3" Friday = "4" Saturday = "5" Sunday = "6" )
TagTypes
const ( CostCenter TagType = "COST_CENTER" Project = "PROJECT" Account = "ACCOUNT" Extended = "EXTENDED" )
TagTypes
const ( PeriodTypePeriod PeriodType = "PERIOD" PeriodTypeDays = "DAYS" PeriodTypeWeeks = "WEEKS" )
PeriodType
Variables ¶
var ( // ErrorReqfieldsMissing is the error returned when the request Options does not have all required fields defined ErrorReqfieldsMissing = fmt.Errorf("Required fields in the Options not provided, see docs") // ErrorDaterangeTooWide is the error returned when the requested daterange in days is to wide ErrorDaterangeTooWide = fmt.Errorf("The amount of days between StartTime and EndTime is above the limit, see docs") )
Functions ¶
func CheckResponse ¶
CheckResponse checks the API response for errors, and returns them if present.
Types ¶
type AggregatedPayload ¶
type AggregatedPayload struct { Data *float64 `json:"data,omitempty"` EndTime *Timestamp `json:"endTime,omitempty"` StartTime *Timestamp `json:"startTime,omitempty"` }
AggregatedPayload is the aggregated data object
type CalculatedForecast ¶
type CalculatedForecast struct { DataPayload []*CalculatedPayload `json:"dataPayload,omitempty"` ExternalForecastConfigurationID *string `json:"externalForecastConfigurationId,omitempty"` ExternalSectionID *string `json:"externalSectionId,omitempty"` ExternalUnitID *string `json:"externalUnitId,omitempty"` }
CalculatedForecast is the calculated forecast generated in Quinyx Forecast
type CalculatedPayload ¶
type CalculatedPayload struct { Data *float64 `json:"data,omitempty"` EditedData *float64 `json:"editedData,omitempty"` StartTime *Timestamp `json:"startTime,omitempty"` EndTime *Timestamp `json:"endTime,omitempty"` }
CalculatedPayload is the payload data object for calculated data
type Client ¶
type Client struct { // Base URL for API requests. Defaults to the public Quinyx API, but can be // set to a domain endpoint to use with other Quinyx Environments. BaseURL should // always be specified with a trailing slash. BaseURL *url.URL // User agent used when communicating with the Quinyx API. UserAgent string // Services used for talking to different parts of the Quinyx API. Tags *TagsService Forecast *ForecastService // contains filtered or unexported fields }
A Client manages communication with the Quinyx API.
Example ¶
package main import ( "context" "fmt" "log" "net/url" "os" "github.com/mollerdaniel/go-quinyx/quinyx" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" ) func main() { ctx := context.Background() // Oauth2 Config conf := clientcredentials.Config{ ClientID: os.Getenv("CLIENTID"), ClientSecret: os.Getenv("CLIENTSECRET"), // Quinyx API does not accept URLEncoded secrets https://tools.ietf.org/html/rfc6749#section-2.3.1 TokenURL: "https://api.quinyx.com/v2/oauth/token", AuthStyle: oauth2.AuthStyleInHeader, EndpointParams: url.Values{ "grant_type": {"client_credentials"}, }, } // HTTP Client client := conf.Client(ctx) // Quinyx API Client q, err := quinyx.NewClient(client, nil) if err != nil { log.Fatalf("Error: %v", err) } // Call Tags Service to get all categories categories, res, err := q.Tags.GetAllCategories(ctx) if err != nil { log.Fatalf("Error: %v RequestUID: %s", err, res.GetQuinyxUID()) } // Dump each category to console for _, tagCategory := range categories { fmt.Println(tagCategory) } }
Output:
func NewClient ¶
NewClient returns a new Quinyx API client. If a nil httpClient is provided, a new http.Client will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
func (*Client) GetTokenURL ¶
GetTokenURL returns the Quinyx Token URL
func (*Client) NewRequest ¶
NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.
type Coordinate ¶
type Coordinate struct { Latitude *float64 `json:"latitude,omitempty"` Longitude *float64 `json:"longitude,omitempty"` Radius *int32 `json:"radius,omitempty"` }
Coordinate defines a Geofence using Long Lat and a Radius
type CustomField ¶
type CustomField struct { Label *string `json:"label,omitempty"` Value *string `json:"value,omitempty"` }
CustomField is a Tag custom field
type DataProvider ¶
type DataProvider struct { ExternalForecastVariableID *string `json:"externalForecastVariableId,omitempty"` ExternalUnitID *string `json:"externalUnitId,omitempty"` ExternalSectionID *string `json:"externalSectionId,omitempty"` DataPayload []*Payload `json:"dataPayload,omitempty"` }
DataProvider is the output object from Quinyx forecast
type DataProviderInput ¶
type DataProviderInput struct { ExternalForecastVariableID *string `json:"externalForecastVariableId,omitempty"` ExternalUnitID *string `json:"externalUnitId,omitempty"` ExternalSectionID *string `json:"externalSectionId,omitempty"` DataPayload []*Payload `json:"forecastDataPayload,omitempty"` }
DataProviderInput is the input object to feed Quinyx forecast
type DataProviderInputList ¶
type DataProviderInputList struct {
DataProviderInputs []DataProviderInput `json:"requests"`
}
DataProviderInputList is the object used to update actual-data in Quinyx Forecast
type DynamicRule ¶
type DynamicRule struct { Amount int64 `json:"amount"` EndTime LocalTime `json:"endTime"` StartTime LocalTime `json:"startTime"` ExternalID string `json:"externalId"` ExternalForecastVariableID string `json:"forecastExternalVariableId"` ShiftTypes []ShiftType `json:"shiftTypes"` Weekdays []Weekday `json:"weekdays"` }
DynamicRule defines a dynamic rule
type EditCalculatedRequest ¶
type EditCalculatedRequest struct { RepetitionSetup bool `json:"repetitionSetup"` StartTime Timestamp `json:"startTime"` EndTime Timestamp `json:"endTime"` PercentageModification float64 `json:"percentageModification"` NewValueForPeriod float64 `json:"newValueForPeriod"` WeekDays []Weekday `json:"weekdays"` RepetitionEndDate Timestamp `json:"repetitionEndDate"` WeekPattern int32 `json:"weekPattern"` }
EditCalculatedRequest is the object used to edit calculated forecast
type Error ¶
type Error struct { Resource string `json:"resource"` // resource on which the error occurred Field string `json:"field"` // field on which the error occurred Code string `json:"code"` // validation error code Message string `json:"message"` // Message describing the error. Errors with Code == "custom" will always have this set. }
Error Error
func (*Error) UnmarshalJSON ¶
UnmarshalJSON from bytes into the Error
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response // HTTP response that caused this error Message string `json:"message"` // error message Errors []Error `json:"errors"` // more detail on individual errors }
ErrorResponse ErrorResponse
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type ForecastPrediction ¶
type ForecastPrediction struct { ExternalForecastVariableID *string `json:"externalForecastVariableId,omitempty"` ExternalForecastConfigurationID *string `json:"externalForecastConfigurationId,omitempty"` ExternalUnitID *string `json:"externalUnitId,omitempty"` ExternalSectionID *string `json:"externalSectionId,omitempty"` RunIdentifier *string `json:"runIdentifier,omitempty"` RunTimestamp *Timestamp `json:"runTimestamp,omitempty"` Payloads []*Payload `json:"forecastDataPayload"` }
ForecastPrediction defines the prediction object
type ForecastService ¶
type ForecastService service
ForecastService handles Quinyx Forecast data
Quinyx API docs: https://api.quinyx.com/v2/docs/swagger-ui.html?urls.primaryName=forecast#/
func (*ForecastService) CreateDynamicRule ¶
func (s *ForecastService) CreateDynamicRule(ctx context.Context, rule *DynamicRule, RequestOptions *RequestOptions) (*DynamicRule, *Response, error)
CreateDynamicRule creates a dynamic rule
func (*ForecastService) CreateStaticRule ¶
func (s *ForecastService) CreateStaticRule(ctx context.Context, rule *StaticRule, RequestOptions *RequestOptions) (*StaticRule, *Response, error)
CreateStaticRule creates a static rule
func (*ForecastService) DeleteDynamicRule ¶
func (s *ForecastService) DeleteDynamicRule(ctx context.Context, dynamicRuleID string, RequestOptions *RequestOptions) (*Response, error)
DeleteDynamicRule deletes a dynamic rule
func (*ForecastService) DeleteForecastData ¶
func (s *ForecastService) DeleteForecastData(ctx context.Context, externalForecastVariableID string, RequestRangeOptions *RequestRangeOptions) (*Response, error)
DeleteForecastData deletes the previously uploaded forecast data for the the given forecast variable. The startTime and endTime must be at the start of hour and the range between these two dates can not exceed 120 days.
func (*ForecastService) DeleteStaticRule ¶
func (s *ForecastService) DeleteStaticRule(ctx context.Context, staticRuleID string, RequestOptions *RequestOptions) (*Response, error)
DeleteStaticRule deletes a static rule
func (*ForecastService) EditCalculatedForecast ¶
func (s *ForecastService) EditCalculatedForecast(ctx context.Context, externalForecastVariableID string, externalForecastConfigurationID string, RequestRangeOptions *RequestOptions, modrequest *EditCalculatedRequest) (*Response, error)
EditCalculatedForecast changes the calculated forecast.
func (*ForecastService) GetActualDataStream ¶
func (s *ForecastService) GetActualDataStream(ctx context.Context, externalForecastVariableID string, RequestRangeOptions *RequestRangeOptions) ([]*DataProvider, *Response, error)
GetActualDataStream gets the actual data previously uploaded for the given forecast variable. The range between these two dates can not exceed 120 days.
func (*ForecastService) GetAggregatedData ¶
func (s *ForecastService) GetAggregatedData(ctx context.Context, externalForecastVariableID string, RequestRangeOptions *RequestRangeOptions) ([]*AggregatedPayload, *Response, error)
GetAggregatedData gets the aggregated data for the given forecast variable. The range between these two dates can not exceed 120 days.
func (*ForecastService) GetCalculatedForecast ¶
func (s *ForecastService) GetCalculatedForecast(ctx context.Context, externalForecastVariableID string, RequestRangeOptions *RequestRangeOptions) ([]*CalculatedForecast, *Response, error)
GetCalculatedForecast gets the calculated forecast for the given forecast variable. The range between these two dates can not exceed 120 days.
func (*ForecastService) GetDynamicRules ¶
func (s *ForecastService) GetDynamicRules(ctx context.Context, RequestOptions *RequestOptions) ([]*DynamicRule, *Response, error)
GetDynamicRules lists dynamic rules
func (*ForecastService) GetForecastData ¶
func (s *ForecastService) GetForecastData(ctx context.Context, externalForecastVariableID string, RequestRangeOptions *RequestRangeOptions) ([]*DataProvider, *Response, error)
GetForecastData gets the uploaded forecast data for the given forecast variable. The range between these two dates can not exceed 120 days.
func (*ForecastService) GetStaticRules ¶
func (s *ForecastService) GetStaticRules(ctx context.Context, RequestOptions *RequestOptions) ([]*StaticRule, *Response, error)
GetStaticRules lists static rules
func (*ForecastService) UpdateDynamicRule ¶
func (s *ForecastService) UpdateDynamicRule(ctx context.Context, rule *DynamicRule, RequestOptions *RequestOptions) (*Response, error)
UpdateDynamicRule updates the existing dynamic rule
func (*ForecastService) UpdateStaticRule ¶
func (s *ForecastService) UpdateStaticRule(ctx context.Context, rule *StaticRule, RequestOptions *RequestOptions) (*Response, error)
UpdateStaticRule updates the existing static rule
func (*ForecastService) UploadBudgetData ¶
func (s *ForecastService) UploadBudgetData(ctx context.Context, appendData bool, dil *DataProviderInputList) (*Response, error)
UploadBudgetData sends budget datapoints to Quinyx Forecast API
func (*ForecastService) UploadPredictedData ¶
func (s *ForecastService) UploadPredictedData(ctx context.Context, inlist *PredictedDataInputList) (*Response, error)
UploadPredictedData is the Operation used to upload generated prediction data. Resolution of datapoints must match expected resolution of variable. The total amount of data rows must not exceed 366
type LocalTime ¶
type LocalTime struct { Hour int `json:"hour"` Minute int `json:"minute"` Nano int `json:"nano"` Second int `json:"second"` }
LocalTime is a specific time on a day
type Payload ¶
type Payload struct { Data *float64 `json:"data,omitempty"` Timestamp *Timestamp `json:"timestamp,omitempty"` }
Payload is the raw data object
type Period ¶
type Period struct { From *Timestamp `json:"from,omitempty"` To *Timestamp `json:"to,omitempty"` Hours *float64 `json:"hours,omitempty"` Type PeriodType `json:"type,omitempty"` Count *float64 `json:"count,omitempty"` }
Period defines a point in time for the tag
type PredictedDataInputList ¶
type PredictedDataInputList struct {
ForecastPredictions []ForecastPrediction `json:"requests"`
}
PredictedDataInputList provides a list of ForecastPredictions
type RequestOptions ¶
type RequestOptions struct { // ExternalSectionID is optional ExternalSectionID *string `url:"externalSectionId,omitempty"` // ExternalUnitID is required ExternalUnitID *string `url:"externalUnitId"` }
RequestOptions is the options object for editing calculated forecast
type RequestRangeOptions ¶
type RequestRangeOptions struct { // StartTime is required StartTime time.Time `url:"startTime"` // EndTime is required EndTime time.Time `url:"endTime"` // ExternalSectionID is optional ExternalSectionID *string `url:"externalSectionId,omitempty"` // ExternalUnitID is required ExternalUnitID *string `url:"externalUnitId"` }
RequestRangeOptions is the options object for querying forecast
type Response ¶
Response is a Quinyx API response. This wraps the standard http.Response returned from Quinyx and provides convenient access to things like pagination links.
func (*Response) GetQuinyxUID ¶
GetQuinyxUID extracts the X-Quinyx-Uid header used for request tracing as a string.
type ShiftType ¶
type ShiftType struct { Amount int `json:"amount"` ShiftTypeID string `json:"externalShiftTypeId"` }
ShiftType ShiftType
type StaticRule ¶
type StaticRule struct { Comment string `json:"comment"` StartDate time.Time `json:"startDate"` EndDate time.Time `json:"endDate"` StartTime LocalTime `json:"startTime"` EndTime LocalTime `json:"endTime"` ExternalID string `json:"externalId"` RepeatPeriod int `json:"repeatPeriod"` ShiftType ShiftType `json:"shiftType"` Weekdays []Weekday `json:"weekdays"` }
StaticRule defines a static rule
type Tag ¶
type Tag struct { CategoryExternalID *string `json:"categoryExternalId,omitempty"` Code *string `json:"code,omitempty"` Coordinates []*Coordinate `json:"coordinates,omitempty"` CustomFields []*CustomField `json:"customFields,omitempty"` EndDate *Timestamp `json:"endDate,omitempty"` ExternalID *string `json:"externalId,omitempty"` Information *string `json:"information,omitempty"` Name *string `json:"name,omitempty"` Periods []*Period `json:"periods,omitempty"` StartDate *Timestamp `json:"startDate,omitempty"` UniqueScheduling *bool `json:"uniqueScheduling,omitempty"` UnitExternalID *string `json:"unitExternalId,omitempty"` }
Tag defines a Quinyx TagIntegration object
type TagCategory ¶
type TagCategory struct { Color *string `json:"color,omitempty"` ExternalID *string `json:"externalId,omitempty"` TagID *int32 `json:"id,omitempty"` Name *string `json:"name,omitempty"` TagType TagType `json:"tagType,omitempty"` }
TagCategory is a Category of tags
type TagType ¶
type TagType string
TagType defines a type of Tag
func (*TagType) UnmarshalJSON ¶
UnmarshalJSON TagType enum
type TagsService ¶
type TagsService service
TagsService handles Quinyx Tags
Quinyx API docs: https://api.quinyx.com/v2/docs/swagger-ui.html?urls.primaryName=tags#/
func (*TagsService) CreateTag ¶
func (s *TagsService) CreateTag(ctx context.Context, categoryExternalID string, tag *Tag) (*Tag, *Response, error)
CreateTag creates and then returns the tag
func (*TagsService) DeleteTag ¶
func (s *TagsService) DeleteTag(ctx context.Context, categoryExternalID string, tagExternalID string) (*Response, error)
DeleteTag removes the tag
func (*TagsService) GetAllCategories ¶
func (s *TagsService) GetAllCategories(ctx context.Context) ([]*TagCategory, *Response, error)
GetAllCategories gets all categories
func (*TagsService) GetAllTags ¶
func (s *TagsService) GetAllTags(ctx context.Context, categoryExternalID string) (*Tag, *Response, error)
GetAllTags based on categoryExternalID While the documentation says it should return all, it actually only returns one tag.
func (*TagsService) GetCategory ¶
func (s *TagsService) GetCategory(ctx context.Context, categoryExternalID string) (*TagCategory, *Response, error)
GetCategory from a categoryExternalID