/
search.go
35 lines (29 loc) · 996 Bytes
/
search.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
package anaconda
import (
"net/url"
)
type SearchMetadata struct {
CompletedIn float32 `json:"completed_in"`
MaxId int64 `json:"max_id"`
MaxIdString string `json:"max_id_str"`
Query string `json:"query"`
RefreshUrl string `json:"refresh_url"`
Count int `json:"count"`
SinceId int64 `json:"since_id"`
SinceIdString string `json:"since_id_str"`
}
type SearchResponse struct {
Statuses []Tweet `json:"statuses"`
Metadata SearchMetadata `json:"search_metadata"`
}
func (a TwitterApi) GetSearch(queryString string, v url.Values) (sr SearchResponse, err error) {
v = cleanValues(v)
v.Set("q", queryString)
response_ch := make(chan response)
a.queryQueue <- query{BaseUrl + "/search/tweets.json", v, &sr, _GET, response_ch}
// We have to read from the response channel before assigning to timeline
// Otherwise this will happen before the responses have been written
resp := <-response_ch
err = resp.err
return sr, err
}