-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch.go
More file actions
112 lines (99 loc) · 3.58 KB
/
Copy pathsearch.go
File metadata and controls
112 lines (99 loc) · 3.58 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package twitter
import (
"fmt"
"net/url"
"time"
)
// GetTweetsSearchRecent returns Tweets from the last 7 days that match a search query.
// Endpoint URL: https://api.twitter.com/2/tweets/search/recent
// Official Documentation: https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent
// Authentication Methods: OAuth 1.0a User Context, OAuth 2.0 Bearer Token
// Rate Limit: 450/15m (app), 180/15m (user)
func (api *Twitter) GetTweetsSearchRecent(v url.Values, options ...QueueOption) (chan *Data, chan error) {
// create the queue to process requests
queue := NewQueue(15*time.Minute/450, 15*time.Minute, true, make(chan *Request), make(chan *Response), options...)
// create the temp results channel
data := make(chan *Data)
errors := make(chan error)
// create the request object
request, _ := NewRquest("GET", fmt.Sprintf("%s/tweets/search/recent", api.baseURL), v, nil)
// start the requests channel processor
go queue.processRequests(api)
// add the 1st request to the channel
queue.requestsChannel <- request
// async process the response channel
go (func(q *Queue, d chan *Data, e chan error, req *Request) {
// on done close channels
// close data channel
defer close(d)
// close error channel
defer close(e)
// listen channel
for {
// capture the response and channel state
res, ok := <-q.responseChannel
// break the loop if the channel is closed
if !ok {
break
}
// send the results to the data channel
d <- &res.Results
// send errors to error channel
if res.Error != nil {
e <- res.Error
}
// we are done! break the loop and close the channels
break
}
})(queue, data, errors, request)
// return the data channel
return data, errors
}
// GetTweetsSearchAll returns the complete history of public Tweets matching a search query;
// since the first Tweet was created March 26, 2006. This endpoint is part of a
// **private beta** for academic researchers only.
// *Please do not share this documentation.*
// Endpoint URL: https://api.twitter.com/2/tweets/search/all
// Official Documentation: https://developer.twitter.com/en/docs/twitter-api/tweets/full-archive-search/api-reference/get-tweets-search-all
// Authentication Methods: OAuth 2.0 Bearer Token
// Rate Limit: 300/15m (app), 1/1s (user)
func (api *Twitter) GetTweetsSearchAll(v url.Values, options ...QueueOption) (chan *Data, chan error) {
// create the queue to process requests
queue := NewQueue(15*time.Minute/300, 15*time.Minute, true, make(chan *Request), make(chan *Response), options...)
// create the temp results channel
data := make(chan *Data)
errors := make(chan error)
// create the request object
request, _ := NewRquest("GET", fmt.Sprintf("%s/tweets/search/all", api.baseURL), v, nil)
// start the requests channel processor
go queue.processRequests(api)
// add the 1st request to the channel
queue.requestsChannel <- request
// async process the response channel
go (func(q *Queue, d chan *Data, e chan error, req *Request) {
// on done close channels
// close data channel
defer close(d)
// close error channel
defer close(e)
// listen channel
for {
// capture the response and channel state
res, ok := <-q.responseChannel
// break the loop if the channel is closed
if !ok {
break
}
// send the results to the data channel
d <- &res.Results
// send errors to error channel
if res.Error != nil {
e <- res.Error
}
// we are done! break the loop and close the channels
break
}
})(queue, data, errors, request)
// return the data channel
return data, errors
}