-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
39 lines (31 loc) · 1.16 KB
/
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
# Require the environment file
require './env.rb'
# Before each route is run create a new geoloqi session for the user.
before do
http_auth = request.env['HTTP_AUTHORIZATION'] || params[:lq_access_token]
@geoloqi = Geoloqi::Session.new :access_token => (http_auth ? http_auth.gsub('Bearer ', '') : nil)
end
# Home page
get '/' do
erb :index
end
# The Titanium App will request this to get a list of categories the user is subscribed to
get '/api/categories' do
# Get a list of all the layers created by the application
layers = Geoloqi::Session.new(:access_token => CONFIG[:geoloqi][:app_access_token]).get('layer/list')[:layers]
# Get a list of all the layers the user is subscribed to
subscribed = @geoloqi.get('layer/subscriptions')
# Start building a response
resp = { :categories => [] }
# For each layer add a entry to the response with layer id, layer name, and subscription status
layers.each do |l|
resp[:categories].push({
:id => l[:layer_id],
:name => l[:name],
:subscribed => !subscribed.select {|s| s[:layer_id] == l[:layer_id]}.empty?
})
end
# Respond with JSON
content_type :json
resp.to_json
end