-
Notifications
You must be signed in to change notification settings - Fork 39
/
resources.go
463 lines (442 loc) · 12 KB
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
package design
import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)
// set of constants reused within multiple actions
const (
SegmentPattern = `^[a-zA-Z0-9_\-@.]+$`
UserPattern = `^[a-zA-Z0-9_\-@.]+$`
CacheParamDescription = `JSON-encoded object of internal cache with count of events provided by third party (mostly Beam's remplib.js), e.g.:
{
10: { // segment rule ID
"d": "2017-11-07T08:06:26.612Z" // RFC3339 date
"c": 11 // number of occurrences
}
}`
FieldsParamDescription = `JSON-encoded object of overriden pairs, e.g.:
{
"utm_campaign": "custom-campaign-id",
// ...
}`
)
var _ = Resource("swagger", func() {
Origin("*", func() {
Methods("GET", "OPTIONS")
Headers("*")
})
NoSecurity()
Files("/swagger.json", "swagger/swagger.json")
})
var _ = Resource("segments", func() {
Description("Segment operations")
BasePath("/segments")
NoSecurity()
Action("get", func() {
Description("Get segment")
Routing(GET("/show"))
Params(func() {
Param("id", Integer, "Segment ID")
Required("id")
})
Response(NotFound)
Response(BadRequest)
Response(OK, SegmentersSegment)
})
Action("list", func() {
Description("List all segments.")
Routing(GET("/"))
Response(NotFound)
Response(BadRequest)
Response(OK, func() {
Media(CollectionOf(Segment, func() {
View("default")
View("tiny")
View("extended")
View("segmenter")
}))
})
})
Action("groups", func() {
Description("List all segment groups.")
Routing(GET("/groups"))
Response(OK, func() {
Media(SegmentGroupsFallback)
})
})
Action("check_user", func() {
Description("Check whether given user ID belongs to segment.")
Routing(GET("/:segment_code/users/check/:user_id"))
Params(func() {
Param("segment_code", String, "Segment code", func() {
Pattern(SegmentPattern)
})
Param("user_id", String, "User ID", func() {
Pattern(UserPattern)
})
Param("fields", String, FieldsParamDescription)
Param("cache", String, CacheParamDescription)
})
Response(NotFound)
Response(BadRequest)
Response(OK, func() {
Media(SegmentCheck)
})
})
Action("check_browser", func() {
Description("Check whether given browser ID belongs to segment.")
Routing(GET("/:segment_code/browsers/check/:browser_id"))
Params(func() {
Param("segment_code", String, "Segment code", func() {
Pattern(SegmentPattern)
})
Param("browser_id", String, "Browser ID", func() {
Pattern(UserPattern)
})
Param("fields", String, FieldsParamDescription)
Param("cache", String, CacheParamDescription)
})
Response(NotFound)
Response(BadRequest)
Response(OK, func() {
Media(SegmentCheck)
})
})
Action("users", func() {
Description("List users of segment.")
Routing(
GET("/:segment_code/users"),
)
Params(func() {
Param("segment_code", String, "Segment code", func() {
Pattern(SegmentPattern)
})
Param("fields", String, FieldsParamDescription)
})
Response(NotFound)
Response(BadRequest)
Response(OK, ArrayOf(String))
})
Action("criteria", func() {
Description("Provide segment blueprint with criteria for individual tables and fields")
Routing(
GET("/criteria"),
)
Response(OK, SegmentBlueprint)
})
// TODO: divide to two separate endpoints after CRM API refactoring
Action("create_or_update", func() {
Description("Create or update segment (for fupdate, use GET parameter ?id={segment_id})")
Payload(SegmentPayload)
Routing(POST("/detail"))
Params(func() {
Param("id", Integer, "Segment ID")
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(NotFound, func() {
Description("Returned when segment with provided ID doesn't exist")
})
Response(OK, Segment)
})
Action("count", func() {
Description("Returns number of users in segment based on provided criteria")
Payload(SegmentTinyPayload)
Routing(POST("/count"))
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, SegmentCount)
})
Action("related", func() {
Description("Returns segments with same or similar criteria")
Payload(SegmentTinyPayload)
Routing(POST("/related"))
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, RelatedSegments)
})
})
var _ = Resource("journal", func() {
Description("Common journal calls")
BasePath("/journal")
NoSecurity()
Action("flags", func() {
Description("List of all available flags")
Routing(GET("/flags"))
Response(OK, Flags)
})
})
var _ = Resource("events", func() {
Description("Events journal")
BasePath("/journal/events")
NoSecurity()
Action("count_action", func() {
Description("Returns counts of events for given action and category")
Routing(POST("/categories/:category/actions/:action/count"))
Payload(EventOptionsPayload)
Params(func() {
Param("action", String, "Event action")
Param("category", String, "Event category")
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("count", func() {
Description("Returns counts of events")
Routing(POST("/count"))
Payload(EventOptionsPayload)
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("list", func() {
Description("Returns full list of events")
Routing(POST("/list"))
Payload(ListEventOptionsPayload)
Response(OK, func() {
Media(CollectionOf(Events, func() {
View("default")
}))
})
})
Action("categories", func() {
Description("List of all tracked categories")
Routing(GET("/categories"))
Response(OK, ArrayOf(String))
})
Action("actions", func() {
Description("List of all tracked actions for given category")
Routing(GET("/categories/:category/actions"))
Params(func() {
Param("category", String, "Category under which the actions were tracked")
})
Response(OK, ArrayOf(String))
})
Action("users", func() {
Description("List of all tracked users")
Routing(GET("/users"))
Response(OK, ArrayOf(String))
})
})
var _ = Resource("commerce", func() {
Description("Commerce journal")
BasePath("/journal/commerce")
NoSecurity()
Action("count_step", func() {
Description("Returns counts of commerce events")
Payload(CommerceOptionsPayload)
Routing(POST("/steps/:step/count"))
Params(func() {
Param("step", String, "Identification of commerce step", func() {
Enum("checkout", "payment", "purchase", "refund")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("count", func() {
Description("Returns counts of commerce events")
Payload(CommerceOptionsPayload)
Routing(POST("/count"))
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("sum_step", func() {
Description("Returns sum of amounts within events")
Payload(CommerceOptionsPayload)
Routing(POST("/steps/:step/sum"))
Params(func() {
Param("step", String, "Identification of commerce step", func() {
Enum("checkout", "payment", "purchase", "refund")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Sum, func() {
View("default")
}))
})
})
Action("sum", func() {
Description("Returns sum of amounts within events")
Payload(CommerceOptionsPayload)
Routing(POST("/sum"))
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Sum, func() {
View("default")
}))
})
})
Action("list", func() {
Description("Returns full list of events")
Routing(POST("/list"))
Payload(ListCommerceOptionsPayload)
Response(OK, func() {
Media(CollectionOf(Commerces, func() {
View("default")
}))
})
})
Action("categories", func() {
Description("List of all available categories")
Routing(GET("/categories"))
Response(OK, ArrayOf(String))
})
Action("actions", func() {
Description("List of all available actions for given category")
Routing(GET("/categories/:category/actions"))
Params(func() {
Param("category", String, "Category (step) under which the actions were tracked")
})
Response(OK, ArrayOf(String))
})
})
var _ = Resource("pageviews", func() {
Description("Pageviews journal")
BasePath("/journal/pageviews")
NoSecurity()
Action("count", func() {
Description("Returns counts of pageviews")
Payload(PageviewOptionsPayload)
Routing(POST("/actions/:action/count"))
Params(func() {
Param("action", String, "Identification of pageview action", func() {
Enum("load", "progress")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("sum", func() {
Description("Returns sum of amounts within events")
Payload(PageviewOptionsPayload)
Routing(POST("/actions/:action/sum"))
Params(func() {
Param("action", String, "Identification of pageview action", func() {
Enum("timespent")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Sum, func() {
View("default")
}))
})
})
Action("avg", func() {
Description("Returns avg of amounts within events")
Payload(PageviewOptionsPayload)
Routing(POST("/actions/:action/avg"))
Params(func() {
Param("action", String, "Identification of pageview action", func() {
Enum("timespent")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Avg, func() {
View("default")
}))
})
})
Action("unique", func() {
Description("Returns unique count of amounts within events")
Payload(PageviewOptionsPayload)
Routing(POST("/actions/:action/unique/:item"))
Params(func() {
Param("action", String, "Identification of pageview action", func() {
Enum("load")
})
Param("item", String, "Identification of queried unique items", func() {
Enum("browsers")
})
})
Response(BadRequest, func() {
Description("Returned when request does not comply with Swagger specification")
})
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
Action("list", func() {
Description("Returns full list of pageviews")
Routing(POST("/list"))
Payload(ListPageviewOptionsPayload)
Response(OK, func() {
Media(CollectionOf(Pageviews, func() {
View("default")
}))
})
})
Action("categories", func() {
Description("List of all available categories")
Routing(GET("/categories"))
Response(OK, ArrayOf(String))
})
Action("actions", func() {
Description("List of all available actions for given category")
Routing(GET("/categories/:category/actions"))
Params(func() {
Param("category", String, "Category under which the actions were tracked")
})
Response(OK, ArrayOf(String))
})
})
var _ = Resource("concurrents", func() {
Description("Show recent concurrent connections")
BasePath("/journal/concurrents")
NoSecurity()
Action("count", func() {
Description("Returns recent concurrent connections identified by browser id")
Payload(ConcurrentsOptionsPayload)
Routing(POST("/count"))
Response(OK, func() {
Media(CollectionOf(Count, func() {
View("default")
}))
})
})
})