forked from vickxxx/appstore
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sales_filters.go
435 lines (379 loc) · 14.9 KB
/
sales_filters.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
package appstore
import (
"fmt"
"time"
)
// SalesReportType type
type SalesReportType string
// SalesReportSubType type
type SalesReportSubType string
// SalesReportFrequency type
type SalesReportFrequency string
// SalesReportVersion type
type SalesReportVersion string
const (
//SalesReportFrequencyDaily const
SalesReportFrequencyDaily SalesReportFrequency = "DAILY"
//SalesReportFrequencyWeekly const
SalesReportFrequencyWeekly SalesReportFrequency = "WEEKLY"
//SalesReportFrequencyMonthly const
SalesReportFrequencyMonthly SalesReportFrequency = "MONTHLY"
//SalesReportFrequencyYearly const
SalesReportFrequencyYearly SalesReportFrequency = "YEARLY"
)
const (
//SalesReportTypeSales const
SalesReportTypeSales SalesReportType = "SALES"
//SalesReportTypePreorder const
SalesReportTypePreorder SalesReportType = "PRE_ORDER"
//SalesReportTypeNewsStand const
SalesReportTypeNewsStand SalesReportType = "NEWSSTAND"
//SalesReportTypeSubscription const
SalesReportTypeSubscription SalesReportType = "SUBSCRIPTION"
//SalesReportTypeSubscriptionEvent const
SalesReportTypeSubscriptionEvent SalesReportType = "SUBSCRIPTION_EVENT"
//SalesReportTypeSubscriptionOfferCodeRedemption const
SalesReportTypeSubscriptionOfferCodeRedemption SalesReportType = "SUBSCRIPTION_OFFER_CODE_REDEMPTION"
//SalesReportTypeSubscriber const
SalesReportTypeSubscriber SalesReportType = "SUBSCRIBER"
)
const (
//SalesReportSubTypeSummary const
SalesReportSubTypeSummary SalesReportSubType = "SUMMARY"
//SalesReportSubTypeDetailed const
SalesReportSubTypeDetailed SalesReportSubType = "DETAILED"
//SalesReportSubTypeOptIn const
SalesReportSubTypeOptIn SalesReportSubType = "OPT_IN"
)
const (
//SalesReportVersion10 const
SalesReportVersion10 SalesReportVersion = "1_0"
//SalesReportVersion11 const
SalesReportVersion11 SalesReportVersion = "1_1"
//SalesReportVersion12 const
SalesReportVersion12 SalesReportVersion = "1_2"
//SalesReportVersion13 const
SalesReportVersion13 SalesReportVersion = "1_3"
)
// SalesReportsBaseFilter Sales reports filter
type SalesReportsBaseFilter struct {
ReportDate time.Time //The report date to download. The date is specified in the YYYY-MM-DD format for all report frequencies except DAILY, which does not require a specified date. For more information, see report availability and storage.
ReportSubType SalesReportSubType //(Required) The report sub type to download. For a list of values, see Allowed Values Based on Sales Report Type below. Possible values: SUMMARY, DETAILED, OPT_IN
ReportType SalesReportType //(Required) The report to download. For more details on each report type see About Reports. Possible values: SALES, PRE_ORDER, NEWSSTAND, SUBSCRIPTION, SUBSCRIPTION_EVENT, SUBSCRIBER
Frequency SalesReportFrequency //(Required) Frequency of the report to download. For a list of values, see Allowed Values Based on Sales Report Type below. Possible values: DAILY, WEEKLY, MONTHLY, YEARLY
Version SalesReportVersion //The version of the report. For a list of values, see Allowed Values Based on Sales Report Type below.
}
// SetReportDate Set report date
func (f *SalesReportsBaseFilter) SetReportDate(value time.Time) *SalesReportsBaseFilter {
f.ReportDate = value
return f
}
// SetReportSubType Set report sub type
func (f *SalesReportsBaseFilter) SetReportSubType(value SalesReportSubType) *SalesReportsBaseFilter {
f.ReportSubType = value
return f
}
// SubTypeDetailed Change report sub type to Detailed
func (f *SalesReportsBaseFilter) SubTypeDetailed() *SalesReportsBaseFilter {
return f.SetReportSubType(SalesReportSubTypeDetailed)
}
// SubTypeOptIn Change report sub type to OptIn
func (f *SalesReportsBaseFilter) SubTypeOptIn() *SalesReportsBaseFilter {
return f.SetReportSubType(SalesReportSubTypeOptIn)
}
// SubTypeSummary Change report sub type to Summary
func (f *SalesReportsBaseFilter) SubTypeSummary() *SalesReportsBaseFilter {
return f.SetReportSubType(SalesReportSubTypeSummary)
}
// SetReportType Set report type
func (f *SalesReportsBaseFilter) SetReportType(value SalesReportType) *SalesReportsBaseFilter {
f.ReportType = value
return f
}
// TypeSales Change report type to Sales
func (f *SalesReportsBaseFilter) TypeSales() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypeSales)
}
// TypePreOrder Change report type to PreOrder
func (f *SalesReportsBaseFilter) TypePreOrder() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypePreorder)
}
// TypeNewsStand Change report type to NewsStand
func (f *SalesReportsBaseFilter) TypeNewsStand() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypeNewsStand)
}
// TypeSubscription Change report type to Subscription
func (f *SalesReportsBaseFilter) TypeSubscription() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypeSubscription)
}
// TypeSubscriptionEvent Change report type to SubscriptionEvent
func (f *SalesReportsBaseFilter) TypeSubscriptionEvent() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypeSubscriptionEvent)
}
// TypeSubscriber Change report type to Subscriber
func (f *SalesReportsBaseFilter) TypeSubscriber() *SalesReportsBaseFilter {
return f.SetReportType(SalesReportTypeSubscriber)
}
// SetFrequency Set frequency
func (f *SalesReportsBaseFilter) SetFrequency(value SalesReportFrequency) *SalesReportsBaseFilter {
f.Frequency = value
return f
}
// Daily Change frequency to Daily
func (f *SalesReportsBaseFilter) Daily() *SalesReportsBaseFilter {
return f.SetFrequency(SalesReportFrequencyDaily)
}
// Weekly Change frequency to Weekly
func (f *SalesReportsBaseFilter) Weekly() *SalesReportsBaseFilter {
return f.SetFrequency(SalesReportFrequencyWeekly)
}
// Monthly Change frequency to Monthly
func (f *SalesReportsBaseFilter) Monthly() *SalesReportsBaseFilter {
return f.SetFrequency(SalesReportFrequencyMonthly)
}
// Yearly Change frequency to Yearly
func (f *SalesReportsBaseFilter) Yearly() *SalesReportsBaseFilter {
return f.SetFrequency(SalesReportFrequencyYearly)
}
// SetVersion Set version
func (f *SalesReportsBaseFilter) SetVersion(value SalesReportVersion) *SalesReportsBaseFilter {
f.Version = value
return f
}
// Version13 Change version to 1_3
func (f *SalesReportsBaseFilter) Version13() *SalesReportsBaseFilter {
return f.SetVersion(SalesReportVersion13)
}
// Version12 Change version to 1_2
func (f *SalesReportsBaseFilter) Version12() *SalesReportsBaseFilter {
return f.SetVersion(SalesReportVersion12)
}
// Version11 Change version to 1_1
func (f *SalesReportsBaseFilter) Version11() *SalesReportsBaseFilter {
return f.SetVersion(SalesReportVersion11)
}
// Version10 Change version to 1_0
func (f *SalesReportsBaseFilter) Version10() *SalesReportsBaseFilter {
return f.SetVersion(SalesReportVersion10)
}
// ToQueryParamsMap Convert filter to query params
func (f *SalesReportsBaseFilter) ToQueryParamsMap() map[string]interface{} {
qs := make(map[string]interface{})
qs["filter[reportSubType]"] = string(f.ReportSubType)
qs["filter[reportType]"] = string(f.ReportType)
qs["filter[frequency]"] = string(f.Frequency)
if !f.ReportDate.IsZero() {
qs["filter[reportDate]"] = f.ReportDate.Format("2006-01-02")
}
if f.Version != "" {
qs["filter[version]"] = string(f.Version)
}
return qs
}
// IsValid Validate sales report filter params
func (f *SalesReportsBaseFilter) IsValid() error {
if f.ReportType == "" {
return fmt.Errorf("SalesReportsBaseFilter.IsValid: %v", "ReportType is required")
}
if f.ReportSubType == "" {
return fmt.Errorf("SalesReportsBaseFilter.IsValid: %v", "ReportSubType is required")
}
if f.Frequency == "" {
return fmt.Errorf("SalesReportsBaseFilter.IsValid: %v", "Frequency is required")
}
return nil
}
// SalesReportsFilterInterface
type SalesReportsFilterInterface interface {
IsValid() error
ToQueryParamsMap() map[string]interface{}
}
// SalesReportsFilter
type SalesReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *SalesReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeSales {
return fmt.Errorf("SalesReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeSummary {
return fmt.Errorf("SalesReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Version != SalesReportVersion11 && f.Version != SalesReportVersion10 {
return fmt.Errorf("SalesReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// SubscriptionsReportsFilter
type SubscriptionsReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *SubscriptionsReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeSubscription {
return fmt.Errorf("SubscriptionsReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeSummary {
return fmt.Errorf("SubscriptionsReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Frequency != SalesReportFrequencyDaily {
return fmt.Errorf("SubscriptionsReportsFilter.IsValid: %v", "Frequency is not valid")
}
if f.Version != SalesReportVersion12 && f.Version != SalesReportVersion13 {
return fmt.Errorf("SubscriptionsReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// SubscriptionsEventsReportsFilter
type SubscriptionsEventsReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *SubscriptionsEventsReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeSubscriptionEvent {
return fmt.Errorf("SubscriptionsEventsReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeSummary {
return fmt.Errorf("SubscriptionsEventsReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Frequency != SalesReportFrequencyDaily {
return fmt.Errorf("SubscriptionsEventsReportsFilter.IsValid: %v", "Frequency is not valid")
}
if f.Version != SalesReportVersion12 && f.Version != SalesReportVersion13 {
return fmt.Errorf("SubscriptionsEventsReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// SubscribersReportsFilter
type SubscribersReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *SubscribersReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeSubscriber {
return fmt.Errorf("SubscribersReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeDetailed {
return fmt.Errorf("SubscribersReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Frequency != SalesReportFrequencyDaily {
return fmt.Errorf("SubscribersReportsFilter.IsValid: %v", "Frequency is not valid")
}
if f.Version != SalesReportVersion12 && f.Version != SalesReportVersion13 {
return fmt.Errorf("SubscribersReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// SubscriptionsOffersCodesRedemptionReportsFilter
type SubscriptionsOffersCodesRedemptionReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *SubscriptionsOffersCodesRedemptionReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeSubscriptionOfferCodeRedemption {
return fmt.Errorf("SubscriptionsOffersCodesRedemptionReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeSummary {
return fmt.Errorf("SubscriptionsOffersCodesRedemptionReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Frequency != SalesReportFrequencyDaily {
return fmt.Errorf("SubscriptionsOffersCodesRedemptionReportsFilter.IsValid: %v", "Frequency is not valid")
}
if f.Version != SalesReportVersion10 {
return fmt.Errorf("SubscriptionsOffersCodesRedemptionReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// NewsstandReportsFilter
type NewsstandReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *NewsstandReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypeNewsStand {
return fmt.Errorf("NewsstandReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeDetailed {
return fmt.Errorf("NewsstandReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Frequency != SalesReportFrequencyDaily && f.Frequency != SalesReportFrequencyWeekly {
return fmt.Errorf("NewsstandReportsFilter.IsValid: %v", "Frequency is not valid")
}
if f.Version != SalesReportVersion10 {
return fmt.Errorf("NewsstandReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// PreOrdersReportsFilter
type PreOrdersReportsFilter struct {
SalesReportsBaseFilter
}
// IsValid Validate sales report filter params
func (f *PreOrdersReportsFilter) IsValid() error {
err := f.SalesReportsBaseFilter.IsValid()
if err != nil {
return err
}
if f.ReportType != SalesReportTypePreorder {
return fmt.Errorf("PreOrdersReportsFilter.IsValid: %v", "ReportType is not valid")
}
if f.ReportSubType != SalesReportSubTypeSummary {
return fmt.Errorf("PreOrdersReportsFilter.IsValid: %v", "ReportSubType is not valid")
}
if f.Version != SalesReportVersion10 {
return fmt.Errorf("PreOrdersReportsFilter.IsValid: %v", "Version is not valid")
}
return nil
}
// NewSalesReportsFilter
func NewSalesReportsFilter() *SalesReportsFilter {
return &SalesReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeSales}}
}
// NewSubscriptionsReportsFilter
func NewSubscriptionsReportsFilter() *SubscriptionsReportsFilter {
return &SubscriptionsReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeSubscription}}
}
// NewSubscriptionsEventsReportsFilter
func NewSubscriptionsEventsReportsFilter() *SubscriptionsEventsReportsFilter {
return &SubscriptionsEventsReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeSubscriptionEvent}}
}
// NewSubscribersReportsFilter
func NewSubscribersReportsFilter() *SubscribersReportsFilter {
return &SubscribersReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeSubscriber}}
}
func NewSubscriptionsOffersCodesRedemptionReportsFilter() *SubscriptionsOffersCodesRedemptionReportsFilter {
return &SubscriptionsOffersCodesRedemptionReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeSubscriptionOfferCodeRedemption}}
}
// NewNewsstandReportsFilter
func NewNewsstandReportsFilter() *NewsstandReportsFilter {
return &NewsstandReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypeNewsStand}}
}
// NewPreOrdersReportsFilter
func NewPreOrdersReportsFilter() *PreOrdersReportsFilter {
return &PreOrdersReportsFilter{SalesReportsBaseFilter{ReportType: SalesReportTypePreorder}}
}