/
linkedin.rb
154 lines (127 loc) · 4.78 KB
/
linkedin.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class ResumeCli::Models::Linkedin
WHITE = '#fff'
ORANGE = 'orange'
def self.basic
fields = ['first-name', 'last-name', 'headline', 'location:(name)', 'skills', 'member-url-resources']
p = linkedin(fields)
message = "\n"
message << color(WHITE, "#{p[:firstName]} #{p[:lastName]}\n")
message << color(ORANGE, "#{p[:headline]}\n")
message << color('#009D9C', "#{p[:location]['name']}\n\n")
message << "Skills: "
p[:skills]['values'].each_with_index do |skill, num|
message << skill['skill']['name'] if num == 0
break if num > 5
message << ', ' << skill['skill']['name'] unless num == 0
end
message << "\n"
if p[:memberUrlResources]
p[:memberUrlResources]['values'].each do |url_info|
message << url_info['name'] << ": " << url_info['url'] << "\n"
end
end
return message
end
def self.education
fields = ['educations']
p = linkedin(fields)
message = "\n"
p[:educations]['values'].each do |edu|
message << "[[;orange;]#{edu['degree']}] from [[;orange;]#{edu['schoolName']}], "
message << "[[;#009D9C;]#{edu['startDate']['year']} - #{ edu['endDate']['year']}]\n"
message << "[[;white;]#{edu['fieldOfStudy']}]\n"
message << "#{edu['notes'] ? word_wrap(edu['notes']) : ''}\n\n"
end
return message
end
def self.positions
fields = ['positions']
p = linkedin(fields)
all_positions = p[:positions]['values'].group_by {|i| i['isCurrent']}
current_positions = all_positions[true]
previous_positions = all_positions[false]
message = "\n[[;white;]Current Positions]\n"
message << "[[;white;]" << "-" * 17 << "]\n\n"
current_positions.each do |cp|
message << position_message_creater(cp, true)
end
message << "[[;white;]Past Positions]\n"
message << "[[;white;]" << "-" * 15 << "]\n\n"
previous_positions.each do |pp|
message << position_message_creater(pp, false)
end
message
end
def self.projects
message = "\n"
PROJECTS['main'].each do |key, project|
message << color(ORANGE, "#{project["title"]}: ") << color('#009D9C', word_wrap(project["description"])) << "\n"
message << project["link"] << "\n\n"
end
return message
end
def self.help
message = "List of supported commands:\n"
message << color(WHITE, 'basic') << ": Get the basic profile\n"
message << color(WHITE, 'positions|pos|exp') << ": Get the positions that I have held over the years\n"
message << color(WHITE, 'education|edu') << ": Education history\n"
message << color(WHITE, 'projects|pro') << ": List of my projects\n"
message << color(WHITE, 'recommendations|reco') << ": LinkedIn recommendations\n"
message << color(WHITE, 'links') << ": Links to my various profiles\n"
message << color(WHITE, 'help') << ": This help menu\n"
return message
end
def self.reco
fields = ['recommendations-received']
p = linkedin(fields)
recoms = p[:recommendationsReceived]
message = "\n"
message << color(WHITE, "Recommendations Received\n")
message << "[[;white;]" << "-" * 25 << "]\n\n"
recoms["values"].each do |reco|
message << word_wrap(reco["recommendationText"]) << "\n"
message << color(ORANGE, "-") << color(ORANGE, reco["recommender"]["firstName"]) << " " << color(ORANGE, reco["recommender"]["lastName"])
end
return message
end
def self.links
message = "\n"
LINKS['main'].each do |key, link|
message << color(ORANGE, "#{link["title"]}: ") << link["link"] << "\n"
end
return message
end
def method_missing(m, *args, &block)
return "type [[;white;]help], to list supported commands"
end
class << self
alias :exp :positions
alias :experience :positions
alias :pos :positions
alias :edu :education
alias :pro :projects
alias :recommendations :reco
end
private
def self.color name, msg
"[[;#{name};]#{msg}]"
end
def self.linkedin fields
basic_profile = $linkedin.get("/v1/people/~:(#{fields.join(',')})", 'x-li-format' => 'json').body
JSON.parse(basic_profile).symbolize_keys
end
def self.position_message_creater(cp, isCurrent)
date = Proc.new {|c| "#{c['month']}/#{c['year']}" }
message = ""
message << "[[;orange;]#{cp['title']}] at [[;orange;]#{cp['company']['name']}], "
message << "[[;#009D9C;]#{date.call(cp['startDate'])} - #{ isCurrent ? "present" : date.call(cp['endDate'])}]\n"
message << "#{cp['summary'] ? word_wrap(cp['summary']) : ''}\n\n"
end
# taken from http://git.io/68hntw
def self.word_wrap(text, options = {})
line_width = options.fetch(:line_width, 100)
text.split("\n").collect! do |line|
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
end