-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
39 lines (31 loc) · 794 Bytes
/
app.rb
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
# [START all]
require 'digest/sha2'
require 'sinatra'
require 'google/cloud/datastore'
get '/' do
erb :lookup
end
get '/search' do
project_id = 'b-a-k-h'
datastore = Google::Cloud::Datastore.new
query = datastore.query('Product')
.select('name')
.order('name', :asc)
.distinct_on('name')
.limit(12)
.where('name', '>=', params[:term])
products = datastore.run query
names = []
products.each do |product|
names << product['name'] if product['name'] =~ /#{Regexp.escape params[:term]}(.*)/i
end
response.write names
content_type :json
status 200
end
get '/_ah/health' do
response.write 'sall good, man'
status 200
end
# [END all]
__END__