All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.leonarduk.clearcheckbook.calls.UserCall Maven / Gradle / Ivy

Go to download

A Java library to access the HTTP developer API for Clearcheckbook.com, the money management website.

There is a newer version: 1.4
Show newest version
/**
 * UserCall
 *
 * @author ${author}
 * @since 10-Jul-2016
 */
package com.leonarduk.clearcheckbook.calls;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.leonarduk.clearcheckbook.ClearCheckBookConnection;
import com.leonarduk.clearcheckbook.ClearcheckbookException;
import com.leonarduk.clearcheckbook.dto.UserDataType;

/**
 * The Class UserCall.
 */
public class UserCall extends AbstractCall {

	/** The Constant _logger. */
	private static final Logger _logger = Logger.getLogger(UserCall.class);

	/** The Constant TYPE. */
	public static final String TYPE = "user";

	/**
	 * Instantiates a new user call.
	 *
	 * @param connection
	 *            the connection
	 */
	public UserCall(final ClearCheckBookConnection connection) {
		super(connection, UserDataType.class);
	}

	/**
	 * Gets the details for the current user. 
* Method: get
* Call: user *

* Example: https://username:[email protected]/api/user/ *

* Parameters:
* Parameter Required Description
* None *

* Returned Values:
* Value Description
* id The current users id in the ClearCheckbook system
* username The current users username
* password MD5 hash of current users password
* email Email address of current user * * @return the user data type * @throws ClearcheckbookException * the clearcheckbook exception */ @Override public UserDataType get() throws ClearcheckbookException { return super.get(); } /* * (non-Javadoc) * * @see com.leonarduk.clearcheckbook.calls.AbstractCall#getUrlSuffix() */ @Override protected String getUrlSuffix() { return UserCall.TYPE; } /** * Creates a new ClearCheckbook.com user account
* Method: post
* Call: user *

* Example:
* https://www.clearcheckbook.com/api/user/ *

* Notes:
* You do not pass any authentication information when creating a user. This is the only * function that behaves this way. If the username or email address exists in the system, this * function returns false.
* Parameters:
* Parameter Required Description
* username Required The desired username for the new user
* xpassword Required an unencoded password for the new user
* email Required an email address for the new user
* app Optional A name for your app (eg: "iPhone App" for an iPhone app). Lets us know where * users are coming from. *

* Returned Values:
* Value Description
* Multiple Responses* The new users id in the ClearCheckbook system on successfull insert or * false if the username or email already exists in system. * * @param dataType * the data type * @return the string * @throws ClearcheckbookException * the clearcheckbook exception */ @Override public String insert(final UserDataType dataType) throws ClearcheckbookException { UserCall._logger.debug("insert: " + dataType); String returnString; try { returnString = this.getConnection().postPage(this.getUrlSuffix(), dataType.getInsertParameters()); final Long id = Long.valueOf(returnString); UserCall._logger.info("insert: created id " + id); return id.toString(); } catch (final NumberFormatException e) { throw new ClearcheckbookException("Failed to create user - already exists", e); } catch (final IOException e) { throw new ClearcheckbookException("Failed to create user ", e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy