-
Notifications
You must be signed in to change notification settings - Fork 2
/
cas.go
79 lines (70 loc) · 1.6 KB
/
cas.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 main
import "log"
const QueryTitlesTableByPriceCode = `SELECT item_id, price FROM service_titles WHERE price_code = $1`
func listItems(e *Envelope) {
titleId, err := e.getKey("TitleId")
if err != nil {
e.Error(9, "Unable to obtain title.", err)
}
attrs, err := e.getKeys("AttributeFilters")
if err != nil {
e.Error(5, "AttributeFilters key did not exist!", err)
}
var licenceStr string
var pricingCode string
for _, attr := range attrs {
name, value := parseNameValue(attr.InnerText())
if name == "TitleKind" {
licenceStr = value
} else if name == "PricingCode" {
pricingCode = value
}
}
// Now validate
licenceKind, err := GetLicenceKind(licenceStr)
if err != nil {
e.Error(5, "Invalid TitleKind was passed by SOAP", err)
}
// Query the titles table to get our title
row := pool.QueryRow(ctx, QueryTitlesTableByPriceCode, pricingCode)
var itemId int
var price int
err = row.Scan(&itemId, &price)
if err != nil {
log.Printf("error while querying titles table: %v", err)
e.Error(2, "error retrieving title", nil)
return
}
e.AddKVNode("ListResultTotalSize", "1")
e.AddCustomType(Items{
TitleId: titleId,
Contents: ContentsMetadata{
TitleIncluded: false,
ContentIndex: 0,
},
Attributes: []Attributes{
{
Name: "TitleVersion",
Value: "0",
},
{
Name: "Prices",
Value: "1",
},
},
Ratings: Ratings{
Name: "E",
Rating: 1,
Age: 9,
},
Prices: Prices{
ItemId: itemId,
Price: Price{
Amount: price,
Currency: "POINTS",
},
Limits: LimitStruct(PR),
LicenseKind: *licenceKind,
},
})
}