1 package com.leonarduk.clearcheckbook.calls; 2 3 import java.io.IOException; 4 5 import org.apache.log4j.Logger; 6 7 import com.leonarduk.clearcheckbook.ClearCheckBookConnection; 8 import com.leonarduk.clearcheckbook.ClearcheckbookException; 9 import com.leonarduk.clearcheckbook.dto.UserDataType; 10 11 public class UserCall extends AbstractCall<UserDataType> { 12 13 private static final Logger _logger = Logger.getLogger(UserCall.class); 14 15 public static final String TYPE = "user"; 16 17 public UserCall(ClearCheckBookConnection connection) { 18 super(connection, UserDataType.class); 19 } 20 21 @Override 22 protected String getUrlSuffix() { 23 return TYPE; 24 } 25 26 /*** 27 * Gets the details for the current user. <br> 28 * Method: get <br> 29 * Call: user 30 * <p> 31 * Example: https://username:password@www.clearcheckbook.com/api/user/ 32 * <p> 33 * Parameters: <br> 34 * Parameter Required Description <br> 35 * None 36 * <p> 37 * Returned Values: <br> 38 * Value Description <br> 39 * id The current users id in the ClearCheckbook system <br> 40 * username The current users username <br> 41 * password MD5 hash of current users password <br> 42 * email Email address of current user 43 * 44 * @throws ClearcheckbookException 45 */ 46 public UserDataType get() throws ClearcheckbookException { 47 return super.get(); 48 } 49 50 /*** 51 * Creates a new ClearCheckbook.com user account <br> 52 * Method: post <br> 53 * Call: user 54 * <p> 55 * Example: <br> 56 * https://www.clearcheckbook.com/api/user/ 57 * <p> 58 * Notes: <br> 59 * You do not pass any authentication information when creating a user. This 60 * is the only function that behaves this way. If the username or email 61 * address exists in the system, this function returns false. <br> 62 * Parameters: <br> 63 * Parameter Required Description <br> 64 * username Required The desired username for the new user <br> 65 * xpassword Required an unencoded password for the new user <br> 66 * email Required an email address for the new user <br> 67 * app Optional A name for your app (eg: "iPhone App" for an iPhone app). 68 * Lets us know where users are coming from. 69 * <p> 70 * Returned Values: <br> 71 * Value Description <br> 72 * Multiple Responses* The new users id in the ClearCheckbook system on 73 * successfull insert or false if the username or email already exists in 74 * system. 75 * 76 * @param 77 * @return 78 * @throws ClearcheckbookException 79 */ 80 @Override 81 public String insert(UserDataType dataType) throws ClearcheckbookException { 82 _logger.debug("insert: " + dataType); 83 String returnString; 84 try { 85 returnString = this.getConnection().postPage(getUrlSuffix(), 86 dataType.getInsertParameters()); 87 88 Long id = Long.valueOf(returnString); 89 _logger.info("insert: created id " + id); 90 return id.toString(); 91 } catch (NumberFormatException e) { 92 throw new ClearcheckbookException( 93 "Failed to create user - already exists", e); 94 } catch (IOException e) { 95 throw new ClearcheckbookException("Failed to create user ", e); 96 } 97 } 98 }