// Path: src/main/java/org/springframework/social/evernote/api/Evernote.java
// public interface Evernote extends ApiBinding {
// 
// 	/**
// 	 * API for performing operations on {@link BusinessNoteStoreClient}.
// 	 *
// 	 * @return operations for {@link BusinessNoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	BusinessNoteStoreOperations businessNoteStoreOperations() throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link LinkedNoteStoreClient}.
// 	 *
// 	 * @param linkedNotebook
// 	 * @return operations for {@link LinkedNoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	LinkedNoteStoreOperations linkedNoteStoreOperations(LinkedNotebook linkedNotebook) throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link NoteStoreClient}.
// 	 *
// 	 * @return operations for {@link NoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	NoteStoreOperations noteStoreOperations() throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link UserStoreClient}.
// 	 *
// 	 * @return operations for {@link UserStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	UserStoreOperations userStoreOperations() throws EvernoteException;
// 
// 
// 	/**
// 	 * Returns underlying {@link ClientFactory} instance.
// 	 *
// 	 * @return {@link ClientFactory} instance.
// 	 */
// 	ClientFactory clientFactory();
// 
// 	/**
// 	 * Retrieve {@link BusinessNoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link BusinessNoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link BusinessNoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	BusinessNoteStoreClient businessNoteStoreClient() throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link LinkedNoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link LinkedNoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link LinkedNoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	LinkedNoteStoreClient linkedNoteStoreClient(LinkedNotebook linkedNotebook) throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link NoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link NoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link NoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	NoteStoreClient noteStoreClient() throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link UserStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link UserStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link UserStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	UserStoreClient userStoreClient() throws EvernoteException;
// 
// 
// 	/**
// 	 * Set to false not to make a proxy for thrift object for null safe collections.
// 	 * <p/>
// 	 * Default is true.
// 	 *
// 	 * @param applyNullSafe set false to disable {@link org.springframework.social.evernote.api.impl.ThriftWrapper}
// 	 */
// 	void setApplyNullSafe(boolean applyNullSafe);
// 
// }


import com.evernote.edam.type.User;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;
import org.springframework.social.connect.UserProfileBuilder;
import org.springframework.social.evernote.api.Evernote;
package org.springframework.social.evernote.connect;


/**
 * @author Tadaya Tsuyukubo
 */
public class EvernoteAdapter implements ApiAdapter<Evernote> {
	@Override
	public boolean test(Evernote evernote) {
		try {
			evernote.userStoreClient().getUser();
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public void setConnectionValues(Evernote evernote, ConnectionValues values) {
		// this impl requires another call to server.
		// TODO: get data from EvernoteAuthToken??
		final User user = evernote.userStoreOperations().getUser();
		values.setProviderUserId(String.valueOf(user.getId()));  // can get from EvernoteAuthToken
		values.setDisplayName(user.getUsername());
		values.setProfileUrl(null);
		values.setImageUrl(null);
	}

	@Override
// Path: src/main/java/org/springframework/social/evernote/api/Evernote.java
// public interface Evernote extends ApiBinding {
// 
// 	/**
// 	 * API for performing operations on {@link BusinessNoteStoreClient}.
// 	 *
// 	 * @return operations for {@link BusinessNoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	BusinessNoteStoreOperations businessNoteStoreOperations() throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link LinkedNoteStoreClient}.
// 	 *
// 	 * @param linkedNotebook
// 	 * @return operations for {@link LinkedNoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	LinkedNoteStoreOperations linkedNoteStoreOperations(LinkedNotebook linkedNotebook) throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link NoteStoreClient}.
// 	 *
// 	 * @return operations for {@link NoteStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	NoteStoreOperations noteStoreOperations() throws EvernoteException;
// 
// 	/**
// 	 * API for performing operations on {@link UserStoreClient}.
// 	 *
// 	 * @return operations for {@link UserStoreClient}.
// 	 * @throws EvernoteException converted unchecked exception.
// 	 */
// 	UserStoreOperations userStoreOperations() throws EvernoteException;
// 
// 
// 	/**
// 	 * Returns underlying {@link ClientFactory} instance.
// 	 *
// 	 * @return {@link ClientFactory} instance.
// 	 */
// 	ClientFactory clientFactory();
// 
// 	/**
// 	 * Retrieve {@link BusinessNoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link BusinessNoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link BusinessNoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	BusinessNoteStoreClient businessNoteStoreClient() throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link LinkedNoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link LinkedNoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link LinkedNoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	LinkedNoteStoreClient linkedNoteStoreClient(LinkedNotebook linkedNotebook) throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link NoteStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link NoteStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link NoteStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	NoteStoreClient noteStoreClient() throws EvernoteException;
// 
// 	/**
// 	 * Retrieve {@link UserStoreClient} instance from underlying {@link ClientFactory}.
// 	 * <p/>
// 	 * When checked exception has thrown while creating {@link UserStoreClient}, it will be converted
// 	 * to {@link EvernoteException} which is an unchecked exception.
// 	 *
// 	 * @return {@link UserStoreClient} instance.
// 	 * @throws EvernoteException encapsulating thrown checked exception.
// 	 */
// 	UserStoreClient userStoreClient() throws EvernoteException;
// 
// 
// 	/**
// 	 * Set to false not to make a proxy for thrift object for null safe collections.
// 	 * <p/>
// 	 * Default is true.
// 	 *
// 	 * @param applyNullSafe set false to disable {@link org.springframework.social.evernote.api.impl.ThriftWrapper}
// 	 */
// 	void setApplyNullSafe(boolean applyNullSafe);
// 
// }


// Path: src/main/java/org/springframework/social/evernote/connect/EvernoteAdapter.java
import com.evernote.edam.type.User;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;
import org.springframework.social.connect.UserProfileBuilder;
import org.springframework.social.evernote.api.Evernote;

package org.springframework.social.evernote.connect;


/**
 * @author Tadaya Tsuyukubo
 */
public class EvernoteAdapter implements ApiAdapter<Evernote> {
	@Override
	public boolean test(Evernote evernote) {
		try {
			evernote.userStoreClient().getUser();
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public void setConnectionValues(Evernote evernote, ConnectionValues values) {
		// this impl requires another call to server.
		// TODO: get data from EvernoteAuthToken??
		final User user = evernote.userStoreOperations().getUser();
		values.setProviderUserId(String.valueOf(user.getId()));  // can get from EvernoteAuthToken
		values.setDisplayName(user.getUsername());
		values.setProfileUrl(null);
		values.setImageUrl(null);
	}

	@Override
	public UserProfile fetchUserProfile(Evernote evernote) {