exoteric 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/exoteric.gemspec CHANGED
@@ -21,8 +21,10 @@ DESCR
21
21
 
22
22
  gem.add_dependency 'rest-client'
23
23
  gem.add_dependency 'json'
24
+ gem.add_dependency 'rack'
24
25
 
25
26
  gem.add_development_dependency 'minitest'
26
27
  gem.add_development_dependency 'rspec'
27
28
  gem.add_development_dependency 'mocha'
29
+ gem.add_development_dependency 'rack-test'
28
30
  end
@@ -0,0 +1,44 @@
1
+ require 'sinatra'
2
+ require 'exoteric/counter'
3
+
4
+ module Exoteric
5
+ class API < Sinatra::Application
6
+
7
+ get "/count.json" do
8
+ content_type "application/json"
9
+
10
+ begin
11
+ networks = (params[:n] || '').split(',')
12
+ counter = Counter.new(params)
13
+
14
+ counter.count(*networks).to_json
15
+ rescue => e
16
+ status 500
17
+ return { :error => e.to_s }.to_json
18
+ end
19
+ end
20
+
21
+ get "/count.js" do
22
+ content_type "text/javascript"
23
+
24
+ begin
25
+ networks = (params[:n] || '').split(',')
26
+ @callback = params[:cb].to_s
27
+ counter = Counter.new(params)
28
+ @count = counter.count(*networks)
29
+
30
+ erb :script
31
+ rescue => e
32
+ status 500
33
+ return { :error => e.to_s }.to_json
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ __END__
41
+
42
+ @@ script
43
+ var Exoteric={c:<%= @count.to_json %>, count: function(sn){return this.c[sn] || 0;}};
44
+ <% unless @callback.empty? %><%= @callback %>();<% end %>
@@ -16,7 +16,7 @@ module Exoteric
16
16
 
17
17
  def initialize(options = {})
18
18
  @url, @options = options[:url], options
19
- raise ArgumentError, "No :url option specified" if @url.to_s.empty?
19
+ raise ArgumentError, "Site url not specified" if @url.to_s.empty?
20
20
  end
21
21
 
22
22
  def count(*counters)
@@ -1,5 +1,5 @@
1
1
  module Exoteric
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
data/spec/api_spec.rb ADDED
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'exoteric/api'
3
+
4
+ describe Exoteric::API do
5
+ let :app do
6
+ Exoteric::API.new
7
+ end
8
+
9
+ describe "resources" do
10
+ before do
11
+ Exoteric::Counter.stubs(:counters).returns(:test)
12
+ Exoteric::Counter.any_instance.stubs(:test_count).returns(10)
13
+ end
14
+
15
+ describe "/count.json" do
16
+ it "returns popularity count from selected networks" do
17
+ get "/count.json?url=http://github.com/&n=test"
18
+ last_response.should be_ok
19
+ JSON.parse(last_response.body)['test'].should == 10
20
+ end
21
+
22
+ it "returns an error when no url specified" do
23
+ get "/count.json?url=&n=test"
24
+ last_response.should_not be_ok
25
+ JSON.parse(last_response.body)['error'].should == 'Site url not specified'
26
+ end
27
+ end
28
+
29
+ describe "/count.js" do
30
+ it "returns script with preloaded counter values and executed callback" do
31
+ get "/count.js?url=http://github.com/&n=test&cb=testCallback"
32
+ last_response.should be_ok
33
+ last_response.body.should =~ /testCallback\(\)/
34
+ last_response.body.should =~ /\{\"test\":10\}/
35
+ end
36
+
37
+ it "returns script with preloaded counter values and no callback if not specified" do
38
+ get "/count.js?url=http://github.com/&n=test"
39
+ last_response.should be_ok
40
+ last_response.body.should =~ /\{\"test\":10\}/
41
+ end
42
+
43
+ it "returns an error when no url specified" do
44
+ get "/count.js?url=&n=test"
45
+ last_response.should_not be_ok
46
+ JSON.parse(last_response.body)['error'].should == 'Site url not specified'
47
+ end
48
+ end
49
+ end
50
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'rspec'
2
2
  require 'minitest/unit'
3
3
  require 'mocha'
4
+ require 'rack/test'
4
5
 
5
6
  require 'exoteric'
6
7
 
7
8
  RSpec.configure do |conf|
8
- conf.mock_with "mocha"
9
+ conf.mock_with "mocha"
10
+ conf.include Rack::Test::Methods
9
11
  end
12
+
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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rack
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: minitest
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +107,22 @@ dependencies:
91
107
  - - ! '>='
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rack-test
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
94
126
  description: Get page statistics from the most popular social networks.
95
127
  email:
96
128
  - chris@nu7hat.ch
@@ -106,12 +138,14 @@ files:
106
138
  - Rakefile
107
139
  - exoteric.gemspec
108
140
  - lib/exoteric.rb
141
+ - lib/exoteric/api.rb
109
142
  - lib/exoteric/counter.rb
110
143
  - lib/exoteric/counters/facebook.rb
111
144
  - lib/exoteric/counters/github.rb
112
145
  - lib/exoteric/counters/google_plus.rb
113
146
  - lib/exoteric/counters/twitter.rb
114
147
  - lib/exoteric/version.rb
148
+ - spec/api_spec.rb
115
149
  - spec/counter_spec.rb
116
150
  - spec/facebook_counter_spec.rb
117
151
  - spec/github_counter_spec.rb
@@ -144,6 +178,7 @@ specification_version: 3
144
178
  summary: Exoteric gives you page statistics from the most popular social networks,
145
179
  i.a. number of tweets, how many people shared link on facebook or google plus etc.
146
180
  test_files:
181
+ - spec/api_spec.rb
147
182
  - spec/counter_spec.rb
148
183
  - spec/facebook_counter_spec.rb
149
184
  - spec/github_counter_spec.rb