klout 2.0.0 → 3.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.
- data/.gitignore +55 -0
- data/Gemfile +2 -4
- data/README.rdoc +14 -21
- data/Rakefile +14 -34
- data/klout.gemspec +21 -69
- data/lib/klout.rb +94 -2
- data/lib/klout/identity.rb +24 -0
- data/lib/klout/user.rb +44 -0
- data/lib/klout/version.rb +3 -0
- data/rails/init.rb +1 -0
- data/spec/klout/klout_spec.rb +6 -50
- data/spec/spec_helper.rb +1 -1
- metadata +45 -58
- data/VERSION +0 -1
- data/lib/klout/api.rb +0 -69
data/.gitignore
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# RVM generated
|
18
|
+
.rvmrc
|
19
|
+
|
20
|
+
*.gem
|
21
|
+
Gemfile.lock
|
22
|
+
.document
|
23
|
+
|
24
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
25
|
+
#
|
26
|
+
# * Create a file at ~/.gitignore
|
27
|
+
# * Include files you want ignored
|
28
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
29
|
+
#
|
30
|
+
# After doing this, these files will be ignored in all your git projects,
|
31
|
+
# saving you from having to 'pollute' every project you touch with them
|
32
|
+
#
|
33
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
34
|
+
#
|
35
|
+
# For MacOS:
|
36
|
+
#
|
37
|
+
.DS_Store
|
38
|
+
|
39
|
+
# For TextMate
|
40
|
+
*.tmproj
|
41
|
+
tmtags
|
42
|
+
|
43
|
+
# For emacs:
|
44
|
+
#*~
|
45
|
+
#\#*
|
46
|
+
#.\#*
|
47
|
+
|
48
|
+
# For vim:
|
49
|
+
#*.swp
|
50
|
+
|
51
|
+
# For redcar:
|
52
|
+
#.redcar
|
53
|
+
|
54
|
+
# For rubinius:
|
55
|
+
#*.rbc
|
data/Gemfile
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
+
gem 'hashie'
|
3
4
|
gem 'httparty'
|
4
5
|
gem 'json'
|
5
6
|
|
6
|
-
group :development do
|
7
|
-
gem 'bundler', '> 1.0.0'
|
7
|
+
group :development, :test do
|
8
8
|
gem 'fakeweb', '~> 1.3.0'
|
9
9
|
gem 'guard-rspec', '~> 0.7.0'
|
10
|
-
gem 'jeweler', '~> 1.8.3'
|
11
|
-
gem 'simplecov', '~> 0.6.1'
|
12
10
|
gem 'rspec', '~> 2.9.0'
|
13
11
|
end
|
data/README.rdoc
CHANGED
@@ -15,24 +15,15 @@ You will need a {Klout API Key}[http://developer.klout.com/member/register] in o
|
|
15
15
|
Please refer to the {Klout API Documentation}[http://klout.com/s/developers/v2] for more information about the API, or follow the examples below:
|
16
16
|
|
17
17
|
require 'klout'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
k.identity(12345678)
|
28
|
-
k.identity('screen_name', :ks) # Query a different network.
|
29
|
-
|
30
|
-
Once you have a +klout_id+ for someone, you can access their Klout score, influence and topics:
|
31
|
-
|
32
|
-
k.users klout_id
|
33
|
-
k.users klout_id, :score
|
34
|
-
k.users klout_id, :influence
|
35
|
-
k.users klout_id, :topics
|
18
|
+
Klout.api_key = ENV['KLOUT_API_KEY']
|
19
|
+
klout_id = Klout::Identity.find_by_screen_name('screen_name')
|
20
|
+
|
21
|
+
user = Klout::Identity.new(klout_id)
|
22
|
+
user.details
|
23
|
+
user.score
|
24
|
+
user.score.scoreDelta.dayChange
|
25
|
+
user.topics
|
26
|
+
user.influence
|
36
27
|
|
37
28
|
And that's it!
|
38
29
|
|
@@ -42,10 +33,12 @@ The {Klout API Documentation}[http://klout.com/s/developers/v2] has great inform
|
|
42
33
|
|
43
34
|
== Errors
|
44
35
|
|
45
|
-
|
36
|
+
Errors are based on the HTTP response of the request, so that you can rescue accordingly:
|
46
37
|
|
47
|
-
rescue Klout::
|
48
|
-
|
38
|
+
rescue Klout::ClientError > req
|
39
|
+
rescue Klout::BadRequest > req
|
40
|
+
rescue Klout::NotFound > req
|
41
|
+
rescue Klout::Unauthorized > req
|
49
42
|
|
50
43
|
== Contributing to Klout
|
51
44
|
|
data/Rakefile
CHANGED
@@ -1,32 +1,10 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "klout"
|
18
|
-
gem.homepage = "http://github.com/terra-firma/klout"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{A Ruby gem for interacting with the Klout API.}
|
21
|
-
gem.description = %Q{Klout is a Ruby gem for interacting with the Klout API.}
|
22
|
-
gem.email = "brian@terra-firma-design.com"
|
23
|
-
gem.authors = ["Brian Getting"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require "bundler/version"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "./lib/klout"
|
28
5
|
require 'rspec/core'
|
29
6
|
require 'rspec/core/rake_task'
|
7
|
+
|
30
8
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
9
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
10
|
end
|
@@ -38,12 +16,14 @@ end
|
|
38
16
|
|
39
17
|
task :default => :spec
|
40
18
|
|
41
|
-
|
42
|
-
|
43
|
-
|
19
|
+
desc "Build the gem"
|
20
|
+
task :build do
|
21
|
+
system "gem build klout.gemspec"
|
22
|
+
end
|
44
23
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
desc "Build and release the gem"
|
25
|
+
task :release => :build do
|
26
|
+
system "gem push klout-#{Klout::VERSION}.gem"
|
49
27
|
end
|
28
|
+
|
29
|
+
task :default => :test
|
data/klout.gemspec
CHANGED
@@ -1,76 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'bundler'
|
2
|
+
require 'bundler/version'
|
3
|
+
|
4
|
+
require File.expand_path('lib/klout/version')
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
+
s.add_runtime_dependency('hashie')
|
8
|
+
s.add_runtime_dependency('httparty')
|
9
|
+
s.add_runtime_dependency('json')
|
10
|
+
s.add_development_dependency('fakeweb')
|
11
|
+
s.add_development_dependency('guard-rspec')
|
12
|
+
s.add_development_dependency('rspec')
|
7
13
|
s.name = "klout"
|
8
|
-
s.version = "2.0.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
14
|
s.authors = ["Brian Getting"]
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".rspec",
|
20
|
-
".travis.yml",
|
21
|
-
"Gemfile",
|
22
|
-
"Guardfile",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"klout.gemspec",
|
27
|
-
"lib/klout.rb",
|
28
|
-
"lib/klout/api.rb",
|
29
|
-
"spec/klout/fixtures/identity.json",
|
30
|
-
"spec/klout/fixtures/influence.json",
|
31
|
-
"spec/klout/fixtures/score.json",
|
32
|
-
"spec/klout/fixtures/topics.json",
|
33
|
-
"spec/klout/fixtures/user.json",
|
34
|
-
"spec/klout/klout_spec.rb",
|
35
|
-
"spec/spec_helper.rb"
|
36
|
-
]
|
15
|
+
s.description = %q{Implements the complete functionality of the Klout REST API (v2+).}
|
16
|
+
s.email = ["brian@tatem.ae"]
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
18
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
19
|
+
s.files = `git ls-files`.split("\n")
|
37
20
|
s.homepage = "http://github.com/terra-firma/klout"
|
38
21
|
s.licenses = ["MIT"]
|
39
22
|
s.require_paths = ["lib"]
|
40
|
-
s.
|
41
|
-
s.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
48
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
49
|
-
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
50
|
-
s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
51
|
-
s.add_development_dependency(%q<guard-rspec>, ["~> 0.7.0"])
|
52
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
53
|
-
s.add_development_dependency(%q<simplecov>, ["~> 0.6.1"])
|
54
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.9.0"])
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<httparty>, [">= 0"])
|
57
|
-
s.add_dependency(%q<json>, [">= 0"])
|
58
|
-
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
59
|
-
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
60
|
-
s.add_dependency(%q<guard-rspec>, ["~> 0.7.0"])
|
61
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
62
|
-
s.add_dependency(%q<simplecov>, ["~> 0.6.1"])
|
63
|
-
s.add_dependency(%q<rspec>, ["~> 2.9.0"])
|
64
|
-
end
|
65
|
-
else
|
66
|
-
s.add_dependency(%q<httparty>, [">= 0"])
|
67
|
-
s.add_dependency(%q<json>, [">= 0"])
|
68
|
-
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
69
|
-
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
|
70
|
-
s.add_dependency(%q<guard-rspec>, ["~> 0.7.0"])
|
71
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
72
|
-
s.add_dependency(%q<simplecov>, ["~> 0.6.1"])
|
73
|
-
s.add_dependency(%q<rspec>, ["~> 2.9.0"])
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
23
|
+
s.summary = %q{A library which implements the complete functionality of of the Klout REST API (v2+).}
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.version = Klout::VERSION
|
26
|
+
s.platform = Gem::Platform::RUBY
|
27
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
28
|
+
end
|
data/lib/klout.rb
CHANGED
@@ -1,4 +1,96 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'uri'
|
1
3
|
require 'httparty'
|
2
|
-
require '
|
4
|
+
require 'hashie'
|
5
|
+
Hash.send :include, Hashie::HashExtensions
|
3
6
|
|
4
|
-
|
7
|
+
libdir = File.dirname(__FILE__)
|
8
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
9
|
+
|
10
|
+
require 'klout/version'
|
11
|
+
require 'klout/identity'
|
12
|
+
require 'klout/user'
|
13
|
+
|
14
|
+
module Klout
|
15
|
+
class << self
|
16
|
+
# Allow Klout.api_key = "..."
|
17
|
+
def api_key=(api_key)
|
18
|
+
Klout.api_key = api_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_uri=(uri)
|
22
|
+
Klout.base_uri uri
|
23
|
+
end
|
24
|
+
|
25
|
+
# Allows the initializer to turn off actually communicating to the REST service for certain environments
|
26
|
+
# Requires fakeweb gem to be installed
|
27
|
+
def disable
|
28
|
+
FakeWeb.register_uri(:any, %r|#{Regexp.escape(Klout.base_uri)}|, :body => '{"Disabled":true}', :content_type => 'application/json; charset=utf-8')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Represents a Klout API error and contains specific data about the error.
|
33
|
+
class KloutError < StandardError
|
34
|
+
attr_reader :data
|
35
|
+
def initialize(data)
|
36
|
+
@data = Hashie::Mash.new(data)
|
37
|
+
super "The Klout API responded with the following error - #{data}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class ClientError < StandardError; end
|
42
|
+
class ServerError < StandardError; end
|
43
|
+
class BadRequest < KloutError; end
|
44
|
+
class Unauthorized < StandardError; end
|
45
|
+
class NotFound < ClientError; end
|
46
|
+
class Unavailable < StandardError; end
|
47
|
+
|
48
|
+
class Klout
|
49
|
+
include HTTParty
|
50
|
+
|
51
|
+
@@base_uri = "http://api.klout.com/v2/"
|
52
|
+
@@api_key = ""
|
53
|
+
headers({
|
54
|
+
'User-Agent' => "klout-rest-#{VERSION}",
|
55
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
56
|
+
'Accept-Encoding' => 'gzip, deflate'
|
57
|
+
})
|
58
|
+
base_uri @@base_uri
|
59
|
+
|
60
|
+
class << self
|
61
|
+
# Get the API key
|
62
|
+
def api_key; @@api_key end
|
63
|
+
|
64
|
+
# Set the API key
|
65
|
+
def api_key=(api_key)
|
66
|
+
return @@api_key unless api_key
|
67
|
+
@@api_key = api_key
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get the Base URI.
|
71
|
+
def base_uri; @@base_uri end
|
72
|
+
|
73
|
+
def get(*args); handle_response super end
|
74
|
+
def post(*args); handle_response super end
|
75
|
+
def put(*args); handle_response super end
|
76
|
+
def delete(*args); handle_response super end
|
77
|
+
|
78
|
+
def handle_response(response) # :nodoc:
|
79
|
+
case response.code
|
80
|
+
when 400
|
81
|
+
raise BadRequest.new response.parsed_response
|
82
|
+
when 401
|
83
|
+
raise Unauthorized.new
|
84
|
+
when 404
|
85
|
+
raise NotFound.new
|
86
|
+
when 400...500
|
87
|
+
raise ClientError.new response.parsed_response
|
88
|
+
when 500...600
|
89
|
+
raise ServerError.new
|
90
|
+
else
|
91
|
+
response
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'klout'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Klout
|
5
|
+
# Represents an identity
|
6
|
+
class Identity
|
7
|
+
class << self
|
8
|
+
def find_by_twitter_id(twitter_id)
|
9
|
+
response = Klout.get "/identity.json/tw/#{twitter_id}", :query => {key: Klout.api_key}
|
10
|
+
Hashie::Mash.new(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by_screen_name(screen_name)
|
14
|
+
response = Klout.get "/identity.json/twitter", :query => {key: Klout.api_key, screenName: screen_name}
|
15
|
+
Hashie::Mash.new(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_klout_id(klout_id)
|
19
|
+
response = Klout.get "/identity.json/klout/#{klout_id}/tw", :query => {key: Klout.api_key}
|
20
|
+
Hashie::Mash.new(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/klout/user.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'klout'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Klout
|
5
|
+
# Represents a user
|
6
|
+
class User
|
7
|
+
attr_reader :klout_id
|
8
|
+
|
9
|
+
def initialize(klout_id)
|
10
|
+
@klout_id = klout_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def details
|
14
|
+
response = get
|
15
|
+
Hashie::Mash.new(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def score
|
19
|
+
response = get "score"
|
20
|
+
Hashie::Mash.new(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def topics
|
24
|
+
response = get "topics"
|
25
|
+
response.parsed_response
|
26
|
+
end
|
27
|
+
|
28
|
+
def influence
|
29
|
+
response = get "influence"
|
30
|
+
Hashie::Mash.new(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def get(action = nil)
|
36
|
+
Klout.get uri_for(action), :query => {key: Klout.api_key}
|
37
|
+
end
|
38
|
+
|
39
|
+
def uri_for(action = nil)
|
40
|
+
action = "/#{action}" if action
|
41
|
+
"/user.json/#{klout_id}#{action}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'klout'
|
data/spec/klout/klout_spec.rb
CHANGED
@@ -1,55 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Klout
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "calling the API" do
|
14
|
-
before(:each) do
|
15
|
-
@k = Klout::API.new(@api_key)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "for a klout_id" do
|
19
|
-
it "should accept a Twitter ID" do
|
20
|
-
user_id = 500042487
|
21
|
-
FakeWeb.register_uri(:get, "#{API_URL}identity.json/tw/#{user_id}?key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/identity.json')))
|
22
|
-
@k.identity(user_id)['id'].should eq('54887627490056592')
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should accept a Twitter screen name" do
|
26
|
-
screen_name = 'dhh'
|
27
|
-
FakeWeb.register_uri(:get, "#{API_URL}identity.json/twitter?screenName=#{screen_name}&key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/identity.json')))
|
28
|
-
@k.identity(screen_name)['id'].should eq('54887627490056592')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "for user" do
|
33
|
-
it "should return profile information" do
|
34
|
-
FakeWeb.register_uri(:get, "#{API_URL}user.json/#{@klout_id}?key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/user.json')))
|
35
|
-
@k.user(@klout_id)['kloutId'].to_i.should eq(@klout_id)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should return score data" do
|
39
|
-
FakeWeb.register_uri(:get, "#{API_URL}user.json/#{@klout_id}/score?key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/score.json')))
|
40
|
-
@k.user(@klout_id, :score)['score'].should eq(18.162389755249023)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return influence data" do
|
44
|
-
FakeWeb.register_uri(:get, "#{API_URL}user.json/#{@klout_id}/influence?key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/influence.json')))
|
45
|
-
@k.user(@klout_id, :influence)['myInfluencersCount'].to_i.should eq(15)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return topics data" do
|
49
|
-
FakeWeb.register_uri(:get, "#{API_URL}user.json/#{@klout_id}/topics?key=#{@api_key}", :body => File.read(File.expand_path('spec/klout/fixtures/topics.json')))
|
50
|
-
@k.user(@klout_id, :topics).size.should eq(5)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
4
|
+
describe Identity do
|
5
|
+
# TODO: test each method
|
6
|
+
end
|
7
|
+
|
8
|
+
describe User do
|
9
|
+
# TODO: test each method
|
54
10
|
end
|
55
11
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: hashie
|
16
|
+
requirement: &70312729874460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70312729874460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: httparty
|
27
|
+
requirement: &70312729872100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,90 +32,72 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70312729872100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: json
|
38
|
+
requirement: &70312729870320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- - ! '
|
41
|
+
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
type: :
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70312729870320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakeweb
|
49
|
-
requirement: &
|
49
|
+
requirement: &70312730459220 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70312730459220
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-rspec
|
60
|
-
requirement: &
|
61
|
-
none: false
|
62
|
-
requirements:
|
63
|
-
- - ~>
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: 0.7.0
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *70240588715040
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: jeweler
|
71
|
-
requirement: &70240588714220 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.8.3
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: *70240588714220
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: simplecov
|
82
|
-
requirement: &70240588707800 !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70312730458800 !ruby/object:Gem::Requirement
|
83
61
|
none: false
|
84
62
|
requirements:
|
85
|
-
- -
|
63
|
+
- - ! '>='
|
86
64
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0
|
65
|
+
version: '0'
|
88
66
|
type: :development
|
89
67
|
prerelease: false
|
90
|
-
version_requirements: *
|
68
|
+
version_requirements: *70312730458800
|
91
69
|
- !ruby/object:Gem::Dependency
|
92
70
|
name: rspec
|
93
|
-
requirement: &
|
71
|
+
requirement: &70312730458380 !ruby/object:Gem::Requirement
|
94
72
|
none: false
|
95
73
|
requirements:
|
96
|
-
- -
|
74
|
+
- - ! '>='
|
97
75
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
76
|
+
version: '0'
|
99
77
|
type: :development
|
100
78
|
prerelease: false
|
101
|
-
version_requirements: *
|
102
|
-
description:
|
103
|
-
email:
|
79
|
+
version_requirements: *70312730458380
|
80
|
+
description: Implements the complete functionality of the Klout REST API (v2+).
|
81
|
+
email:
|
82
|
+
- brian@tatem.ae
|
104
83
|
executables: []
|
105
84
|
extensions: []
|
106
85
|
extra_rdoc_files:
|
107
86
|
- README.rdoc
|
108
87
|
files:
|
88
|
+
- .gitignore
|
109
89
|
- .rspec
|
110
90
|
- .travis.yml
|
111
91
|
- Gemfile
|
112
92
|
- Guardfile
|
113
93
|
- README.rdoc
|
114
94
|
- Rakefile
|
115
|
-
- VERSION
|
116
95
|
- klout.gemspec
|
117
96
|
- lib/klout.rb
|
118
|
-
- lib/klout/
|
97
|
+
- lib/klout/identity.rb
|
98
|
+
- lib/klout/user.rb
|
99
|
+
- lib/klout/version.rb
|
100
|
+
- rails/init.rb
|
119
101
|
- spec/klout/fixtures/identity.json
|
120
102
|
- spec/klout/fixtures/influence.json
|
121
103
|
- spec/klout/fixtures/score.json
|
@@ -136,19 +118,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
118
|
- - ! '>='
|
137
119
|
- !ruby/object:Gem::Version
|
138
120
|
version: '0'
|
139
|
-
segments:
|
140
|
-
- 0
|
141
|
-
hash: 1810060536700847596
|
142
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
122
|
none: false
|
144
123
|
requirements:
|
145
124
|
- - ! '>='
|
146
125
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
126
|
+
version: 1.3.6
|
148
127
|
requirements: []
|
149
128
|
rubyforge_project:
|
150
129
|
rubygems_version: 1.8.10
|
151
130
|
signing_key:
|
152
131
|
specification_version: 3
|
153
|
-
summary: A
|
154
|
-
|
132
|
+
summary: A library which implements the complete functionality of of the Klout REST
|
133
|
+
API (v2+).
|
134
|
+
test_files:
|
135
|
+
- spec/klout/fixtures/identity.json
|
136
|
+
- spec/klout/fixtures/influence.json
|
137
|
+
- spec/klout/fixtures/score.json
|
138
|
+
- spec/klout/fixtures/topics.json
|
139
|
+
- spec/klout/fixtures/user.json
|
140
|
+
- spec/klout/klout_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0
|
data/lib/klout/api.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Klout
|
2
|
-
class API
|
3
|
-
include HTTParty
|
4
|
-
format :plain
|
5
|
-
default_timeout 30
|
6
|
-
|
7
|
-
attr_accessor :api_key, :timeout
|
8
|
-
|
9
|
-
# == Usage
|
10
|
-
#
|
11
|
-
# Initialize with your Klout API key:
|
12
|
-
#
|
13
|
-
# k = Klout::API.new('api-key')
|
14
|
-
#
|
15
|
-
# Or you can set the +ENV['KLOUT_API_KEY']+ environment variable:
|
16
|
-
#
|
17
|
-
# k = Klout::API.new
|
18
|
-
#
|
19
|
-
def initialize(api_key = nil)
|
20
|
-
@api_key = api_key || ENV['KLOUT_API_KEY'] || raise(ArgumentError)
|
21
|
-
end
|
22
|
-
|
23
|
-
def base_api_url # :nodoc:
|
24
|
-
"http://api.klout.com/v2"
|
25
|
-
end
|
26
|
-
|
27
|
-
# === Identity
|
28
|
-
#
|
29
|
-
# Use the +identity+ method to get a user's +klout_id+.
|
30
|
-
# Pass either a numerical Twitter ID (Integer) or a Twitter screen name (String)
|
31
|
-
#
|
32
|
-
# k.identity(500042487)
|
33
|
-
# k.identity('dhh')
|
34
|
-
#
|
35
|
-
# You can also select a different network:
|
36
|
-
#
|
37
|
-
# k.identity('dhh', :ks)
|
38
|
-
#
|
39
|
-
def identity(id, network = :tw)
|
40
|
-
path = id.is_a?(Integer) ? "#{network}/#{id}?key=#{@api_key}" : "twitter?screenName=#{id}&key=#{@api_key}"
|
41
|
-
call("/identity.json/#{path}")
|
42
|
-
end
|
43
|
-
|
44
|
-
# === User
|
45
|
-
#
|
46
|
-
# Use the +user+ method to get information about a user. Pass in a trait
|
47
|
-
# option to get score, influence and topics data:
|
48
|
-
#
|
49
|
-
# k.user(635263)
|
50
|
-
# k.user(635263, :influence)
|
51
|
-
# k.user(635263, :score)
|
52
|
-
# k.user(635263, :topics)
|
53
|
-
#
|
54
|
-
def user(id, trait = nil)
|
55
|
-
lookup = trait.nil? ? '' : "/#{trait.to_s}"
|
56
|
-
call("/user.json/#{id}#{lookup}?key=#{@api_key}")
|
57
|
-
end
|
58
|
-
|
59
|
-
protected
|
60
|
-
|
61
|
-
def call(endpoint) # :nodoc:
|
62
|
-
response = self.class.get(base_api_url + endpoint)
|
63
|
-
response.code.to_i == 200 ? JSON.parse(response.body) : raise(API::Error.new("HTTP Response Code: #{response.code}"))
|
64
|
-
end
|
65
|
-
|
66
|
-
class Error < StandardError
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|