exoteric 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ \#*
19
+ .\#*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exoteric.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Chris Kowalik
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Exoteric
2
+
3
+ Exoteric gives you page statistics from the most popular social networks, i.a.
4
+ number of tweets, how many people shared link on facebook or google plus
5
+ etc.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'exoteric'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install exoteric
20
+
21
+ ## Usage
22
+
23
+ Pretty simple stuff:
24
+
25
+ counter = Exoteric.new(:url => 'http://github.com/')
26
+ counter.count(:twitter, :facebook, :plusone)
27
+
28
+ Leaving requested counters blank or specifying `:all` will cause that
29
+ all registered APIs will be used to gather page popularity:
30
+
31
+ counter.count # shortcut for counter.count(:all)
32
+
33
+ Some APIs required extra parameters, eg. to get github watchers for
34
+ the repository you must specify `:github_repo` option:
35
+
36
+ counter = Exoteric.new(
37
+ :url => 'http://desantapp.com/',
38
+ :github_repo => 'nu7hatch/desantapp'
39
+ )
40
+ counter.count(:github)
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = ENV['RSPEC_OPTS']
7
+ end
8
+
9
+ task :test => :spec
10
+ task :default => :test
data/exoteric.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/exoteric/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Chris Kowalik"]
6
+ gem.email = ["chris@nu7hat.ch"]
7
+ gem.description = %q{Get page statistics from the most popular social networks.}
8
+ gem.summary = <<-DESCR
9
+ Exoteric gives you page statistics from the most popular social networks,
10
+ i.a. number of tweets, how many people shared link on facebook or google plus
11
+ etc.
12
+ DESCR
13
+ gem.homepage = "http://github.com/nu7hatch/exoteric/"
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.name = "exoteric"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Exoteric::VERSION
21
+
22
+ gem.add_dependency 'rest-client'
23
+ gem.add_dependency 'json'
24
+
25
+ gem.add_development_dependency 'minitest'
26
+ gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'mocha'
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module Exoteric
5
+ class Counter
6
+ attr_reader :url, :options
7
+
8
+ def self.<<(counter)
9
+ send :include, counter
10
+ counters << counter.id
11
+ end
12
+
13
+ def self.counters
14
+ @counters ||= []
15
+ end
16
+
17
+ def initialize(options = {})
18
+ @url, @options = options[:url], options
19
+ raise ArgumentError, "No :url option specified" if @url.to_s.empty?
20
+ end
21
+
22
+ def count(*counters)
23
+ if counters.size == 0 || counters.first == :all
24
+ counters = self.class.counters
25
+ end
26
+
27
+ counters.inject({}) do |res, name|
28
+ res[name] = send("#{name}_count")
29
+ res
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ require 'exoteric/counters/twitter'
36
+ require 'exoteric/counters/facebook'
37
+ require 'exoteric/counters/google_plus'
38
+ require 'exoteric/counters/github'
@@ -0,0 +1,20 @@
1
+ module Exoteric
2
+ module Facebook
3
+ def self.id
4
+ :facebook
5
+ end
6
+
7
+ def facebook_url
8
+ "http://graph.facebook.com/?ids=#{url}"
9
+ end
10
+
11
+ def facebook_count
12
+ res = RestClient.get(facebook_url)
13
+ JSON.parse(res.to_str)[url]['shares'].to_i
14
+ rescue
15
+ 0
16
+ end
17
+ end
18
+
19
+ Counter << Facebook
20
+ end
@@ -0,0 +1,24 @@
1
+ module Exoteric
2
+ module Github
3
+ def self.id
4
+ :github
5
+ end
6
+
7
+ def github_url
8
+ "https://api.github.com/repos/#{repo_name}"
9
+ end
10
+
11
+ def repo_name
12
+ options[:github_repo]
13
+ end
14
+
15
+ def github_count
16
+ res = RestClient.get(github_url)
17
+ JSON.parse(res.to_str)['watchers_count'].to_i
18
+ rescue
19
+ 0
20
+ end
21
+ end
22
+
23
+ Counter << Github
24
+ end
@@ -0,0 +1,19 @@
1
+ module Exoteric
2
+ module GooglePlus
3
+ def self.id
4
+ :plusone
5
+ end
6
+
7
+ def plusone_url
8
+ "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ"
9
+ end
10
+
11
+ def plusone_count
12
+ json = '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' + url + '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'
13
+ res = RestClient.post(plusone_url, json, :content_type => :json)
14
+ JSON.parse(res.to_str)[0]['result']['metadata']['globalCounts']['count'].to_i
15
+ end
16
+ end
17
+
18
+ Counter << GooglePlus
19
+ end
@@ -0,0 +1,20 @@
1
+ module Exoteric
2
+ module Twitter
3
+ def self.id
4
+ :twitter
5
+ end
6
+
7
+ def twitter_url
8
+ "http://urls.api.twitter.com/1/urls/count.json?url=#{url}"
9
+ end
10
+
11
+ def twitter_count
12
+ res = RestClient.get(twitter_url)
13
+ JSON.parse(res.to_str)['count'].to_i
14
+ rescue
15
+ 0
16
+ end
17
+ end
18
+
19
+ Counter << Twitter
20
+ end
@@ -0,0 +1,7 @@
1
+ module Exoteric
2
+ VERSION = "0.0.1"
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
data/lib/exoteric.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "exoteric/version"
2
+ require "exoteric/counter"
3
+
4
+ module Exoteric
5
+ def self.new(options)
6
+ Counter.new(options)
7
+ end
8
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Exoteric::Counter do
4
+ describe ".new" do
5
+ it "raises ArgumentError when no :url specified" do
6
+ expect { Exoteric::Counter.new }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ it "returns new instance when url specified" do
10
+ c = Exoteric::Counter.new(:url => 'http://github.com/')
11
+ c.should be
12
+ c.url.should == 'http://github.com/'
13
+ c.options.should have_key(:url)
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ subject do
19
+ Exoteric::Counter.new(:url => 'http://github.com/').tap do |c|
20
+ c.class.stubs(:counters).returns([:test])
21
+ c.expects(:test_count).returns(10)
22
+ end
23
+ end
24
+
25
+ it "counts popularity in specified social networks" do
26
+ res = subject.count(:test)
27
+ res[:test].should == 10
28
+ end
29
+
30
+ it "returns count from all registered apis when no params" do
31
+ res = subject.count
32
+ res[:test].should == 10
33
+ end
34
+
35
+ it "returns count from all registered apis when :all specified" do
36
+ res = subject.count(:all)
37
+ res[:test].should == 10
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Exoteric::Facebook do
4
+ subject do
5
+ Exoteric::Counter.new(:url => "http://github.com/")
6
+ end
7
+
8
+ describe "#facebook_count" do
9
+ it "returns number of facebook likes" do
10
+ subject.facebook_count.should > 0
11
+ end
12
+ end
13
+
14
+ describe "#count" do
15
+ it "returns number of facebook likes when :facebook param specified" do
16
+ subject.count(:facebook)[:facebook].should > 0
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Exoteric::Github do
4
+ subject do
5
+ Exoteric::Counter.new(
6
+ :url => 'http://areyoufuckingcoding.me',
7
+ :github_repo => 'nu7hatch/areyoufuckingcoding.me'
8
+ )
9
+ end
10
+
11
+ describe "#github_count" do
12
+ it "returns number of github repo watcher" do
13
+ subject.github_count.should > 0
14
+ end
15
+ end
16
+
17
+ describe "#count" do
18
+ it "returns number of github repo watchers when :github param specified" do
19
+ subject.count(:github)[:github].should > 0
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Exoteric::GooglePlus do
4
+ subject do
5
+ Exoteric::Counter.new(:url => "http://github.com/")
6
+ end
7
+
8
+ describe "#plusone_count" do
9
+ it "returns number of plusone shares" do
10
+ subject.plusone_count.should > 0
11
+ end
12
+ end
13
+
14
+ describe "#count" do
15
+ it "returns number of plusone shares when :plusone param specified" do
16
+ subject.count(:plusone)[:plusone].should > 0
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'minitest/unit'
3
+ require 'mocha'
4
+
5
+ require 'exoteric'
6
+
7
+ RSpec.configure do |conf|
8
+ conf.mock_with "mocha"
9
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Exoteric::Twitter do
4
+ subject do
5
+ Exoteric::Counter.new(:url => "http://github.com/")
6
+ end
7
+
8
+ describe "#twitter_count" do
9
+ it "returns number of tweets" do
10
+ subject.twitter_count.should > 0
11
+ end
12
+ end
13
+
14
+ describe "#count" do
15
+ it "returns number of tweets when :twitter param specified" do
16
+ subject.count(:twitter)[:twitter].should > 0
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exoteric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Kowalik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Get page statistics from the most popular social networks.
95
+ email:
96
+ - chris@nu7hat.ch
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - exoteric.gemspec
108
+ - lib/exoteric.rb
109
+ - lib/exoteric/counter.rb
110
+ - lib/exoteric/counters/facebook.rb
111
+ - lib/exoteric/counters/github.rb
112
+ - lib/exoteric/counters/google_plus.rb
113
+ - lib/exoteric/counters/twitter.rb
114
+ - lib/exoteric/version.rb
115
+ - spec/counter_spec.rb
116
+ - spec/facebook_counter_spec.rb
117
+ - spec/github_counter_spec.rb
118
+ - spec/google_plus_counter_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/twitter_counter_spec.rb
121
+ homepage: http://github.com/nu7hatch/exoteric/
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.24
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Exoteric gives you page statistics from the most popular social networks,
145
+ i.a. number of tweets, how many people shared link on facebook or google plus etc.
146
+ test_files:
147
+ - spec/counter_spec.rb
148
+ - spec/facebook_counter_spec.rb
149
+ - spec/github_counter_spec.rb
150
+ - spec/google_plus_counter_spec.rb
151
+ - spec/spec_helper.rb
152
+ - spec/twitter_counter_spec.rb