-
Notifications
You must be signed in to change notification settings - Fork 11
/
wildberries.go
70 lines (58 loc) · 1.97 KB
/
wildberries.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
package wildberries
//import "gopkg.in/webnice/debug.v1"
//import "gopkg.in/webnice/log.v2"
import (
"fmt"
"time"
"github.com/webnice/wildberries/models/wildberries/incomes"
monthSale "github.com/webnice/wildberries/models/wildberries/month_detail_sale"
"github.com/webnice/wildberries/models/wildberries/orders"
"github.com/webnice/wildberries/models/wildberries/sales"
"github.com/webnice/wildberries/models/wildberries/stocks"
"github.com/webnice/wildberries/modules/communication"
)
// New Creates an new object of package and return interface
func New(apiKey string) Interface {
var (
com communication.Interface
wbs *impl
uri string
fromAt time.Time
)
com, fromAt = communication.New(), time.Now().Truncate(time.Hour*24)
uri = fmt.Sprintf(serviceURNv1, serviceURL)
wbs = &impl{
apiKey: apiKey,
inc: incomes.New(com, uri, apiKey, fromAt),
ods: orders.New(com, uri, apiKey, fromAt),
sle: sales.New(com, uri, apiKey, fromAt),
stk: stocks.New(com, uri, apiKey, fromAt),
mds: monthSale.New(com, uri, apiKey, fromAt),
com: com,
fromAt: fromAt,
}
return wbs
}
// From Set of date and time of the beginning of the period for data request
func (wbs *impl) From(from time.Time) Interface {
if from.IsZero() {
return wbs
}
wbs.fromAt = from
wbs.inc.From(wbs.fromAt)
wbs.ods.From(wbs.fromAt)
wbs.sle.From(wbs.fromAt)
wbs.stk.From(wbs.fromAt)
wbs.mds.From(wbs.fromAt)
return wbs
}
// Incomes methods of reports about supply
func (wbs *impl) Incomes() incomes.Interface { return wbs.inc }
// Orders methods of reports about orders
func (wbs *impl) Orders() orders.Interface { return wbs.ods }
// Sales methods of reports about sales
func (wbs *impl) Sales() sales.Interface { return wbs.sle }
// Stocks methods of reports about warehouse
func (wbs *impl) Stocks() stocks.Interface { return wbs.stk }
// MonthDetailSale methods of reports about monthly sales
func (wbs *impl) MonthDetailSale() monthSale.Interface { return wbs.mds }