// Path: src/main/java/org/springframework/social/tumblr/api/Tumblr.java
// public interface Tumblr {
// 
//     BlogOperations blogOperations(String blogHostname);
//     
//     UserOperations userOperations();
// 
//     TaggedOperations taggedOperations();
// }
// 
// Path: src/main/java/org/springframework/social/tumblr/api/impl/TumblrTemplate.java
// public class TumblrTemplate extends AbstractOAuth1ApiBinding implements Tumblr {
// 
//     private String apiKey;
// 
//     private UserOperations userOperations;
// 
//     private TaggedOperations taggedOperations;
// 
//     private TumblrOAuth1Credentials credentials;
// 
//     /**
//      * Constructor to make unauthenticated calls to Tumblr's public API methods.
//      */
//     public TumblrTemplate() {
//         super();
//         initApis();
//     }
// 
//     /**
//      * Constructor to make calls to Tumblr's API methods that require an API key.
//      *
//      * @param consumerKey your Tumblr app's API key
//      */
//     public TumblrTemplate(String consumerKey) {
//         super();
//         this.apiKey = consumerKey;
//         initApis();
//     }
// 
//     /**
//      * Constructor to make calls to Tubmlr's API on behalf of a Tumblr user.
//      *
//      * @param consumerKey your Tumblr app's API key
//      * @param consumerSecret your Tumblr app's secret
//      * @param accessToken the access token your app has been granted for a particular user
//      * @param accessTokenSecret the access token secret your app has been granted for a particular user
//      */
//     public TumblrTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
//         super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//         this.apiKey = consumerKey;
//         credentials = new TumblrOAuth1Credentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//         initApis();
//     }
// 
//     public TumblrOAuth1Credentials getCredentials() {
//         return credentials;
//     }
// 
//     @Override
//     protected void configureRestTemplate(RestTemplate restTemplate) {
//         List<HttpMessageConverter<?>> oldMessageConverters = restTemplate.getMessageConverters();
//         for (HttpMessageConverter<?> converter : oldMessageConverters) {
//             if (converter instanceof FormHttpMessageConverter) {
//                 // use LATIN1 character set for all form posts...?
//                 ((FormHttpMessageConverter) converter).setCharset(Charset.forName("LATIN1"));
//             }
//         }
//         // replace the default OAuth1 interceptor with a custom one that uses a custom SigningSupport impl
//         // doing some hokey stuff here to make the credentials available to the interceptor
//         TumblrOAuth1RequestInterceptor interceptor = new TumblrOAuth1RequestInterceptor(this);
//         List<ClientHttpRequestInterceptor> newInterceptors = new ArrayList<ClientHttpRequestInterceptor>();
//         newInterceptors.add(interceptor);
//         restTemplate.setInterceptors(newInterceptors);
//     }
// 
//     @Override
//     protected MappingJackson2HttpMessageConverter getJsonMessageConverter() {
//         return new TumblrHttpMessageConverter();
//     }
// 
//     public BlogOperations blogOperations(String blogHostname) {
//         return new BlogTemplate(getRestTemplate(), isAuthorized(), apiKey, blogHostname);
//     }
// 
//     public UserOperations userOperations() {
//         return userOperations;
//     }
// 
//     public TaggedOperations taggedOperations() {
//         return taggedOperations;
//     }
// 
//     private void initApis() {
//         this.userOperations = new UserTemplate(getRestTemplate(), isAuthorized(), apiKey);
//         this.taggedOperations = new TaggedOperationsTemplate(getRestTemplate(), isAuthorized(), apiKey);
//     }
// }


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.social.UserIdSource;
import org.springframework.social.config.xml.ApiHelper;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.tumblr.api.Tumblr;
import org.springframework.social.tumblr.api.impl.TumblrTemplate;
package org.springframework.social.tumblr.config.support;


/**
 * Support class for JavaConfig and XML configuration support.
 * Creates an API binding instance for the current user's connection.
 */
public class TumblrApiHelper implements ApiHelper<Tumblr> {

    private final UsersConnectionRepository usersConnectionRepository;

    private final UserIdSource userIdSource;

    private TumblrApiHelper(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource) {
        this.usersConnectionRepository = usersConnectionRepository;
        this.userIdSource = userIdSource;        
    }

    public Tumblr getApi() {
        if (logger.isDebugEnabled()) {
            logger.debug("Getting API binding instance for Tumblr");
        }
        
        Connection<Tumblr> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Tumblr.class);
// Path: src/main/java/org/springframework/social/tumblr/api/Tumblr.java
// public interface Tumblr {
// 
//     BlogOperations blogOperations(String blogHostname);
//     
//     UserOperations userOperations();
// 
//     TaggedOperations taggedOperations();
// }
// 
// Path: src/main/java/org/springframework/social/tumblr/api/impl/TumblrTemplate.java
// public class TumblrTemplate extends AbstractOAuth1ApiBinding implements Tumblr {
// 
//     private String apiKey;
// 
//     private UserOperations userOperations;
// 
//     private TaggedOperations taggedOperations;
// 
//     private TumblrOAuth1Credentials credentials;
// 
//     /**
//      * Constructor to make unauthenticated calls to Tumblr's public API methods.
//      */
//     public TumblrTemplate() {
//         super();
//         initApis();
//     }
// 
//     /**
//      * Constructor to make calls to Tumblr's API methods that require an API key.
//      *
//      * @param consumerKey your Tumblr app's API key
//      */
//     public TumblrTemplate(String consumerKey) {
//         super();
//         this.apiKey = consumerKey;
//         initApis();
//     }
// 
//     /**
//      * Constructor to make calls to Tubmlr's API on behalf of a Tumblr user.
//      *
//      * @param consumerKey your Tumblr app's API key
//      * @param consumerSecret your Tumblr app's secret
//      * @param accessToken the access token your app has been granted for a particular user
//      * @param accessTokenSecret the access token secret your app has been granted for a particular user
//      */
//     public TumblrTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
//         super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//         this.apiKey = consumerKey;
//         credentials = new TumblrOAuth1Credentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//         initApis();
//     }
// 
//     public TumblrOAuth1Credentials getCredentials() {
//         return credentials;
//     }
// 
//     @Override
//     protected void configureRestTemplate(RestTemplate restTemplate) {
//         List<HttpMessageConverter<?>> oldMessageConverters = restTemplate.getMessageConverters();
//         for (HttpMessageConverter<?> converter : oldMessageConverters) {
//             if (converter instanceof FormHttpMessageConverter) {
//                 // use LATIN1 character set for all form posts...?
//                 ((FormHttpMessageConverter) converter).setCharset(Charset.forName("LATIN1"));
//             }
//         }
//         // replace the default OAuth1 interceptor with a custom one that uses a custom SigningSupport impl
//         // doing some hokey stuff here to make the credentials available to the interceptor
//         TumblrOAuth1RequestInterceptor interceptor = new TumblrOAuth1RequestInterceptor(this);
//         List<ClientHttpRequestInterceptor> newInterceptors = new ArrayList<ClientHttpRequestInterceptor>();
//         newInterceptors.add(interceptor);
//         restTemplate.setInterceptors(newInterceptors);
//     }
// 
//     @Override
//     protected MappingJackson2HttpMessageConverter getJsonMessageConverter() {
//         return new TumblrHttpMessageConverter();
//     }
// 
//     public BlogOperations blogOperations(String blogHostname) {
//         return new BlogTemplate(getRestTemplate(), isAuthorized(), apiKey, blogHostname);
//     }
// 
//     public UserOperations userOperations() {
//         return userOperations;
//     }
// 
//     public TaggedOperations taggedOperations() {
//         return taggedOperations;
//     }
// 
//     private void initApis() {
//         this.userOperations = new UserTemplate(getRestTemplate(), isAuthorized(), apiKey);
//         this.taggedOperations = new TaggedOperationsTemplate(getRestTemplate(), isAuthorized(), apiKey);
//     }
// }


// Path: src/main/java/org/springframework/social/tumblr/config/support/TumblrApiHelper.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.social.UserIdSource;
import org.springframework.social.config.xml.ApiHelper;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.tumblr.api.Tumblr;
import org.springframework.social.tumblr.api.impl.TumblrTemplate;

package org.springframework.social.tumblr.config.support;


/**
 * Support class for JavaConfig and XML configuration support.
 * Creates an API binding instance for the current user's connection.
 */
public class TumblrApiHelper implements ApiHelper<Tumblr> {

    private final UsersConnectionRepository usersConnectionRepository;

    private final UserIdSource userIdSource;

    private TumblrApiHelper(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource) {
        this.usersConnectionRepository = usersConnectionRepository;
        this.userIdSource = userIdSource;        
    }

    public Tumblr getApi() {
        if (logger.isDebugEnabled()) {
            logger.debug("Getting API binding instance for Tumblr");
        }
        
        Connection<Tumblr> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Tumblr.class);
        if (logger.isDebugEnabled() && connection == null) {