-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoonshine.warclight.go
95 lines (80 loc) · 2.42 KB
/
moonshine.warclight.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
94
95
// Warclight Pieces
//
// NB. OBSOLETE and should be removed when there is an opportunity. I
// want to query the status of this and understand more where the
// resource went.
package main
import (
"encoding/json"
"fmt"
)
//lint:file-ignore U1000 Ignore all unused code, it serves a reference purpose.
// newWarclightSearch creates a ShineRequest object to enable us to query Shine/Warclight.
func newWarclightSearch(page int, ffb string, sort string, order string) shineRequest {
//
// Example warclight requests:
// * `http://warclight.archivesunleashed.org/catalog.json?f[content_ffb][]=47494638&page=2`
//
//
var newShine shineRequest
newShine.shineURL = "http://warclight.archivesunleashed.org/catalog.json"
newShine.page = fmt.Sprintf("%d", page)
newShine.badDeed = fmt.Sprintf("f[content_ffb][]=%s", ffb)
newShine.sort = fmt.Sprintf("sort=%s", sort)
newShine.order = fmt.Sprintf("order=%s", order)
return newShine
}
func statWarclightResults(resp string) (int, int, error) {
wl, err := parseWarclight(resp)
if err != nil {
return 0, 0, err
}
return wl.Meta.Pages.TotalCount,
wl.Meta.Pages.TotalPages,
nil
}
// WarclightResult holds the Warclight return data
type WarclightResult struct {
Data []WarclightAttrs
Meta WarclightMeta
}
// WarclightAttrs data contains information about the web pages returned
type WarclightAttrs struct {
Attributes WarclightAttrDetails
}
// WarclightAttrDetails stores web page attributes including the URL we want
type WarclightAttrDetails struct {
URL string
}
// WarclightMeta contains metadata about the result returned
type WarclightMeta struct {
Pages WarclightPages
}
// WarclightPages is our result metadata
type WarclightPages struct {
CurrentPage int `json:"Current_Page"`
FirstPage bool `json:"First_Page"`
LastPage bool `json:"Last_Page"`
LimitValue int `json:"Limit_Value"`
TotalCount int `json:"Total_Count"`
TotalPages int `json:"Total_Pages"`
}
func parseWarclight(data string) (WarclightResult, error) {
var js WarclightResult
json.Unmarshal([]byte(data), &js)
if js.Meta.Pages.CurrentPage < 1 {
return WarclightResult{}, fmt.Errorf("unable to read JSON result")
}
return js, nil
}
func parseJSONForLinks(js string) ([]string, error) {
var httpSlice []string
wl, err := parseWarclight(js)
if err != nil {
return httpSlice, err
}
for index := range wl.Data {
httpSlice = append(httpSlice, wl.Data[index].Attributes.URL)
}
return httpSlice, nil
}