-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
50 lines (41 loc) · 1.15 KB
/
project.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
package gocrawlhq
import (
"encoding/json"
"net/http"
)
type Project struct {
Paused bool `json:"paused"`
Name string `json:"name"`
Exclusions []string `json:"exclusions"`
SeencheckEnabled bool `json:"seencheck_enabled"`
SeencheckTTL int `json:"seencheck_ttl"`
Stats struct {
Pending int `json:"pending"`
Processing int `json:"processing"`
CompletedSeeds int `json:"completed_seeds"`
CompletedAssets int `json:"completed_assets"`
} `json:"stats"`
}
func (c *Client) GetProject() (p *Project, err error) {
expectedStatusCodes := 200
req, err := http.NewRequest(http.MethodGet, c.ProjectEndpoint.String(), nil)
if err != nil {
return p, err
}
req.Header.Add("X-Auth-Key", c.Key)
req.Header.Add("X-Auth-Secret", c.Secret)
req.Header.Add("User-Agent", "gocrawlhq/"+Version)
if c.Identifier != "" {
req.Header.Add("X-Identifier", c.Identifier)
}
resp, err := c.HTTPClient.Do(req)
if err != nil {
return p, err
}
defer resp.Body.Close()
if resp.StatusCode != expectedStatusCodes {
return p, err
}
err = json.NewDecoder(resp.Body).Decode(&p)
return p, err
}