-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsvc_order.go
93 lines (77 loc) · 3.9 KB
/
svc_order.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
package lokalise
import (
"fmt"
)
const (
pathOrders = "orders"
)
type OrderService struct {
BaseService
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
type Order struct {
WithProjectID
WithCreationTime
WithCreationUser
OrderID string `json:"order_id"`
CardID int64 `json:"card_id"`
PaymentMethod string `json:"payment_method"`
Status string `json:"status"`
SourceLangISO string `json:"source_language_iso"`
TargetLangISOs []string `json:"target_language_isos"`
Keys []int64 `json:"keys"`
SourceWords map[string]int64 `json:"source_words"`
ProviderSlug string `json:"provider_slug"`
TranslationStyle string `json:"translation_style,omitempty"`
TranslationTierID int64 `json:"translation_tier"`
TranslationTierName string `json:"translation_tier_name"`
Briefing string `json:"briefing,omitempty"`
Total float64 `json:"total"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type CreateOrder struct {
ProjectID string `json:"project_id"`
CardID int64 `json:"card_id"`
PaymentMethod string `json:"payment_method"`
Briefing string `json:"briefing"`
SourceLangISO string `json:"source_language_iso"`
TargetLangISOs []string `json:"target_language_isos"`
Keys []int `json:"keys"`
ProviderSlug string `json:"provider_slug"`
TranslationTierID int64 `json:"translation_tier"`
DryRun bool `json:"dry_run,omitempty"`
TranslationStyle string `json:"translation_style,omitempty"`
}
type OrdersResponse struct {
Paged
Orders []Order `json:"orders"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *OrderService) List(teamID int64) (r OrdersResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), fmt.Sprintf("%s/%d/%s", pathTeams, teamID, pathOrders), &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *OrderService) Create(teamID int64, order CreateOrder) (r Order, err error) {
resp, err := c.post(c.Ctx(), fmt.Sprintf("%s/%d/%s", pathTeams, teamID, pathOrders), &r, order)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *OrderService) Retrieve(teamID int64, orderID string) (r Order, err error) {
resp, err := c.get(c.Ctx(), fmt.Sprintf("%s/%d/%s/%s", pathTeams, teamID, pathOrders, orderID), &r)
if err != nil {
return
}
return r, apiError(resp)
}