-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_all_posts_mentioning_github.rb
More file actions
50 lines (41 loc) · 1.14 KB
/
find_all_posts_mentioning_github.rb
File metadata and controls
50 lines (41 loc) · 1.14 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
Bundler.require
class SearchPostStream
def initialize(keyword, language: nil)
# Set environment variable TWINGLY_SEARCH_KEY
client = Twingly::Search::Client.new do |client|
client.user_agent = "MyCompany/1.0" # Set optional user agent
end
@query = client.query do |query|
query_parts = [
"sort-order:asc",
"sort:published",
keyword,
]
query_parts << "lang:#{language}" if language
query.search_query = query_parts.join(" ")
end
end
# Run block for each blog post returned from api.
# Uses a sliding time-based window to get all results.
# @see https://app.twingly.com/blog_search?tab=documentation
def each
loop do
result = execute_with_retry
result.posts.each do |post|
yield post
end
break if result.all_results_returned?
@query.start_time = result.posts.last.published_at
end
end
private
def execute_with_retry
Retryable.retryable(on: Twingly::Search::ServerError) do
@query.execute
end
end
end
stream = SearchPostStream.new("(github) AND (hipchat OR slack)")
stream.each do |post|
puts post.url
end