kloutbg 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ lib/klout.rb
2
+ Manifest
3
+ Rakefile
4
+ README
5
+ spec/klout_spec.rb
6
+ spec/spec.opts
7
+ spec/spec_helper.rb
8
+ tasks/rspec.rake
data/README ADDED
@@ -0,0 +1,23 @@
1
+ Klout measures influence on topics across the social web to find the people the world listens to
2
+
3
+ See http://klout.com for more information about their service
4
+
5
+ Install:
6
+
7
+ sudo gem install klout
8
+
9
+ Usage and Example
10
+
11
+ >> require 'rubygems'
12
+ >> require 'klout'
13
+ >> Klout.api_key = "yourkloutapikey"
14
+ >> Klout.score('jasontorres')
15
+ => {"user"=>{"kscore"=>19.74, "status"=>200, "status_message"=>"OK"}}
16
+ >> Klout.profile('jasontorres')
17
+ {"user"=>{"score"=>{"slope"=>0, "kscore"=>"19.7429", "kclass"=>"connector", "true_reach"=>"195", "amplification_score"=>"0", "kscore_description"=>"", "network_score"=>"0", "kclass_description"=>"You are a constant source of information to your friends and co-workers. There is a good chance that you probably introduced several of your friends to Twitter. Your taste and opinion is respected and your judgment is trusted.", "date_updated"=>"2009-07-09 00:59:08"}, "twitter_screen_name"=>"jasontorres", "status"=>200, "twitter_id"=>"406073", "status_message"=>"OK"}}
18
+
19
+ Disclaimer: Author is not anyway involved w/ Klout.com
20
+
21
+ Klout is a copyright trademark of Klout.com
22
+
23
+ MIT License
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'echoe'
3
+ require 'fileutils'
4
+ require './lib/klout'
5
+
6
+ Echoe.new 'klout', '0.1.0' do |p|
7
+ p.author = 'Jason Torres'
8
+ p.email = 'jason.e.torres@gmail.com'
9
+ p.url = 'http://github.com/jasontorres/klout'
10
+ p.description = "Klout - Twitter Analytics"
11
+ p.runtime_dependencies = ["typhoeus"]
12
+
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{kloutbg}
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jason Torres", "Brad Gilreath"]
9
+ s.date = %q{2010-11-04}
10
+ s.description = %q{Kloutbg - Fork of Jason Torres and updated to recent Klout API}
11
+ s.email = %q{bwgilreath@gmail.com}
12
+ s.extra_rdoc_files = ["lib/klout.rb", "README", "tasks/rspec.rake"]
13
+ s.files = ["lib/klout.rb", "Manifest", "Rakefile", "README", "spec/klout_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "klout.gemspec"]
14
+ s.homepage = %q{https://github.com/bgilreath/klout}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Klout", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{klout}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Kloutbg - Twitter Analytics}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<typhoeus>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<typhoeus>, [">= 0"])
32
+ end
33
+ end
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ =begin rdoc
7
+
8
+ Klout measures influence on topics across the social web to find the people the world listens to
9
+
10
+ See http://klout.com for more information about their service
11
+
12
+ Usage:
13
+
14
+ Klout.api_key = ""
15
+ Klout.score('jasontorres')
16
+
17
+ =end
18
+
19
+
20
+ class Klout
21
+ VERSION = '0.0.1'
22
+ class << self
23
+
24
+ @@base_host = "http://api.klout.com"
25
+ @@api_version = "1"
26
+ @@api_key = ""
27
+
28
+ def base_host=(host)
29
+ @@base_host = host
30
+ end
31
+
32
+ def api_key=(api)
33
+ @@api_key = api
34
+ end
35
+
36
+ def base_key
37
+ @@base_host
38
+ end
39
+
40
+ def api_key
41
+ @@api_key
42
+ end
43
+
44
+ def score(username)
45
+ #request_uri = "http://klout.com/api/twitter/1/klout/#{@@api_key}/#{username}.json"
46
+ request_uri = "#{@@base_host}/#{@@api_version}/klout.json?key=#{@@api_key}&users=#{username}"
47
+ return request(request_uri)
48
+ end
49
+
50
+ def profile(username)
51
+ request_uri = "http://klout.com/api/twitter/1.1/profiledetail/#{@@api_key}/#{username}.json"
52
+ return request(request_uri)
53
+ end
54
+
55
+ def request(request_uri)
56
+ url = URI.parse(request_uri)
57
+ response = Net::HTTP.start(url.host, url.port) { |http|
58
+ http.get(url.path)
59
+ }
60
+
61
+ case response
62
+ when Net::HTTPSuccess
63
+ if response.body
64
+ begin
65
+ JSON.parse(response.body)
66
+ rescue Exception => e
67
+ puts e.backtrace
68
+ false
69
+ end
70
+ end
71
+ else
72
+ response.error!
73
+ end
74
+ end
75
+
76
+
77
+
78
+ end
79
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Klout" do
4
+
5
+ before do
6
+ Klout.api_key = ""
7
+ end
8
+
9
+ it "should assign the correct API key" do
10
+ Klout.api_key.should == ""
11
+ end
12
+
13
+ context "score request" do
14
+ before do
15
+ @score_request ||= lambda {
16
+ Klout.score('jasontorres')
17
+ }
18
+
19
+ @score_result ||= @score_request.call
20
+ end
21
+
22
+ it "should score!" do
23
+ @score_result.should be_instance_of(Hash)
24
+ end
25
+
26
+ it "should have the required keys" do
27
+ @score_result.has_key?('user').should == true
28
+ @score_result['user'].has_key?('kscore').should == true
29
+ @score_result['user'].has_key?('status').should == true
30
+ @score_result['user'].has_key?('status_message').should == true
31
+ end
32
+ end
33
+
34
+ context "profile request" do
35
+ before do
36
+ @profile_request ||= lambda {
37
+ Klout.profile('jasontorres')
38
+ }
39
+ @profile_result ||= @profile_request.call
40
+ end
41
+
42
+ it "should have a profile" do
43
+ @profile_result.should be_instance_of(Hash)
44
+ end
45
+
46
+ it "should have the required keys" do
47
+ @profile_result.has_key?('user').should == true
48
+ @profile_result['user'].has_key?('score').should == true
49
+ @profile_result['user']['score'].has_key?('slope').should == true
50
+ @profile_result['user']['score'].has_key?('kscore').should == true
51
+ @profile_result['user']['score'].has_key?('kclass').should == true
52
+ @profile_result['user']['score'].has_key?('true_reach').should == true
53
+ @profile_result['user']['score'].has_key?('amplification_score').should == true
54
+ @profile_result['user']['score'].has_key?('kscore_description').should == true
55
+ @profile_result['user']['score'].has_key?('network_score').should == true
56
+ @profile_result['user']['score'].has_key?('kclass_description').should == true
57
+ @profile_result['user']['score'].has_key?('date_updated').should == true
58
+ @profile_result['user'].has_key?('twitter_screen_name').should == true
59
+ @profile_result['user'].has_key?('status').should == true
60
+ @profile_result['user'].has_key?('twitter_id').should == true
61
+ @profile_result['user'].has_key?('status_message').should == true
62
+ end
63
+
64
+ end
65
+
66
+
67
+ end
68
+
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'klout'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kloutbg
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jason Torres
14
+ - Brad Gilreath
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-11-04 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: typhoeus
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Kloutbg - Fork of Jason Torres and updated to recent Klout API
37
+ email: bwgilreath@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - lib/klout.rb
44
+ - README
45
+ - tasks/rspec.rake
46
+ files:
47
+ - lib/klout.rb
48
+ - Manifest
49
+ - Rakefile
50
+ - README
51
+ - spec/klout_spec.rb
52
+ - spec/spec.opts
53
+ - spec/spec_helper.rb
54
+ - tasks/rspec.rake
55
+ - klout.gemspec
56
+ has_rdoc: true
57
+ homepage: https://github.com/bgilreath/klout
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --line-numbers
63
+ - --inline-source
64
+ - --title
65
+ - Klout
66
+ - --main
67
+ - README
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 11
85
+ segments:
86
+ - 1
87
+ - 2
88
+ version: "1.2"
89
+ requirements: []
90
+
91
+ rubyforge_project: klout
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Kloutbg - Twitter Analytics
96
+ test_files: []
97
+