6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/okbot/cli/stack.rb', line 6
def title
title = ask "Input text: "
print "Doing your title..."
spin_it{
sleep rand(4)+2
}
url = "https://api.stackexchange.com/2.2/search/advanced?pagesize=5&order=desc&sort=activity&title=#{title}&site=stackoverflow&filter=!1zSk2G.tfS9G_M7ErPqm("
uri = URI(url)
response = Net::HTTP.get(uri)
output = JSON.parse(response)
rows = []
output["items"].each_index do |i, t|
rows << ['Tags', output["items"][i]["tags"]]
rows << ['Title', output["items"][i]["title"]]
rows << ['Is answered', output["items"][i]["is_answered"]]
rows << ['Link', output["items"][i]["link"]]
rows << :separator
end
puts table([nil, Rainbow("Result for: #{title}").red], *rows)
end
|