klout_stable 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccc95acc76595fc9038b4e24eb66ab00f96b7cb2
4
+ data.tar.gz: 0caf80a9c0be980e23864dd22e2cf361df2155bb
5
+ SHA512:
6
+ metadata.gz: 2865ca656328816b5763253909d02f83f7981dea4df5d30144fc52591b118945440f2d3923ac01139e4e1435c8bd8fd375db06536d44d894f293fb06a7992353
7
+ data.tar.gz: 1974f8a17bf2b0b580c227d6f904a9574b99bbf560e78ac35ba1a9ac85dd71568c17060354065c2213bbb77e4cb2372e6d5659f81e1dd85268d9d6693c8305ea
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'hashie'
4
+ gem 'httparty'
5
+ gem 'json'
6
+
7
+ group :development, :test do
8
+ gem 'fakeweb', '>= 1.3.0'
9
+ gem 'guard-rspec', '>= 0.7.0'
10
+ gem 'rspec', '>= 2.9.0'
11
+ end
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "bundler/version"
3
+ require "rake/testtask"
4
+ require "./lib/klout_stable"
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ end
16
+
17
+ task :default => :spec
18
+
19
+ desc "Build the gem"
20
+ task :build do
21
+ system "gem build klout_stable.gemspec"
22
+ end
23
+
24
+ desc "Build and release the gem"
25
+ task :release => :build do
26
+ system "gem push klout_stable-#{KloutAPI::VERSION}.gem"
27
+ end
28
+
29
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ require 'bundler'
2
+ require 'bundler/version'
3
+
4
+ require File.expand_path('lib/klout/version')
5
+
6
+ Gem::Specification.new do |s|
7
+ s.add_runtime_dependency('hashie','2.1.2')
8
+ s.add_runtime_dependency('httparty','0.13.1')
9
+ s.add_runtime_dependency('json','1.8.1')
10
+ s.add_development_dependency('fakeweb','1.3.0')
11
+ s.add_development_dependency('guard-rspec','4.2.10')
12
+ s.add_development_dependency('rspec','3.0.0')
13
+ s.name = "klout_stable"
14
+ s.authors = ["Marcus Yearwood"]
15
+ s.description = %q{Implements the complete functionality of the Klout REST API (v2+) and uses versioned dependencies. }
16
+ s.email = ["m.yearwood@live.com"]
17
+ s.homepage = "http://github.com/myearwood/klout_stable"
18
+ s.licenses = ["MIT"]
19
+ s.files = `git ls-files`.split("\n")
20
+ s.require_paths = ["lib"]
21
+ s.summary = %q{ All the existing Klout gems are broken becuase of an update to a dependency that was not backwards compatible.
22
+ This gem uses versioned dependencies to provide a working, stable Klout API }
23
+ s.version = '3.0.2'
24
+ s.platform = Gem::Platform::RUBY
25
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'klout_stable'
2
+ require 'json'
3
+
4
+ module KloutAPI
5
+ # Represents an identity
6
+ class Identity
7
+ class << self
8
+ def find_by_twitter_id(twitter_id)
9
+ response = KloutAPI.get "/identity.json/tw/#{twitter_id}", :query => {:key => KloutAPI.api_key}
10
+ Hashie::Mash.new(response)
11
+ end
12
+
13
+ def find_by_screen_name(screen_name)
14
+ response = KloutAPI.get "/identity.json/twitter", :query => {:key => KloutAPI.api_key, :screenName => screen_name}
15
+ Hashie::Mash.new(response)
16
+ end
17
+
18
+ def find_by_klout_id(klout_id)
19
+ response = KloutAPI.get "/identity.json/klout/#{klout_id}/tw", :query => {:key => KloutAPI.api_key}
20
+ Hashie::Mash.new(response)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'klout_stable'
2
+ require 'json'
3
+
4
+ module KloutAPI
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
+ KloutAPI.get uri_for(action), :query => {:key => KloutAPI.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
@@ -0,0 +1,3 @@
1
+ module KloutAPI
2
+ VERSION = "3.0.1" unless defined?(KloutAPI::VERSION)
3
+ end
@@ -0,0 +1,97 @@
1
+ require 'cgi'
2
+ require 'uri'
3
+ require 'httparty'
4
+ require 'hashie'
5
+ Hash.send :include, Hashie::HashExtensions
6
+
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 KloutAPI
15
+ class << self
16
+ # Allow Klout.api_key = "..."
17
+ def api_key=(api_key)
18
+ KloutAPI.api_key = api_key
19
+ end
20
+
21
+ def base_uri=(uri)
22
+ KloutAPI.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(KloutAPI.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 KloutAPIError < 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 < KloutAPIError; end
44
+ class Unauthorized < StandardError; end
45
+ class NotFound < ClientError; end
46
+ class Unavailable < StandardError; end
47
+
48
+ class KloutAPI
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
97
+
@@ -0,0 +1 @@
1
+ require 'klout_stable'
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "54887627490056592",
3
+ "network": "ks"
4
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "myInfluencers" : [
3
+ {
4
+ "entity" : {
5
+ "id" : "851563",
6
+ "payload" : {
7
+ "kloutId" : "851563",
8
+ "score" : {
9
+ "score" : 100.0
10
+ },
11
+ "topics" : [
12
+ {
13
+ "topicData" : {
14
+ "id" : "8655841127676549162",
15
+ "displayName" : "Social Media",
16
+ "name" : "social media",
17
+ "slug" : "social-media",
18
+ "imageUrl" : "http://kcdn3.klout.com/static/images/topics/social-media2.png"
19
+ },
20
+ "score" : 90.0,
21
+ "strength" : "strong",
22
+ "seconds" : 7736654
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ }
28
+ ],
29
+ "myInfluencees" : [
30
+ {
31
+ "entity" : {
32
+ "id" : "54606150835198872",
33
+ "payload" : {
34
+ "kloutId" : "54606150835198872",
35
+ "score" : {
36
+ "score" : 14.543242454528809
37
+ },
38
+ "topics" : []
39
+ }
40
+ }
41
+ }
42
+ ],
43
+ "myInfluencersCount" : 15,
44
+ "myInfluenceesCount" : 138166
45
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "score": 18.162389755249023,
3
+ "scoreDelta": {
4
+ "dayChange": -0.09396934509277344,
5
+ "weekChange": -0.5575828552246094,
6
+ "monthChange": -0.7959918975830078
7
+ }
8
+ }
@@ -0,0 +1,37 @@
1
+ [
2
+ {
3
+ "id": "9050521595422321114",
4
+ "displayName": "Email Marketing",
5
+ "name": "email marketing",
6
+ "slug": "email-marketing",
7
+ "imageUrl": "http://kcdn3.klout.com/static/images/icons/generic-topic.png"
8
+ },
9
+ {
10
+ "id": "8450884106658763087",
11
+ "displayName": "Law",
12
+ "name": "law",
13
+ "slug": "law",
14
+ "imageUrl": "http://kcdn3.klout.com/static/images/topics/law_a883efae09bbe8bea4677d217d18fa85.png"
15
+ },
16
+ {
17
+ "id": "9219221220892053994",
18
+ "displayName": "Ruby",
19
+ "name": "ruby",
20
+ "slug": "ruby",
21
+ "imageUrl": "http://kcdn3.klout.com/static/images/topics/ruby_2f7531a7ddf45d64367d533f8674c714.png"
22
+ },
23
+ {
24
+ "id": "6843285985518810775",
25
+ "displayName": "Ruby on Rails",
26
+ "name": "ruby on rails",
27
+ "slug": "ruby-on-rails",
28
+ "imageUrl": "http://kcdn3.klout.com/static/images/topics/ruby on rails_3efb002572bbce5be4c27932ca05e52a.png"
29
+ },
30
+ {
31
+ "id": "7815",
32
+ "displayName": "Manhattan",
33
+ "name": "manhattan",
34
+ "slug": "manhattan",
35
+ "imageUrl": "http://kcdn3.klout.com/static/images/icons/generic-topic.png"
36
+ }
37
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "kloutId": "635263",
3
+ "score": {
4
+ "score": 76.60027313232422
5
+ }
6
+ }
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ module KloutAPI
4
+ describe Identity do
5
+ # TODO: test each method
6
+ end
7
+
8
+ describe User do
9
+ # TODO: test each method
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'fakeweb'
2
+ require 'klout_stable'
3
+
4
+ FakeWeb.allow_net_connect = false
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+ FakeWeb.clean_registry
9
+ KloutAPI.api_key = '13adsf2dsf67adsf824aadfdsf12'
10
+ @klout_id = 635263
11
+ end
12
+ end
data/test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "klout_stable"
2
+
3
+ def get_klout_keyword(username)
4
+ Klout.api_key = '3te54g7vcg82d47wg7whcje8'
5
+ klout_id = Klout::Identity.find_by_screen_name(username)
6
+ user = Klout::User.new(klout_id[:id])
7
+ topics = user.topics
8
+ if !topics.empty?
9
+ return topics[0]["name"]
10
+ else
11
+ return topics
12
+ end
13
+
14
+ end
15
+
16
+ puts get_klout_keyword("forbes")
17
+
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: klout_stable
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Yearwood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 4.2.10
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.10
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ description: 'Implements the complete functionality of the Klout REST API (v2+) and
98
+ uses versioned dependencies. '
99
+ email:
100
+ - m.yearwood@live.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - Gemfile
106
+ - Rakefile
107
+ - klout_stable.gemspec
108
+ - lib/klout/identity.rb
109
+ - lib/klout/user.rb
110
+ - lib/klout/version.rb
111
+ - lib/klout_stable.rb
112
+ - rails/init.rb
113
+ - spec/klout/fixtures/identity.json
114
+ - spec/klout/fixtures/influence.json
115
+ - spec/klout/fixtures/score.json
116
+ - spec/klout/fixtures/topics.json
117
+ - spec/klout/fixtures/user.json
118
+ - spec/klout/klout_spec.rb
119
+ - spec/spec_helper.rb
120
+ - test.rb
121
+ homepage: http://github.com/myearwood/klout_stable
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.6
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.2.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: All the existing Klout gems are broken becuase of an update to a dependency
145
+ that was not backwards compatible. This gem uses versioned dependencies to provide
146
+ a working, stable Klout API
147
+ test_files: []