Skip to content

Commit

Permalink
added presenting the profile of the logged in user
Browse files Browse the repository at this point in the history
  • Loading branch information
jettro committed Nov 2, 2010
1 parent 23ad735 commit b20f5a0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -97,20 +97,38 @@ public String authorizeCallback(@RequestParam(value = "oauth_verifier", defaultV
*/ */
@RequestMapping(value = "linkedin/connections", method = RequestMethod.GET) @RequestMapping(value = "linkedin/connections", method = RequestMethod.GET)
public String connections(WebRequest request) { public String connections(WebRequest request) {
LinkedInTemplate template = createLinkedInTemplate(request);

List<LinkedInProfile> connections = template.getConnections();
request.setAttribute("connections", connections, WebRequest.SCOPE_REQUEST);

return "connections";
}

/**
* Handles the request to obtain the profile of the current logged in user
* @param request Spring provided WebRequest
* @return String representing the name of the view to show
*/
@RequestMapping(value = "linkedin/profile", method = RequestMethod.GET)
public String profile(WebRequest request) {
LinkedInTemplate template = createLinkedInTemplate(request);

LinkedInProfile userProfile = template.getUserProfile();
request.setAttribute("profile", userProfile, WebRequest.SCOPE_REQUEST);
return "profile";
}

private LinkedInTemplate createLinkedInTemplate(WebRequest request) {
Token accessToken = obtainAccessTokenFromSession(request); Token accessToken = obtainAccessTokenFromSession(request);
if (accessToken == null) { if (accessToken == null) {
throw new RuntimeException("An access token must be available here"); throw new RuntimeException("An access token must be available here");
} }
LinkedInTemplate template = new LinkedInTemplate( return new LinkedInTemplate(
apiKey, apiKey,
apiSecret, apiSecret,
accessToken.getToken(), accessToken.getToken(),
accessToken.getSecret()); accessToken.getSecret());

List<LinkedInProfile> connections = template.getConnections();
request.setAttribute("connections", connections, WebRequest.SCOPE_REQUEST);

return "connections";
} }


private Token obtainRequestTokenFromSession(WebRequest request) { private Token obtainRequestTokenFromSession(WebRequest request) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<p>Now you are connected to linkedin, you can ask the following thinks:</p> <p>Now you are connected to linkedin, you can ask the following thinks:</p>
<ul> <ul>
<li><a href="<c:url value="/connect/linkedin/connections" />">Connections</a></li> <li><a href="<c:url value="/connect/linkedin/connections" />">Connections</a></li>
<li><a href="<c:url value="/connect/linkedin/profile" />">My Profile</a></li>
</ul> </ul>
<jsp:include page="../inc/footer.jsp"/> <jsp:include page="../inc/footer.jsp"/>
3 changes: 2 additions & 1 deletion src/main/webapp/WEB-INF/views/connections.jsp
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
<jsp:include page="inc/header.jsp"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:include page="inc/header.jsp"/>
<jsp:include page="inc/navigation.jsp"/>
<table> <table>
<c:forEach items="${connections}" var="connection"> <c:forEach items="${connections}" var="connection">
<tr> <tr>
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/views/inc/navigation.jsp
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div>
<span><a href="<c:url value="/connect/linkedin/connections" />">Connections</a></span>
<span><a href="<c:url value="/connect/linkedin/profile" />">My Profile</a></span>
</div>
26 changes: 26 additions & 0 deletions src/main/webapp/WEB-INF/views/profile.jsp
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,26 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:include page="inc/header.jsp"/>
<jsp:include page="inc/navigation.jsp"/>
<table>
<tr>
<td>First name</td>
<td><c:out value="${profile.firstName}" /></td>
</tr>
<tr>
<td>Last name</td>
<td><c:out value="${profile.lastName}" /></td>
</tr>
<tr>
<td>headline</td>
<td><c:out value="${profile.headline}" /></td>
</tr>
<tr>
<td>PublicProfileUrls</td>
<td><c:out value="${profile.publicProfileUrl}" /></td>
</tr>
<tr>
<td>Industry</td>
<td><c:out value="${profile.industry}" /></td>
</tr>
</table>
<jsp:include page="inc/footer.jsp"/>

0 comments on commit b20f5a0

Please sign in to comment.