Class: Linkedin2CV::Converter
- Inherits:
-
Object
- Object
- Linkedin2CV::Converter
- Includes:
- Logging
- Defined in:
- lib/linkedin2cv/converter.rb
Constant Summary collapse
- API_KEY =
ENV['LINKEDIN_API_KEY']
- API_SECRET =
ENV["LINKEDIN_API_SECRET"]
Instance Method Summary collapse
-
#auth ⇒ Object
Public: Authenticate & Authorize the end user (via OAuth2) and fetch access token.
-
#create_resume(options = {}) ⇒ Object
Public: Create a resume given a LinkedIn Profile.
-
#fetch_token_from_tempfile ⇒ Object
Public: Fetch the token from a temporary oauth token file.
-
#get_profile ⇒ Object
Public: Fetch Profile Data.
-
#initialize(token = nil) ⇒ Converter
constructor
A new instance of Converter.
-
#prompt_user_authorisation ⇒ Object
Public: Invoke the API and browser session for end user authentication.
Methods included from Logging
configure_logger_for, #log, logger_for
Constructor Details
#initialize(token = nil) ⇒ Converter
Returns a new instance of Converter.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/linkedin2cv/converter.rb', line 20 def initialize(token = nil) @display_fields = ["company", "publication", "patent", "language", "skills", "certification", "education", "course", "volunteer", "recommendations"] @profile_fields = ["projects:(start-date,end-date,description,id,name,url),main-address,phone-numbers,email-address,first-name,last-name,maiden-name,formatted-name,phonetic-first-name,phonetic-last-name,formatted-phonetic-name,headline,location:(name,country:(code)),industry,current-status,current-share,num-connections,num-connections-capped,summary,specialties,positions,picture-url,api-standard-profile-request:(url,headers),public-profile-url,last-modified-timestamp,proposal-comments,associations,interests,publications:(id,title,publisher:(name),authors:(id,name,person),date,url,summary),patents,languages:(id,language:(name),proficiency:(level,name)),skills:(id,skill:(name)),certifications:(id,name,authority:(name),number,start-date,end-date),educations:(id,school-name,field-of-study,start-date,end-date,degree,activities,notes),courses:(id,name,number),three-current-positions:(id,title,summary,start-date,end-date,is-current,company),three-past-positions:(id,title,summary,start-date,end-date,is-current,company),num-recommenders,recommendations-received:(id,recommendation-type,recommendation-text,recommender),mfeed-rss-url,following,job-bookmarks,suggestions,date-of-birth,member-url-resources:(url,name),related-profile-views,honors-awards"] @token = token # Confirm API keys setup raise StandardError, "API_KEY not set" unless !API_KEY.nil? raise StandardError, "API_SECRET not set" unless !API_SECRET.nil? # Setup default options to be merged with supplied ones end |
Instance Method Details
#auth ⇒ Object
Public: Authenticate & Authorize the end user (via OAuth2) and fetch access token
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/linkedin2cv/converter.rb', line 58 def auth if @token.nil? # If in CLI Mode, spawn a thread, run the API and open a browser window thread = nil if !File.exists?('.token') auth_thread = puts "Waiting to retrieve LinkedIn OAuth token" sleep 1 until auth_thread.thread_variable?('access_token') end # Get Token from environment @token = fetch_token_from_tempfile puts "I have a token for you: #{@token}" end @token end |
#create_resume(options = {}) ⇒ Object
Public: Create a resume given a LinkedIn Profile
Takes
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/linkedin2cv/converter.rb', line 36 def create_resume( = {}) # Get Profile profile = get_profile # Find stylist (LaTeX / Asciidoc etc.) # Find output factory/plugin (fetch from Github?) case ['format'] when 'latex' require 'linkedin2cv/renderer/latex_renderer' # Currently only supports one LaTeX template renderer = Linkedin2CV::LatexRenderer.new renderer.render(profile, ) else puts "Sorry mate, I don't yet support the '#{['format']}' format'" end end |
#fetch_token_from_tempfile ⇒ Object
Public: Fetch the token from a temporary oauth token file.
112 113 114 115 116 117 118 |
# File 'lib/linkedin2cv/converter.rb', line 112 def fetch_token_from_tempfile # Store in env for command line! file = File.new('.token', 'r') token = file.read file.close token end |
#get_profile ⇒ Object
Public: Fetch Profile Data
81 82 83 84 85 86 87 88 89 |
# File 'lib/linkedin2cv/converter.rb', line 81 def get_profile # Auth token = auth # Get Client info based on fields provided client = LinkedIn::Client.new(API_KEY, API_SECRET, token) client.profile(:fields => @profile_fields) end |
#prompt_user_authorisation ⇒ Object
Public: Invoke the API and browser session for end user authentication.
Returns a sub-process containing the API session.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/linkedin2cv/converter.rb', line 95 def require './app/routes/web' # Start local API Launchy.open("http://localhost:5000/cli/auth") auth_thread = Thread.new do Linkedin2CV::Routes::Web.run! end auth_thread end |