com.leonarduk.clearcheckbook.calls.LimitCall Maven / Gradle / Ivy
Show all versions of clearcheckbookapi Show documentation
/**
* LimitCall
*
* @author ${author}
* @since 10-Jul-2016
*/
package com.leonarduk.clearcheckbook.calls;
import java.io.IOException;
import java.util.List;
import org.apache.log4j.Logger;
import com.leonarduk.clearcheckbook.ClearCheckBookConnection;
import com.leonarduk.clearcheckbook.ClearcheckbookException;
import com.leonarduk.clearcheckbook.dto.LimitDataType;
import com.leonarduk.clearcheckbook.dto.ParsedNameValuePair;
/**
* The Class LimitCall.
*
* @author Stephen Leonard
* @since 30 Jan 2014
*/
public class LimitCall extends AbstractCall {
/** The Constant _logger. */
private static final Logger _logger = Logger.getLogger(LimitCall.class);
/** The Constant TYPE. */
public static final String TYPE = "limit";
/**
* Instantiates a new limit call.
*
* @param connection
* the connection
*/
public LimitCall(final ClearCheckBookConnection connection) {
super(connection, LimitDataType.class);
}
/**
* Delete a specific limit for the current user.
* Method: delete
* Call: limit
*
* Example:
* https://username:[email protected]/api/limit/
*
* Parameters:
* Parameter Required Description
* id Required The id of the limit to delete
*
* Returned Values:
* Value Description
* true / false Returns true on a successful delete or false/null on fail
*
* @param input
* the input
* @return true, if successful
* @throws ClearcheckbookException
* the clearcheckbook exception
*/
@Override
public boolean delete(final ParsedNameValuePair input) throws ClearcheckbookException {
final boolean delete = super.delete(input);
LimitCall._logger.debug(delete);
return delete;
}
/**
* Edit a specific limit for the current user.
* Method: put
* Call: limit
*
*
* Example:
* https://username:[email protected]/api/limit/
*
* Parameters:
* Parameter Required Description
* id Required The id of the limit being edited.
* amount Required The amount this limit should be for (eg: 300)
* duration Required The duration of this budget based on when it resets. (0=Weekly;
* 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually)
* reset_day Required Integer 1-31 for the day this limit should reset on. If this number is
* higher than the last day of the month, the limit will reset on the last day of the month.
*
* start_date Required If the duration is not 2, this will be when the budget originally starts
* (formatted as yyyy-mm-dd).
* rollover Required Whether or not this limit rolls over any unused money to the next month.
* 0=false, 1=true
* transfer Required Whether or not this limit includes transfers in the amount spent. 0=false,
* 1=true
* deposit Required Whether or not this limit uses deposits to reduce the amount spent. 0=false,
* 1=true
*
* Returned Values:
* Value Description
* true / false Returns true on a successful edit or false/null on fail. ACTUALLY - it returns
* "null" on success and "" on fail
*
* @param dataType
* the data type
* @return true, if successful
* @throws ClearcheckbookException
* the clearcheckbook exception
*/
@Override
public boolean edit(final LimitDataType dataType) throws ClearcheckbookException {
String returnString;
try {
returnString = this.getConnection().putPage(this.getUrlSuffix(),
dataType.getEditParameters());
LimitCall._logger.debug("returned: [" + returnString + "]");
final boolean ok = (returnString.equals("null"));
LimitCall._logger.info("edit : edited " + ok);
return ok;
}
catch (final IOException e) {
throw new ClearcheckbookException("Failed to edit " + this.getUrlSuffix(), e);
}
}
/**
* Returns information about a specific limit.
* Method: get
* Call: limit
*
*
* Example:
* https://username:[email protected]/api/limit/
*
* Parameters:
* Parameter Required Description
* id Required The id of the limit you want
*
* Returned Values:
* Value Description
* id The id of the limit
* amount The amount this limit is set for
* reset_day The day of the month this limit is going to reset.
* rollover TRUE or FALSE for whether or not this limit rollsover
* transfer TRUE or FALSE for whether or not this limit includes transfers in the amount spent.
*
* deposit TRUE or FALSE for whether or not this limit uses deposits to reduce the amount spent.
*
* duration The duration of this budget based on when it resets. (0=Weekly; 1=Bi-Weekly;
* 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually)
* start_date If the duration is not 2, this will be when the budget originally started.
* this_start_date This is when the budget for the current time period started.
* this_end_date This is when the budget for the current time period ends.
* original_limit The original amount of the limit (in case rollover is set to true).
*
* @param id
* the id
* @return the limit data type
* @throws ClearcheckbookException
* the clearcheckbook exception
*/
@Override
public LimitDataType get(final ParsedNameValuePair id) throws ClearcheckbookException {
final LimitDataType limitDataType = super.get(id);
LimitCall._logger.debug(limitDataType);
return limitDataType;
}
/**
* Returns an array of limits for the current user
* Method: get
* Call: limits
*
* Example:
* https://username:[email protected]/api/limits/
*
* Parameters:
* Parameter Required Description
* None
*
* Returned Values:
* Value Description
* id The id of the limit
* name The Account or Category name this limit is assigned to.
* limit_amount The amount this limit is set to.
* account_id If this is a limit for an account, this will be the id of that account (0 if it's
* not set for an account)
* category_id If this is a limit for a category, this is the id of that category (0 if it's not
* set for a category)
* spent The amount spent so far for this transaction.
* rollover Whether or not this limit rolls over on its reset day
* reset_day The day of the month this limit is set to reset.
* transfer Whether or not this limit includes transfers in the amount spent.
* deposit Whether or not this limit uses deposits to reduce the amount spent.
* duration The duration of this budget based on when it resets. (0=Weekly; 1=Bi-Weekly;
* 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually)
* start_date If the duration is not 2, this will be when the budget originally started.
* this_start_date This is when the budget for the current time period started.
* this_end_date This is when the budget for the current time period ends.
* original_limit The original amount of the limit (in case rollover is set to true).
*
* @return the all
* @throws ClearcheckbookException
* the clearcheckbook exception
*/
@Override
public List getAll() throws ClearcheckbookException {
return super.getAll();
}
/*
* (non-Javadoc)
*
* @see com.leonarduk.clearcheckbook.calls.AbstractCall#getUrlSuffix()
*/
@Override
protected String getUrlSuffix() {
return LimitCall.TYPE;
}
/**
* Inserts a limit for the current user
* Method: post
* Call: limit
*
* Example:
* https://username:[email protected]/api/limit/
*
* Parameters:
* Parameter Required Description
* account_id Required If the limit is for an account, the id of the account. Default is 0.
* category_id Required If the limit is for a category, the id of the category. Default is 0.
*
* amount Required The amount this limit should be for (eg: 300)
* duration Required The duration of this budget based on when it resets. (0=Weekly;
* 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually)
* reset_day Required Integer 1-31 for the day this limit should reset on. If this number is
* higher than the last day of the month, the limit will reset on the last day of the month.
*
* start_date Required If the duration is not 2, this will be when the budget originally starts
* (formatted as yyyy-mm-dd).
* rollover Required Whether or not this limit rolls over any unused money to the next month.
* 0=false, 1=true
* transfer Required Whether or not this limit includes transfers in the amount spent. 0=false,
* 1=true
* deposit Required Whether or not this limit uses deposits to reduce the amount spent. 0=false,
* 1=true
*
* Returned Values:
* Value Description
* id / false Returns the id of the newly created limit on success or false/null on fail
*
* @param input
* the input
* @return the string
* @throws ClearcheckbookException
* the clearcheckbook exception
*/
@Override
public String insert(final LimitDataType input) throws ClearcheckbookException {
final String insert = super.insert(input);
LimitCall._logger.debug(insert);
return insert;
}
}