1. Stephen McDonald
  2. linkedout

Commits

Stephen McDonald  committed bd23553

Cleaned up routes and views.

  • Participants
  • Parent commits 3a3113d
  • Branches default

Comments (0)

Files changed (4)

File app.rb

View file
 
 get "/" do
   if session[:auth].nil?
-    args = {:oauth_callback => "#{request.url}callback"}
-    request_token = @client.request_token args
-    session[:request] = request_token.token, request_token.secret
-    redirect @client.request_token.authorize_url
+    erubis :index
   else
-    redirect "/create"
+    @profiles = (@client.connections.all + [@profile]).sort_by {|p|
+      p.first_name.upcase
+    }
+    erubis :create
   end
 end
 
-get "/callback" do
-  token, secret = session[:request]
-  pin = params[:oauth_verifier]
-  session[:auth] = @client.authorize_from_request token, secret, pin
-  redirect "/create"
-end
-
-get "/create" do
-  @profiles = (@client.connections.all + [@profile]).sort_by {|p|
-    p.first_name.upcase
-  }
-  erubis :create
-end
-
-post "/create" do
+post "/" do
   @resume = Resume.first_or_create(:by => @profile.id, :for => params[:id])
   @resume.update(:email => params[:email])
   @profile = @client.profile :id => params[:id], :fields => resume_fields
   attachment @profile.first_name + @profile.last_name + ".pdf"
   PDFKit.new(erubis :resume).to_pdf
 end
+
+get "/login" do
+  if params[:oauth_verifier].nil?
+    args = {:oauth_callback => "#{request.url}"}
+    request_token = @client.request_token args
+    session[:request] = request_token.token, request_token.secret
+    redirect @client.request_token.authorize_url
+  else
+    token, secret = session[:request]
+    pin = params[:oauth_verifier]
+    session[:auth] = @client.authorize_from_request token, secret, pin
+    redirect "/"
+  end
+end

File views/create.erb

View file
 <head>
 
 <meta charset="utf-8">
-<title>Linked Out</title>
-<meta name="description" content="Convert LinkedIn profiles into beautiful PDF resumes.">
+<title>LinkedOut</title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
 <script>
         }
     });
 
-    select.change(function() {
+    var profile = function() {
         var template = $('#profile-template').tmpl(profiles[this.value]);
         $('#profile').html(template);
-    });
+    };
+
+    select.change(profile).keyup(profile);
 
     select.val('<%= @profile.id %>').change();
 
 
 </script>
 <style>
-    #profiles, #profile {margin:10px;}
     #profile * {margin:0;}
+    #profile {
+        border:1px solid #ccc; padding:10px; min-height:80px; width:500px;
+        margin-top:10px;
+    }
     #profile img {float:left; width:80px; height:80px; margin-right:10px;}
+    .button {
+        display:block; cursor:pointer; padding:10px 20px; margin-top:20px;
+        font-weight:bold;
+    }
 </style>
+
 </head>
-
 <body>
 
+<h1>LinkedOut</h1>
+<p>Choose a profile to create a resume.</p>
+
 <form method="post">
+    <label for="profiles">Profile:</label>
     <select name="id" id="profiles"></select>
     <script id="profile-template" type="text/x-jquery-tmpl">
         <img src="${picture_url}">
-        <h1>${name}</h1>
+        <h2>${name}</h2>
         <p>${headline}</p>
     </script>
     <div id="profile"></div>
+    <p>LinkedIn doesn't allow access to email addresses, so you can optionally
+       add an email address to the resume.</p>
     <label for="email">Email:</label>
     <input name="email" id="email">
-    <input type="submit" value="Create resume">
+    <input class="button" type="submit" value="Create resume">
 </form>
 
 </body>

File views/index.erb

View file
+<!doctype html>
+<html lang="en">
+<head>
+
+<meta charset="utf-8">
+<title>LinkedOut</title>
+<meta name="description" content="Convert LinkedIn profiles into clean PDF resumes.">
+
+</head>
+<body>
+
+<h1>LinkedOut</h1>
+<p>Convert LinkedIn profiles into clean PDF resumes.</p>
+
+<a href="login">Login via LinkedIn</a>
+
+</body>
+</html>

File views/resume.erb

View file
-<html>
+<!doctype html>
+<html lang="en">
 <head>
-    <meta charset="utf-8">
-    <style>
-        * {font-family:sans-serif; margin:10px 0; line-height:26px; font-size:16px;}
-        hr {margin:30px 0;}
-        h1 {font-size:26px;}
-        h2 {font-size:22px; font-weight:normal; margin-top:20px;}
-        h2, .experience {color:#666;}
-        h3 {margin-top:20px;}
-        li, a {margin:5px 0;}
-    </style>
+
+<meta charset="utf-8">
+<style>
+    * {font-family:sans-serif; margin:10px 0; line-height:26px; font-size:16px;}
+    hr {margin:30px 0;}
+    h1 {font-size:26px;}
+    h2 {font-size:22px; font-weight:normal; margin-top:20px;}
+    h2, .experience {color:#666;}
+    h3 {margin-top:20px;}
+    li, a {margin:5px 0;}
+</style>
+
 </head>
 <body>
 
     <% end %>
 </ul>
 
-<% unless @profile.summary.strip.empty? %>
+<% if @profile.summary && !profile.summary.strip.empty? %>
 <hr>
 <h2>Overview</h2>
 <%== erubis :section, :locals => {:data => @profile.summary} %>