rocky-klout 0.0.1

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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-10-16
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ init.rb
7
+ lib/rocky-klout.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+ test/test_helper.rb
12
+ test/test_rocky-klout.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+ ADRIAAAAAAAAAAN!
2
+
3
+
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = rocky-klout
2
+
3
+ * http://github.com/empika/rocky-klout
4
+
5
+ == DESCRIPTION:
6
+
7
+ Quick, easy access to the Klout.com API. Loosely based on the Klout gem by Jason Torres (http://github.com/jasontorres/klout) but using HTTParty and updating API methods.
8
+
9
+ == REQUIREMENTS:
10
+
11
+ HTTParty
12
+
13
+ == INSTALL:
14
+
15
+ sudo gem install rocky-klout
16
+
17
+ == Usage:
18
+
19
+ > rk = RockyKlout.new(your_api_key_here)
20
+ > rk.user_show("empika")
21
+ => Hash
22
+ > rk.user_show(["empika", "kibokoapp", "darthvader"])
23
+ => Hash
24
+
25
+ Available methods:
26
+
27
+ score_klout("username_or_id"), score_klout(["array" "of", "usernames", "or", "ids"])
28
+
29
+ user_show("username_or_id"), user_show(["array" "of", "usernames", "or", "ids"])
30
+ user_topics("username_or_id"), user_topics(["array" "of", "usernames", "or", "ids"])
31
+ user_stats("username_or_id"), user_stats(["array" "of", "usernames", "or", "ids"])
32
+ user_history("username_or_id", "measure", "start_date", "end_date"), user_history(["array" "of", "usernames", "or", "ids"], "measure", "start_date", "end_date")
33
+ I have no idea what some of the options for user_history are as its not very well documented. if you know, please let me know.
34
+
35
+ relationship_influenced_by("username_or_id"), relationship_influenced_by(["array" "of", "usernames", "or", "ids"])
36
+ relationship_influcencer_of("username_or_id"), relationship_influcencer_of(["array" "of", "usernames", "or", "ids"])
37
+
38
+ topic_search("topic_string")
39
+ topic_verify("topic_string")
40
+
41
+ Enjoy!
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2010 Eddy Parris
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/rocky-klout'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'rocky-klout' do
14
+ self.developer 'Eddy Parris', 'eddy@kibokoapp.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [['httparty','>= 0.6.1']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/lib/rocky-klout'
@@ -0,0 +1,84 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'httparty'
4
+ begin
5
+ require 'cgi'
6
+ end
7
+
8
+ $:.unshift(File.dirname(__FILE__)) unless
9
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
10
+
11
+ # module RockyKlout
12
+ # VERSION = '0.0.1'
13
+ # end
14
+
15
+ class RockyKlout
16
+ include HTTParty
17
+ VERSION = '0.0.1'
18
+
19
+ @@base_uri = "http://api.klout.com"
20
+ @@api_version = "1"
21
+
22
+ @@api_key = ""
23
+
24
+ def initialize(api_key)
25
+ @@api_key = api_key
26
+ end
27
+
28
+ def api_key=(api)
29
+ @@api_key = api
30
+ end
31
+
32
+ def api_key
33
+ @@api_key
34
+ end
35
+
36
+ def score_klout(usernames)
37
+ request_uri = "/#{@@api_version}/klout.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
38
+ self.class.get(@@base_uri + request_uri)
39
+ end
40
+
41
+ def user_show(usernames)
42
+ request_uri = "/#{@@api_version}/users/show.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
43
+ self.class.get(@@base_uri + request_uri)
44
+ end
45
+
46
+ def user_topics(usernames)
47
+ request_uri = "/#{@@api_version}/users/topics.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
48
+ self.class.get(@@base_uri + request_uri)
49
+ end
50
+
51
+ def user_stats(usernames)
52
+ request_uri = "/#{@@api_version}/users/stats.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
53
+ self.class.get(@@base_uri + request_uri)
54
+ end
55
+
56
+ def user_history(usernames, measure, start_date, end_date)
57
+ request_uri = "/#{@@api_version}/users/show.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",") +
58
+ "&measure=" + CGI.escape(measure) +
59
+ "&start_date=" + CGI.escape(start_date)
60
+ "&end_date=" + CGI.escape(end_date)
61
+ self.class.get(@@base_uri + request_uri)
62
+ end
63
+
64
+ def relationship_influenced_by(usernames)
65
+ request_uri = "/#{@@api_version}/soi/influenced_by.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
66
+ self.class.get(@@base_uri + request_uri)
67
+ end
68
+
69
+ def relationship_influcencer_of(usernames)
70
+ request_uri = "/#{@@api_version}/soi/influencer_of.json?key=#{@@api_key}&users=" + usernames.collect{|name| CGI.escape(name)}.join(",")
71
+ self.class.get(@@base_uri + request_uri)
72
+ end
73
+
74
+ def topic_search(topic)
75
+ request_uri = "/#{@@api_version}/topics/search.json?key=#{@@api_key}&topic=" + CGI.escape(topic)
76
+ self.class.get(@@base_uri + request_uri)
77
+ end
78
+
79
+ def topic_verify(topic)
80
+ request_uri = "/#{@@api_version}/topics/verify.json?key=#{@@api_key}&topic=" + CGI.escape(topic)
81
+ self.class.get(@@base_uri + request_uri)
82
+ end
83
+
84
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/rocky-klout.rb'}"
9
+ puts "Loading rocky-klout gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/rocky-klout'
@@ -0,0 +1,124 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestRockyKlout < Test::Unit::TestCase
4
+
5
+ def setup
6
+ usage = "Usage: ruby test_rocky-klout.rb -- [klout_api_key]"
7
+ puts "Uh oh! \n"
8
+ puts usage
9
+ unless !ARGV[0].nil?
10
+
11
+ exit
12
+ end
13
+ @api_key = ARGV[0] #"uxs4r9352tszfnau7np97zqs"
14
+ @rk = RockyKlout.new(@api_key)
15
+ @user_single = "darthvader"
16
+ @user_array = ["darthvader", "DeathStarPR"]
17
+ @measure = nil # not used yet, see test
18
+ @start_date = nil # not used yet, see test
19
+ @end_date = nil # not used yet, see test
20
+ @topic = "star wars"
21
+ end
22
+
23
+ # klout score
24
+ def test_score_klout_single
25
+ response = @rk.score_klout(@user_single)
26
+ assert_instance_of Hash, response
27
+ assert_equal response["status"], 200
28
+ end
29
+
30
+ def test_score_klout_array
31
+ response = @rk.score_klout(@user_array)
32
+ assert_instance_of Hash, response
33
+ assert_equal response["status"], 200
34
+ end
35
+
36
+ # user methods
37
+ def test_user_show_single
38
+ response = @rk.user_show(@user_single)
39
+ assert_instance_of Hash, response
40
+ assert_equal response["status"], 200
41
+ end
42
+
43
+ def test_user_show_array
44
+ response = @rk.user_show(@user_array)
45
+ assert_instance_of Hash, response
46
+ assert_equal response["status"], 200
47
+ end
48
+
49
+ def test_user_topics_single
50
+ response = @rk.user_topics(@user_single)
51
+ assert_instance_of Hash, response
52
+ assert_equal response["status"], 200
53
+ end
54
+
55
+ def test_user_topics_array
56
+ response = @rk.user_topics(@user_array)
57
+ assert_instance_of Hash, response
58
+ assert_equal response["status"], 200
59
+ end
60
+
61
+ def test_user_stats_single
62
+ response = @rk.user_stats(@user_single)
63
+ assert_instance_of Hash, response
64
+ assert_equal response["status"], 200
65
+ end
66
+
67
+ def test_user_stats_array
68
+ response = @rk.user_stats(@user_array)
69
+ assert_instance_of Hash, response
70
+ assert_equal response["status"], 200
71
+ end
72
+
73
+ # skip these because we have no way of knowing what the arguments are
74
+ # def test_user_history_single
75
+ # response = @rk.user_history(@user_single, @measure, @start_date, @end_date)
76
+ # assert_instance_of Hash, response
77
+ # assert_equal response["status"], 200
78
+ # end
79
+ #
80
+ # def test_user_history_array
81
+ # response = @rk.user_history(@user_array, @measure, @start_date, @end_date)
82
+ # assert_instance_of Hash, response
83
+ # assert_equal response["status"], 200
84
+ # end
85
+
86
+ # relationship methods
87
+ def test_relationship_influenced_by_single
88
+ response = @rk.relationship_influenced_by(@user_single)
89
+ assert_instance_of Hash, response
90
+ assert_equal response["status"], 200
91
+ end
92
+
93
+ def test_relationship_influenced_by_array
94
+ response = @rk.relationship_influenced_by(@user_array)
95
+ assert_instance_of Hash, response
96
+ assert_equal response["status"], 200
97
+ end
98
+
99
+ def test_relationship_influcencer_of_single
100
+ response = @rk.relationship_influenced_by(@user_single)
101
+ assert_instance_of Hash, response
102
+ assert_equal response["status"], 200
103
+ end
104
+
105
+ def test_relationship_influcencer_of_array
106
+ response = @rk.relationship_influenced_by(@user_array)
107
+ assert_instance_of Hash, response
108
+ assert_equal response["status"], 200
109
+ end
110
+
111
+
112
+ # topic methods
113
+ def test_topic_search_single
114
+ response = @rk.topic_search(@topic)
115
+ assert_instance_of Hash, response
116
+ assert_equal response["status"], 200
117
+ end
118
+
119
+ def test_topic_verify_array
120
+ response = @rk.topic_verify(@topic)
121
+ assert_instance_of Hash, response
122
+ assert_equal response["status"], 200
123
+ end
124
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rocky-klout
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Eddy Parris
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-19 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubyforge
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 4
50
+ version: 2.0.4
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: hoe
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 2
64
+ - 6
65
+ - 2
66
+ version: 2.6.2
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Quick, easy access to the Klout.com API. Loosely based on the Klout gem by Jason Torres (http://github.com/jasontorres/klout) but using HTTParty and updating API methods.
70
+ email:
71
+ - eddy@kibokoapp.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - History.txt
78
+ - Manifest.txt
79
+ - PostInstall.txt
80
+ files:
81
+ - History.txt
82
+ - Manifest.txt
83
+ - PostInstall.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - init.rb
87
+ - lib/rocky-klout.rb
88
+ - script/console
89
+ - script/destroy
90
+ - script/generate
91
+ - test/test_helper.rb
92
+ - test/test_rocky-klout.rb
93
+ has_rdoc: true
94
+ homepage: http://github.com/empika/rocky-klout
95
+ licenses: []
96
+
97
+ post_install_message: PostInstall.txt
98
+ rdoc_options:
99
+ - --main
100
+ - README.rdoc
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: rocky-klout
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Quick, easy access to the Klout.com API
128
+ test_files:
129
+ - test/test_helper.rb
130
+ - test/test_rocky-klout.rb