/
hire_with_google_helper.go
88 lines (77 loc) 路 2.36 KB
/
hire_with_google_helper.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
package jobpostings
import (
"context"
"encoding/json"
"net/http"
"strings"
)
type hireWithGoogleJobs []struct {
//Context string `json:"@context"`
//Type string `json:"@type"`
//DatePosted time.Time `json:"datePosted"`
//Description string `json:"description"`
//HiringOrganization struct {
// Type string `json:"@type"`
// Name string `json:"name"`
// Department struct {
// Type string `json:"@type"`
// Name string `json:"name"`
// } `json:"department"`
// Logo string `json:"logo"`
//} `json:"hiringOrganization"`
//Identifier struct {
// Type string `json:"@type"`
// Name string `json:"name"`
// Value string `json:"value"`
//} `json:"identifier"`
JobLocation struct {
Type string `json:"@type"`
Address struct {
Type string `json:"@type"`
AddressLocality string `json:"addressLocality"`
//AddressRegion string `json:"addressRegion"`
AddressCountry string `json:"addressCountry"`
} `json:"address"`
} `json:"jobLocation"`
Title string `json:"title"`
URL string `json:"url"`
//EmploymentType string `json:"employmentType"`
}
// curl 'https://hire.withgoogle.com/v2/api/t/company/public/jobs/' | jq .
func getHireWithGoogleJobPostingsFor(ctx context.Context, company string) (<-chan *JobPosting, error) {
req, err := http.NewRequest("GET", "https://hire.withgoogle.com/v2/api/t/"+company+"/public/jobs/", nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req = req.WithContext(ctx)
resp, err := HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
doc := hireWithGoogleJobs{}
err = json.NewDecoder(resp.Body).Decode(&doc)
if err != nil {
return nil, err
}
jobPostings := make(chan *JobPosting)
go func() {
defer close(jobPostings)
for _, item := range doc {
url := strings.TrimSpace(strings.Replace(item.URL, "http://", "https://", -1))
titleStr := strings.TrimSpace(item.Title)
locationStr := "unknown"
if item.JobLocation.Type == "@Place" || item.JobLocation.Type == "Place" {
locationStr = strings.Join([]string{item.JobLocation.Address.AddressLocality, item.JobLocation.Address.AddressCountry}, ",")
}
jobPostings <- &JobPosting{
Company: company,
URL: url,
Title: titleStr,
Location: locationStr,
}
}
}()
return jobPostings, nil
}