-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_sjs.go
84 lines (66 loc) · 1.47 KB
/
source_sjs.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
package main
import (
"encoding/json"
"log"
"strconv"
)
type SjsResponeRoot struct {
TotalCount int `json:"totalCount"`
Documents []SjsJob `json:"documents"`
}
type SjsJob struct {
Link string
Id int `json:"id"`
JobNumber int `json:"jobNumber"`
Name string `json:"Name"`
ShortDescription string `json:"ShortDescription"`
Status struct {
Title string `json:"title"`
} `json:"Status"`
Type struct {
Title string `json:"title"`
} `json:"Type"`
}
func (job SjsJob) GetLink() string {
return job.Link
}
func (job SjsJob) GetTitle() string {
return job.Name
}
func (job SjsJob) GetDescription() string {
return job.ShortDescription
}
func (job SjsJob) GetType() string {
return job.Type.Title
}
type Sjs struct {
Container string
RequestMethod string
}
func SjsMakeSource() *Sjs {
source := &Sjs{}
source.RequestMethod = METHOD_GET
return source
}
func (sjs *Sjs) GetRequestMethod() string {
return sjs.RequestMethod
}
func (sjs *Sjs) GetRequestData() []byte {
return make([]byte, 0)
}
func (sjs *Sjs) GetQuery() string {
return ""
}
func (sjs *Sjs) GetOnScrapedHandler(data []byte) []IEntity {
parsedData := &SjsResponeRoot{}
err := json.Unmarshal(data, parsedData)
if err != nil {
log.Fatal(err)
}
jobs := make([]IEntity, 0)
for _, job := range parsedData.Documents {
job.Link = "https://www.sjs.co.nz/job/" + strconv.Itoa(job.Id)
jobs = append(jobs, job)
}
return jobs
}