-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsale.go
79 lines (68 loc) · 1.91 KB
/
sale.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
package appannie
import (
"fmt"
"net/url"
"time"
)
type SaleInfo struct {
Date string
ProductId string `json:"product_id,omitempty"`
Country string
Units struct {
Product struct{ Downloads, Updates, Refunds, Promotions int64 }
Iap struct{ Sales, Refunds, Promotions int }
}
Revenue struct {
Product struct{ Downloads, Updates, Refunds, Promotions string }
Iap struct{ Sales, Refunds, Promotions string }
Ad string
}
}
type IapSaleInfo struct {
Date string
Country string
Iap string
Units struct{ Sales, Refunds, Promotions int }
Revenue struct {
Sales string
Refunds string
Promotions string
}
}
type ProductSaleResponse struct {
APIResponse
Currency string
Vertical string
Market string
SalesList []SaleInfo `json:"sales_list,omitempty"`
IapSales []IapSaleInfo `json:"iap_sales,omitempty"`
PageNum int `json:"page_num"`
PageIndex int `json:"page_index"`
PrevPage int `json:"prev_page"`
NextPage int `json:"next_page"`
}
func (cli *Client) ProductSales(accountId, productId int, start, end time.Time) (info ProductSaleResponse, err error) {
q := url.Values{}
q.Set("break_down", "date")
q.Set("start_date", start.Format("2006-01-02"))
q.Set("end_date", end.Format("2006-01-02"))
//q.Set("page_index", "0")
//q.Set("currency", "USD")
//q.Set("countries", "all")
path := fmt.Sprintf("/accounts/%d/products/%d/sales", accountId, productId)
err = cli.request(path, q, &info)
return
}
//TODO:Need to be testing
func (cli *Client) AccountSales(accountId int, start, end time.Time) (info ProductSaleResponse, err error) {
q := url.Values{}
q.Set("break_down", "date")
q.Set("start_date", start.Format("2006-01-02"))
q.Set("end_date", end.Format("2006-01-02"))
//q.Set("page_index", "0")
//q.Set("currency", "USD")
//q.Set("countries", "all")
path := fmt.Sprintf("/accounts/%d/sales", accountId)
err = cli.request(path, q, &info)
return
}