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 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
- counter.count(*networks).to_json
18
+ @count = counter.count(*networks)
19
+
20
+ @count.to_json
15
21
  rescue => e
16
22
  status 500
17
- return { :error => e.to_s }.to_json
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 <<-SCRIPT
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
- return { :error => e.to_s }.to_json
39
+ { :error => e.to_s }.to_json
37
40
  end
38
41
  end
39
42
 
@@ -1,5 +1,5 @@
1
1
  module Exoteric
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
 
4
4
  def self.version
5
5
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exoteric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: