thinkcreate-reputation 0.1.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.
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'reputation'
4
+
5
+ Reputation.run(ARGV)
@@ -0,0 +1,58 @@
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir)
3
+
4
+ require 'services/base'
5
+ Dir[libdir+'/services/**/*.rb'].each{|s| require s}
6
+
7
+ module Reputation
8
+ extend self
9
+
10
+ def self.run(args = ARGV)
11
+ unless ARGV.size == 2
12
+ puts(usage)
13
+ exit
14
+ end
15
+
16
+ service_name = args.first
17
+ account = args.last
18
+
19
+ begin
20
+ @service = Service.class_for(service_name).new(account)
21
+ rescue NameError
22
+ puts "Err: No service named '#{service_name}' found!"
23
+ puts usage
24
+ exit
25
+ end
26
+
27
+ puts(<<-RESULT.trim)
28
+ Account '#{account}' on #{@service}
29
+
30
+ #{@service.render_items}
31
+
32
+ RESULT
33
+ end
34
+
35
+ def self.usage()<<-USAGE.trim
36
+ Usage:
37
+ #{$0} <service> <account-name>
38
+
39
+ Supported services:
40
+ - github
41
+ - twitter
42
+ - youtube
43
+
44
+ USAGE
45
+ end
46
+
47
+ end
48
+
49
+
50
+ class String
51
+ def camelize
52
+ self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
53
+ end
54
+
55
+ def trim
56
+ self.gsub(/^ +/, '')
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ module Reputation
2
+ class Service
3
+ require 'open-uri'
4
+ require 'hpricot'
5
+
6
+ attr_reader :account
7
+
8
+ def initialize(account)
9
+ @account = account
10
+ end
11
+
12
+ def profile_page
13
+ begin
14
+ @profile_page ||= Hpricot(open(account_uri))
15
+ rescue OpenURI::HTTPError
16
+ # assume no account
17
+ puts "No account named '#{account}' found on #{self}"
18
+ exit(1)
19
+ end
20
+ end
21
+
22
+ def render_items
23
+ result = []
24
+
25
+ max_description_len = self.class.items.collect{|_, description| description.size}.max
26
+
27
+ self.class.items.each do |name, description|
28
+ gap = max_description_len - description.size
29
+
30
+ result << "#{description}: #{' ' * gap}"
31
+ result.last << self.send(name)
32
+ end
33
+ result.join("\n")
34
+ end
35
+
36
+ def to_s
37
+ self.class.to_s.split('::').last.gsub(/^./){$&.upcase}
38
+ end
39
+
40
+
41
+ # CLASS
42
+ def self.inherited(sub)
43
+ sub.class_eval{ @items = []}
44
+ end
45
+
46
+ def self.item(name, description, &block)
47
+ self.send(:define_method, name) do
48
+ result = instance_eval(&block)
49
+ # assume Hpricot::Elem
50
+ result.inner_text.strip rescue result
51
+ end
52
+ self.items << [name, description]
53
+ end
54
+
55
+ def self.items
56
+ @items
57
+ end
58
+
59
+ def self.class_for(service)
60
+ service_name = service.camelize
61
+
62
+ Reputation.const_get(service_name)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ module Reputation
2
+ class Github < Service
3
+
4
+ item(:name, 'Full name') do
5
+ (profile_page%'div.vcard span#profile_name')
6
+ end
7
+
8
+ item(:member_since, 'Member since') do
9
+ member_since = (profile_page%"label[text()*='Member Since:']").following.inner_text.strip
10
+ days_ago = (Date.today - Date.parse(member_since)).to_i
11
+ "#{member_since} (#{days_ago} days)"
12
+ end
13
+
14
+ item(:public_repos, 'Public repositories') do
15
+ cCreated, cForked = %w(Created Forked).collect do |text|
16
+ (profile_page/"li.project div.meta[text()*='#{text}']").size
17
+ end
18
+ "#{cCreated + cForked} (created: #{cCreated}, forked: #{cForked})"
19
+ end
20
+
21
+ item(:followers, 'Followers') do
22
+ (profile_page%"label[text()*='Followers:']").following
23
+ end
24
+
25
+ def account_uri
26
+ "http://github.com/#{account}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Reputation
2
+ class Twitter < Service
3
+
4
+ item(:name, 'Name') { (profile_page%"ul.entry-author span.fn") }
5
+ item(:updates, 'Updates') { (profile_page%"span#update_count") }
6
+ item(:followers, 'Followers') { (profile_page%"span#follower_count") }
7
+ item(:following, 'Following') { (profile_page%"span#following_count") }
8
+
9
+ def account_uri
10
+ "http://twitter.com/#{account}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Reputation
2
+ class Youtube < Service
3
+ item(:videos_submitted, "Videos submitted") do
4
+ (profile_page%"a[@name*='channel-box-item-count']")
5
+ end
6
+
7
+ item(:member_since, "Member since") do
8
+ (profile_page%"strong#user-profile-member-since")
9
+ end
10
+
11
+ item(:subscribers, "Subscribers") do
12
+ (profile_page%"strong#user-profile-subscriber-count")
13
+ end
14
+
15
+ def account_uri
16
+ "http://www.youtube.com/user/#{account}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ReputationTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'context'
4
+ require 'matchy'
5
+ require 'rr'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'reputation'
9
+
10
+ class Test::Unit::TestCase
11
+ include RR::Adapters::TestUnit
12
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thinkcreate-reputation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gert Goet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-10 00:00:00 -08:00
13
+ default_executable: reputation
14
+ dependencies: []
15
+
16
+ description: Get a quick overview of someone's account at services like github, twitter etc.
17
+ email: gert@thinkcreate.nl
18
+ executables:
19
+ - reputation
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - VERSION.yml
26
+ - bin/reputation
27
+ - lib/reputation.rb
28
+ - lib/services
29
+ - lib/services/base.rb
30
+ - lib/services/github.rb
31
+ - lib/services/twitter.rb
32
+ - lib/services/youtube.rb
33
+ - test/reputation_test.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/thinkcreate/reputation
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --inline-source
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Get a quick overview of someone's account at services like github, twitter etc.
62
+ test_files: []
63
+