-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
49 lines (40 loc) · 980 Bytes
/
data.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 polr
import (
"encoding/json"
"net/url"
)
type DataResultContainer struct {
Action string `json:"action"`
Result DataResult `json:"result"`
}
type DataResult struct {
URLEnding string `json:"url_ending"`
Data []struct {
Label string `json:"label"`
Clicks int `json:"clicks"`
X string `json:"x"`
Y int `json:"y"`
} `json:"data"`
}
// Shorten shortens an url.
func (c *Polr) Data(urlEnding, statsType, leftBound, rightBound string) (re *DataResult, err error) {
p := url.Values{}
p.Set("url_ending", urlEnding)
p.Set("stats_type", statsType)
if leftBound != "" {
p.Set("left_bound", leftBound)
}
if rightBound != "" {
p.Set("right_bound", rightBound)
}
resp, err := c.makeRequest("POST", "data/link?"+p.Encode(), nil)
if err != nil {
return nil, err
}
var reContainer DataResultContainer
uErr := json.Unmarshal(resp, &reContainer)
if uErr != nil {
return nil, uErr
}
return &reContainer.Result, nil
}