1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
2
3package personalizeevents
4
5import (
6	"fmt"
7	"time"
8
9	"github.com/aws/aws-sdk-go/aws"
10	"github.com/aws/aws-sdk-go/aws/awsutil"
11	"github.com/aws/aws-sdk-go/aws/request"
12	"github.com/aws/aws-sdk-go/private/protocol"
13	"github.com/aws/aws-sdk-go/private/protocol/restjson"
14)
15
16const opPutEvents = "PutEvents"
17
18// PutEventsRequest generates a "aws/request.Request" representing the
19// client's request for the PutEvents operation. The "output" return
20// value will be populated with the request's response once the request completes
21// successfully.
22//
23// Use "Send" method on the returned Request to send the API call to the service.
24// the "output" return value is not valid until after Send returns without error.
25//
26// See PutEvents for more information on using the PutEvents
27// API call, and error handling.
28//
29// This method is useful when you want to inject custom logic or configuration
30// into the SDK's request lifecycle. Such as custom headers, or retry logic.
31//
32//
33//    // Example sending a request using the PutEventsRequest method.
34//    req, resp := client.PutEventsRequest(params)
35//
36//    err := req.Send()
37//    if err == nil { // resp is now filled
38//        fmt.Println(resp)
39//    }
40//
41// See also, https://docs.aws.amazon.com/goto/WebAPI/personalize-events-2018-03-22/PutEvents
42func (c *PersonalizeEvents) PutEventsRequest(input *PutEventsInput) (req *request.Request, output *PutEventsOutput) {
43	op := &request.Operation{
44		Name:       opPutEvents,
45		HTTPMethod: "POST",
46		HTTPPath:   "/events",
47	}
48
49	if input == nil {
50		input = &PutEventsInput{}
51	}
52
53	output = &PutEventsOutput{}
54	req = c.newRequest(op, input, output)
55	req.Handlers.Unmarshal.Swap(restjson.UnmarshalHandler.Name, protocol.UnmarshalDiscardBodyHandler)
56	return
57}
58
59// PutEvents API operation for Amazon Personalize Events.
60//
61// Records user interaction event data.
62//
63// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
64// with awserr.Error's Code and Message methods to get detailed information about
65// the error.
66//
67// See the AWS API reference guide for Amazon Personalize Events's
68// API operation PutEvents for usage and error information.
69//
70// Returned Error Codes:
71//   * ErrCodeInvalidInputException "InvalidInputException"
72//   Provide a valid value for the field or parameter.
73//
74// See also, https://docs.aws.amazon.com/goto/WebAPI/personalize-events-2018-03-22/PutEvents
75func (c *PersonalizeEvents) PutEvents(input *PutEventsInput) (*PutEventsOutput, error) {
76	req, out := c.PutEventsRequest(input)
77	return out, req.Send()
78}
79
80// PutEventsWithContext is the same as PutEvents with the addition of
81// the ability to pass a context and additional request options.
82//
83// See PutEvents for details on how to use this API operation.
84//
85// The context must be non-nil and will be used for request cancellation. If
86// the context is nil a panic will occur. In the future the SDK may create
87// sub-contexts for http.Requests. See https://golang.org/pkg/context/
88// for more information on using Contexts.
89func (c *PersonalizeEvents) PutEventsWithContext(ctx aws.Context, input *PutEventsInput, opts ...request.Option) (*PutEventsOutput, error) {
90	req, out := c.PutEventsRequest(input)
91	req.SetContext(ctx)
92	req.ApplyOptions(opts...)
93	return out, req.Send()
94}
95
96// Represents user interaction event information sent using the PutEvents API.
97type Event struct {
98	_ struct{} `type:"structure"`
99
100	// An ID associated with the event. If an event ID is not provided, Amazon Personalize
101	// generates a unique ID for the event. An event ID is not used as an input
102	// to the model. Amazon Personalize uses the event ID to distinquish unique
103	// events. Any subsequent events after the first with the same event ID are
104	// not used in model training.
105	EventId *string `locationName:"eventId" min:"1" type:"string"`
106
107	// The type of event. This property corresponds to the EVENT_TYPE field of the
108	// Interactions schema.
109	//
110	// EventType is a required field
111	EventType *string `locationName:"eventType" min:"1" type:"string" required:"true"`
112
113	// A string map of event-specific data that you might choose to record. For
114	// example, if a user rates a movie on your site, you might send the movie ID
115	// and rating, and the number of movie ratings made by the user.
116	//
117	// Each item in the map consists of a key-value pair. For example,
118	//
119	// {"itemId": "movie1"}
120	//
121	// {"itemId": "movie2", "eventValue": "4.5"}
122	//
123	// {"itemId": "movie3", "eventValue": "3", "numberOfRatings": "12"}
124	//
125	// The keys use camel case names that match the fields in the Interactions schema.
126	// The itemId and eventValue keys correspond to the ITEM_ID and EVENT_VALUE
127	// fields. In the above example, the eventType might be 'MovieRating' with eventValue
128	// being the rating. The numberOfRatings would match the 'NUMBER_OF_RATINGS'
129	// field defined in the Interactions schema.
130	//
131	// Properties is a required field
132	Properties aws.JSONValue `locationName:"properties" type:"jsonvalue" required:"true"`
133
134	// The timestamp on the client side when the event occurred.
135	//
136	// SentAt is a required field
137	SentAt *time.Time `locationName:"sentAt" type:"timestamp" required:"true"`
138}
139
140// String returns the string representation
141func (s Event) String() string {
142	return awsutil.Prettify(s)
143}
144
145// GoString returns the string representation
146func (s Event) GoString() string {
147	return s.String()
148}
149
150// Validate inspects the fields of the type to determine if they are valid.
151func (s *Event) Validate() error {
152	invalidParams := request.ErrInvalidParams{Context: "Event"}
153	if s.EventId != nil && len(*s.EventId) < 1 {
154		invalidParams.Add(request.NewErrParamMinLen("EventId", 1))
155	}
156	if s.EventType == nil {
157		invalidParams.Add(request.NewErrParamRequired("EventType"))
158	}
159	if s.EventType != nil && len(*s.EventType) < 1 {
160		invalidParams.Add(request.NewErrParamMinLen("EventType", 1))
161	}
162	if s.Properties == nil {
163		invalidParams.Add(request.NewErrParamRequired("Properties"))
164	}
165	if s.SentAt == nil {
166		invalidParams.Add(request.NewErrParamRequired("SentAt"))
167	}
168
169	if invalidParams.Len() > 0 {
170		return invalidParams
171	}
172	return nil
173}
174
175// SetEventId sets the EventId field's value.
176func (s *Event) SetEventId(v string) *Event {
177	s.EventId = &v
178	return s
179}
180
181// SetEventType sets the EventType field's value.
182func (s *Event) SetEventType(v string) *Event {
183	s.EventType = &v
184	return s
185}
186
187// SetProperties sets the Properties field's value.
188func (s *Event) SetProperties(v aws.JSONValue) *Event {
189	s.Properties = v
190	return s
191}
192
193// SetSentAt sets the SentAt field's value.
194func (s *Event) SetSentAt(v time.Time) *Event {
195	s.SentAt = &v
196	return s
197}
198
199type PutEventsInput struct {
200	_ struct{} `type:"structure"`
201
202	// A list of event data from the session.
203	//
204	// EventList is a required field
205	EventList []*Event `locationName:"eventList" min:"1" type:"list" required:"true"`
206
207	// The session ID associated with the user's visit.
208	//
209	// SessionId is a required field
210	SessionId *string `locationName:"sessionId" min:"1" type:"string" required:"true"`
211
212	// The tracking ID for the event. The ID is generated by a call to the CreateEventTracker
213	// (https://docs.aws.amazon.com/personalize/latest/dg/API_CreateEventTracker.html)
214	// API.
215	//
216	// TrackingId is a required field
217	TrackingId *string `locationName:"trackingId" min:"1" type:"string" required:"true"`
218
219	// The user associated with the event.
220	UserId *string `locationName:"userId" min:"1" type:"string"`
221}
222
223// String returns the string representation
224func (s PutEventsInput) String() string {
225	return awsutil.Prettify(s)
226}
227
228// GoString returns the string representation
229func (s PutEventsInput) GoString() string {
230	return s.String()
231}
232
233// Validate inspects the fields of the type to determine if they are valid.
234func (s *PutEventsInput) Validate() error {
235	invalidParams := request.ErrInvalidParams{Context: "PutEventsInput"}
236	if s.EventList == nil {
237		invalidParams.Add(request.NewErrParamRequired("EventList"))
238	}
239	if s.EventList != nil && len(s.EventList) < 1 {
240		invalidParams.Add(request.NewErrParamMinLen("EventList", 1))
241	}
242	if s.SessionId == nil {
243		invalidParams.Add(request.NewErrParamRequired("SessionId"))
244	}
245	if s.SessionId != nil && len(*s.SessionId) < 1 {
246		invalidParams.Add(request.NewErrParamMinLen("SessionId", 1))
247	}
248	if s.TrackingId == nil {
249		invalidParams.Add(request.NewErrParamRequired("TrackingId"))
250	}
251	if s.TrackingId != nil && len(*s.TrackingId) < 1 {
252		invalidParams.Add(request.NewErrParamMinLen("TrackingId", 1))
253	}
254	if s.UserId != nil && len(*s.UserId) < 1 {
255		invalidParams.Add(request.NewErrParamMinLen("UserId", 1))
256	}
257	if s.EventList != nil {
258		for i, v := range s.EventList {
259			if v == nil {
260				continue
261			}
262			if err := v.Validate(); err != nil {
263				invalidParams.AddNested(fmt.Sprintf("%s[%v]", "EventList", i), err.(request.ErrInvalidParams))
264			}
265		}
266	}
267
268	if invalidParams.Len() > 0 {
269		return invalidParams
270	}
271	return nil
272}
273
274// SetEventList sets the EventList field's value.
275func (s *PutEventsInput) SetEventList(v []*Event) *PutEventsInput {
276	s.EventList = v
277	return s
278}
279
280// SetSessionId sets the SessionId field's value.
281func (s *PutEventsInput) SetSessionId(v string) *PutEventsInput {
282	s.SessionId = &v
283	return s
284}
285
286// SetTrackingId sets the TrackingId field's value.
287func (s *PutEventsInput) SetTrackingId(v string) *PutEventsInput {
288	s.TrackingId = &v
289	return s
290}
291
292// SetUserId sets the UserId field's value.
293func (s *PutEventsInput) SetUserId(v string) *PutEventsInput {
294	s.UserId = &v
295	return s
296}
297
298type PutEventsOutput struct {
299	_ struct{} `type:"structure"`
300}
301
302// String returns the string representation
303func (s PutEventsOutput) String() string {
304	return awsutil.Prettify(s)
305}
306
307// GoString returns the string representation
308func (s PutEventsOutput) GoString() string {
309	return s.String()
310}
311