/*
 * Copyright 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.social.linkedin.api.impl;

import java.util.List;

import org.springframework.social.linkedin.api.LinkedInApi;
import org.springframework.social.linkedin.api.LinkedInConnections;
import org.springframework.social.linkedin.api.LinkedInProfile;
import org.springframework.social.oauth1.ProtectedResourceClientFactory;
import org.springframework.web.client.RestTemplate;

/**
 * This is the central class for interacting with LinkedIn.
 * <p>
 * Greenhouse operations require OAuth authentication with the server.
 * Therefore, LinkedInTemplate must be constructed with the minimal information
 * required to sign requests with and OAuth 1 Authorization header.
 * </p>
 * @author Craig Walls
 */
public class LinkedInTemplate implements LinkedInApi {

	private final RestTemplate restTemplate;

	/**
	 * Creates a new LinkedInTemplate given the minimal amount of information needed to sign requests with OAuth 1 credentials.
	 * @param apiKey the application's API key
	 * @param apiSecret the application's API secret
	 * @param accessToken an access token acquired through OAuth authentication with LinkedIn
	 * @param accessTokenSecret an access token secret acquired through OAuth authentication with LinkedIn
	 */
	public LinkedInTemplate(String apiKey, String apiSecret, String accessToken, String accessTokenSecret) {
		this.restTemplate = ProtectedResourceClientFactory.create(apiKey, apiSecret, accessToken, accessTokenSecret);
	}

	public String getProfileId() {
		return getUserProfile().getId();
	}

	public String getProfileUrl() {
		return getUserProfile().getPublicProfileUrl();
	}

	public LinkedInProfile getUserProfile() {
		return restTemplate.getForObject(GET_CURRENT_USER_INFO, LinkedInProfile.class);
	}

	public List<LinkedInProfile> getConnections() {
		LinkedInConnections connections = restTemplate.getForObject("https://api.linkedin.com/v1/people/~/connections", LinkedInConnections.class);
		return connections.getConnections();
	}

	// subclassing hooks
	
	protected RestTemplate getRestTemplate() {
		return restTemplate;
	}

	static final String GET_CURRENT_USER_INFO = "https://api.linkedin.com/v1/people/~:public";

}

@@ -925,82 +925,11 @@
 th1.
-ProtectedResourceClientFactory;%0Aimport org.springframework.web.client.Rest
+Api
 Temp
@@ -1290,16 +1290,36 @@
 emplate 
+extends ApiTemplate 
 implemen
@@ -1340,51 +1340,8 @@
  %7B%0A%0A
-%09private final RestTemplate restTemplate;%0A%0A
 %09/**
@@ -1477,19 +1477,24 @@
  @param 
-api
+consumer
 Key the 
@@ -1526,19 +1526,24 @@
  @param 
-api
+consumer
 Secret t
@@ -1802,19 +1802,24 @@
 (String 
-api
+consumer
 Key, Str
@@ -1822,19 +1822,24 @@
  String 
-api
+consumer
 Secret, 
@@ -1892,77 +1892,35 @@
 %7B%0A%09%09
-this.restTemplate = ProtectedResourceClientFactory.create(apiKey, api
+super(consumerKey, consumer
 Secr
@@ -1955,24 +1955,25 @@
 Secret);%0A%09%7D%0A
+%09
 %0A%09public Str
@@ -2162,33 +2162,36 @@
 le() %7B%0A%09%09return 
-r
+getR
 estTemplate.getF
@@ -2177,32 +2177,34 @@
  getRestTemplate
+()
 .getForObject(GE
@@ -2337,17 +2337,20 @@
 tions = 
-r
+getR
 estTempl
@@ -2352,16 +2352,18 @@
 Template
+()
 .getForO
@@ -2495,103 +2495,8 @@
 %09%7D%0A%0A
-%09// subclassing hooks%0A%09%0A%09protected RestTemplate getRestTemplate() %7B%0A%09%09return restTemplate;%0A%09%7D%0A%0A
 %09sta

Add setRequestFactory() on templates to enable custom settings such as proxy configuration.