forked from ChimeraCoder/anaconda
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jobs.go
49 lines (37 loc) · 1.09 KB
/
jobs.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
package anaconda
import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
)
func (a TwitterApi) PostStatsJobs(idaccount string, values url.Values) (job Job, err error) {
response_ch := make(chan response)
a.queryQueue <- query{fmt.Sprintf("%s/stats/jobs/accounts/%s", AdsUrl, idaccount), values, &job, _POST, response_ch}
return job, (<-response_ch).err
}
func (a TwitterApi) GetStatsJobs(idaccount string, values url.Values) (jobs Jobs, err error) {
response_ch := make(chan response)
a.queryQueue <- query{fmt.Sprintf("%s/stats/jobs/accounts/%s", AdsUrl, idaccount), values, &jobs, _GET, response_ch}
return jobs, (<-response_ch).err
}
func (a TwitterApi) ParseStatsJobs(url string) (stats Stats, err error) {
var (
resp *http.Response
archive *gzip.Reader
)
if resp, err = http.Get(url); err == nil {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
err = errors.New(resp.Status)
return
}
if archive, err = gzip.NewReader(resp.Body); err == nil {
defer archive.Close()
err = json.NewDecoder(archive).Decode(&stats)
}
}
return
}