-
Notifications
You must be signed in to change notification settings - Fork 0
/
etsy_synchronizer.go
59 lines (54 loc) · 1.62 KB
/
etsy_synchronizer.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
package main
import (
"time"
)
type etsySynchronizer struct {
dCache dataStore
}
func newEtsySynchronizer(cache dataStore) *etsySynchronizer {
es := new(etsySynchronizer)
es.dCache = cache
return es
}
func (es *etsySynchronizer) processOrdersForUsers() {
for {
edm := newEtsyDataManager()
userList := es.dCache.getUserMap()
for _, userDetails := range userList {
if userDetails.TrelloDetails.SelectedBoardID == "" {
continue
}
orderList, err := edm.getTransactionList(userDetails)
if err != nil {
Error(err)
continue
}
lptID := userDetails.EtsyDetails.LastProcessedTrasactionID
for i := len(orderList.Results) - 1; i >= 0; i-- {
etsyTransaction := orderList.Results[i]
if etsyTransaction.ID > lptID && etsyTransaction.ShippedTime == 0 {
es.postTransactionToTrello(etsyTransaction, &userDetails)
lptID = etsyTransaction.ID
}
}
userDetails.EtsyDetails.LastProcessedTrasactionID = lptID
es.dCache.saveDetailsToCache(userDetails.UserID, userDetails)
}
time.Sleep(time.Second * 30)
}
}
func (es *etsySynchronizer) postTransactionToTrello(tranDetails etsyTransactionDetails, info *userInfo) {
tdm := newTrelloDataManager()
edm := newEtsyDataManager()
imageDetails, _ := edm.getImageDetails(info, tranDetails)
card := trelloCardDetails{
Name: tranDetails.Title,
Descripton: tranDetails.Description,
ListID: info.TrelloDetails.SelectedListID,
//Labels: info.EtsyDetails.UserShopDetails.ShopName,
URL: tranDetails.EtsyURL,
}
var resultCard trelloCardDetailsResponse
tdm.addCard(info, card, &resultCard)
tdm.attachImage(info, &resultCard, imageDetails)
}