-
Notifications
You must be signed in to change notification settings - Fork 0
/
info_source.rb
126 lines (118 loc) · 3.42 KB
/
info_source.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require 'json'
class InfoSource
attr :title
def data
{}.to_json
end
def profile_link
"<a href=#{profile_url}>view profile</a>"
end
end
class GithubInfo < InfoSource
require 'rest_client'
def initialize
@title = "Github"
end
def data
res = RestClient.get "https://api.github.com/users/#{settings.github_conf[:user]}"
res_json = JSON.parse(res)
fields = ['login', 'avatar_url', 'html_url', 'public_repos', 'public_gists', 'followers', 'following', 'created_at']
data = {}
fields.each do |field|
data["github_#{field}"] = res_json[field]
end
data['github_created_at'] = Time.parse(data['github_created_at']).to_s
data.to_json
end
def profile_url
"https://github.com/#{settings.github_conf[:user]}"
end
end
class LinkedinInfo < InfoSource
require 'linkedin'
def initialize
@title="LinkedIn"
end
def data
client = LinkedIn::Client.new(settings.linkedin_conf[:api_key], settings.linkedin_conf[:secret])
client.authorize_from_access(settings.linkedin_conf[:access_key1], settings.linkedin_conf[:access_key2])
user = client.profile(:fields => %w(picture-url public-profile-url headline skills positions))
current_position = user.positions.all[0]
current_position = "#{current_position.title} at #{current_position.company.name}"
skills = user.skills.all.map{|s| s.skill.name}.join(', ')
user_fields = {
:linkedin_skills => skills,
:linkedin_position => current_position
}
[:headline, :picture_url, :public_profile_url].each do |field|
user_fields["linkedin_#{field}"] = user.send(field)
end
user_fields.to_json
end
def profile_url
"http://www.linkedin.com/in/#{settings.github_conf[:user]}"
end
end
class WwrInfo < InfoSource
require 'open-uri'
require 'nokogiri'
def initialize
@title = "Working With Rails"
end
def data
doc = Nokogiri::HTML(open(profile_url))
data = {}
sidebar = doc.search("#Side")
data[:wwr_authority_items] = sidebar.search("ul.authority/li").map(&:inner_html).join("\n")
doc.css("#Side > div").each_with_index do |div, i|
case i
when 1
node = div.search("div:nth-child(2)")
data[:wwr_authority] = node && node.inner_text.chomp
#TODO as percentage
when 2
node = div.search("div:nth-child(2)")
data[:wwr_popularity] = node && node.inner_text.chomp
#TODO as percentage
when 3
data[:wwr_ranking] = div && div.inner_text.chomp.sub(/^Ranking:\s/,'')
end
end
node = sidebar.search("p").first
data[:wwr_experience] = node && node.inner_text.chomp
data.to_json
end
def profile_url
"http://workingwithrails.com/person/#{settings.wwr_conf[:user]}"
end
end
class GildInfo < InfoSource
require 'open-uri'
require 'nokogiri'
def initialize
@title="Gild"
end
def data
doc = Nokogiri::HTML(open(profile_url))
data = {:gild_skills => []}
skills = doc.search("#profile_user_skills_content")
skills.search("ul.users_skills/li").each_with_index do |li, i|
name = li.search(".profile_user_skill_name")
score = li.search("span.current_score")
data[:gild_skills] << [name.inner_text, score.inner_text]
#TODO as percentage
end
data.to_json
end
def profile_url
"http://www.gild.com/#{settings.gild_conf[:user]}"
end
end
class BioInfo < InfoSource
def initialize
@title="Bio"
end
def profile_url
nil
end
end