Skip to content

Instantly share code, notes, and snippets.

@mhluska
Last active March 3, 2017 23:42
Show Gist options
  • Save mhluska/9f8ba26bfc8e355c8532 to your computer and use it in GitHub Desktop.
Save mhluska/9f8ba26bfc8e355c8532 to your computer and use it in GitHub Desktop.
Jekyll plugin for blog post on syncing resume with LinkedIn profile: http://mhluska.com/blog/2014/08/20/syncing-a-jekyll-blog-resume-with-your-linkedin-profile/
# _plugins/resume_json.rb
require 'oauth'
require 'yaml'
require 'json'
module Jekyll
class Resume < Jekyll::Generator
def format_date(date)
Date.new(date['year'], date['month']).strftime('%b %Y').to_s
end
def format_position!(position)
position['startDate'] = format_date(position['startDate'])
position['endDate'] = position['endDate'] ? format_date(position['endDate']) : 'present'
position
end
def generate(site)
oauth = YAML.load_file('_oauth.yml')
consumer_options = {
site: 'https://api.linkedin.com',
authorize_path: '/uas/oauth/authorize',
request_token_path: '/uas/oauth/requestToken',
access_token_path: '/uas/oauth/accessToken'
}
consumer = OAuth::Consumer.new(oauth['consumer_key'], oauth['consumer_secret'], consumer_options)
access_token = OAuth::AccessToken.new(consumer, oauth['oauth_token'], oauth['oauth_secret'])
url = CGI::escape('http://www.linkedin.com/in/mhluska')
fields = [
'first-name',
'last-name',
'location:(name)',
'picture-url',
'positions',
'projects',
'educations'
].join(',')
resume_json_text = access_token.get("http://api.linkedin.com/v1/people/url=#{url}:(#{fields})", 'x-li-format' => 'json').body
resume_json = JSON.parse(resume_json_text)
resume_json['positions']['values'].map! { |position| format_position!(position) }
resume_page = site.pages.detect {|page| page.name == 'resume.html'}
resume_page.data['resume'] = resume_json
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment