exoteric 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/exoteric/api.rb +11 -8
- data/lib/exoteric/version.rb +1 -1
- metadata +1 -1
data/lib/exoteric/api.rb
CHANGED
@@ -4,17 +4,23 @@ require 'exoteric/counter'
|
|
4
4
|
module Exoteric
|
5
5
|
class API < Sinatra::Application
|
6
6
|
|
7
|
+
SCRIPT_TPL = <<-JS
|
8
|
+
var Exoteric={c:<%= @count.to_json %>, count: function(sn){return this.c[sn] || 0;}};
|
9
|
+
<% unless @callback.empty? %><%= @callback %>();<% end %>
|
10
|
+
JS
|
11
|
+
|
7
12
|
get "/count.json" do
|
8
13
|
content_type "application/json"
|
9
14
|
|
10
15
|
begin
|
11
16
|
networks = (params[:n] || '').split(',')
|
12
17
|
counter = Counter.new(params)
|
13
|
-
|
14
|
-
|
18
|
+
@count = counter.count(*networks)
|
19
|
+
|
20
|
+
@count.to_json
|
15
21
|
rescue => e
|
16
22
|
status 500
|
17
|
-
|
23
|
+
{ :error => e.to_s }.to_json
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
@@ -27,13 +33,10 @@ module Exoteric
|
|
27
33
|
counter = Counter.new(params)
|
28
34
|
@count = counter.count(*networks)
|
29
35
|
|
30
|
-
erb
|
31
|
-
var Exoteric={c:<%= @count.to_json %>, count: function(sn){return this.c[sn] || 0;}};
|
32
|
-
<% unless @callback.empty? %><%= @callback %>();<% end %>
|
33
|
-
SCRIPT
|
36
|
+
erb SCRIPT_TPL
|
34
37
|
rescue => e
|
35
38
|
status 500
|
36
|
-
|
39
|
+
{ :error => e.to_s }.to_json
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
data/lib/exoteric/version.rb
CHANGED