View Javadoc

1   package com.leonarduk.clearcheckbook.calls;
2   
3   import java.io.IOException;
4   import java.util.List;
5   
6   import org.apache.log4j.Logger;
7   
8   import com.leonarduk.clearcheckbook.ClearCheckBookConnection;
9   import com.leonarduk.clearcheckbook.ClearcheckbookException;
10  import com.leonarduk.clearcheckbook.dto.LimitDataType;
11  import com.leonarduk.clearcheckbook.dto.ParsedNameValuePair;
12  
13  /***
14   * 
15   * 
16   * 
17   * @author Stephen Leonard
18   * @since 30 Jan 2014
19   * 
20   * @version $Author:: $: Author of last commit
21   * @version $Rev:: $: Revision of last commit
22   * @version $Date:: $: Date of last commit
23   * 
24   */
25  public class LimitCall extends AbstractCall<LimitDataType> {
26  
27  	private static final Logger _logger = Logger.getLogger(LimitCall.class);
28  
29  	public static final String TYPE = "limit";
30  
31  	@Override
32  	protected String getUrlSuffix() {
33  		return TYPE;
34  	}
35  
36  	public LimitCall(ClearCheckBookConnection connection) {
37  		super(connection, LimitDataType.class);
38  	}
39  
40  	/***
41  	 * Returns an array of limits for the current user<br>
42  	 * Method: get<br>
43  	 * Call: limits
44  	 * <p>
45  	 * Example: <br>
46  	 * https://username:password@www.clearcheckbook.com/api/limits/
47  	 * <p>
48  	 * Parameters: <br>
49  	 * Parameter Required Description <br>
50  	 * None
51  	 * <p>
52  	 * Returned Values: <br>
53  	 * Value Description <br>
54  	 * id The id of the limit <br>
55  	 * name The Account or Category name this limit is assigned to. <br>
56  	 * limit_amount The amount this limit is set to. <br>
57  	 * account_id If this is a limit for an account, this will be the id of that
58  	 * account (0 if it's not set for an account) <br>
59  	 * category_id If this is a limit for a category, this is the id of that
60  	 * category (0 if it's not set for a category) <br>
61  	 * spent The amount spent so far for this transaction. <br>
62  	 * rollover Whether or not this limit rolls over on its reset day <br>
63  	 * reset_day The day of the month this limit is set to reset. <br>
64  	 * transfer Whether or not this limit includes transfers in the amount
65  	 * spent. <br>
66  	 * deposit Whether or not this limit uses deposits to reduce the amount
67  	 * spent. <br>
68  	 * duration The duration of this budget based on when it resets. (0=Weekly;
69  	 * 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually) <br>
70  	 * start_date If the duration is not 2, this will be when the budget
71  	 * originally started. <br>
72  	 * this_start_date This is when the budget for the current time period
73  	 * started. <br>
74  	 * this_end_date This is when the budget for the current time period ends. <br>
75  	 * original_limit The original amount of the limit (in case rollover is set
76  	 * to true).
77  	 */
78  	@Override
79  	public List<LimitDataType> getAll() throws ClearcheckbookException {
80  		return super.getAll();
81  	}
82  
83  	/***
84  	 * Returns information about a specific limit. <br>
85  	 * Method: get <br>
86  	 * Call: limit
87  	 * <p>
88  	 * <br>
89  	 * Example: <br>
90  	 * https://username:password@www.clearcheckbook.com/api/limit/
91  	 * <p>
92  	 * Parameters: <br>
93  	 * Parameter Required Description <br>
94  	 * id Required The id of the limit you want
95  	 * <p>
96  	 * Returned Values: <br>
97  	 * Value Description <br>
98  	 * id The id of the limit <br>
99  	 * amount The amount this limit is set for <br>
100 	 * reset_day The day of the month this limit is going to reset. <br>
101 	 * rollover TRUE or FALSE for whether or not this limit rollsover <br>
102 	 * transfer TRUE or FALSE for whether or not this limit includes transfers
103 	 * in the amount spent. <br>
104 	 * deposit TRUE or FALSE for whether or not this limit uses deposits to
105 	 * reduce the amount spent. <br>
106 	 * duration The duration of this budget based on when it resets. (0=Weekly;
107 	 * 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually; 5=Annually) <br>
108 	 * start_date If the duration is not 2, this will be when the budget
109 	 * originally started. <br>
110 	 * this_start_date This is when the budget for the current time period
111 	 * started. <br>
112 	 * this_end_date This is when the budget for the current time period ends. <br>
113 	 * original_limit The original amount of the limit (in case rollover is set
114 	 * to true).
115 	 */
116 	@Override
117 	public LimitDataType get(ParsedNameValuePair id)
118 			throws ClearcheckbookException {
119 		LimitDataType limitDataType = super.get(id);
120 		_logger.debug(limitDataType);
121 		return limitDataType;
122 	}
123 
124 	/***
125 	 * Inserts a limit for the current user <br>
126 	 * Method: post <br>
127 	 * Call: limit
128 	 * <p>
129 	 * Example: <br>
130 	 * https://username:password@www.clearcheckbook.com/api/limit/
131 	 * <p>
132 	 * Parameters: <br>
133 	 * Parameter Required Description <br>
134 	 * account_id Required If the limit is for an account, the id of the
135 	 * account. Default is 0. <br>
136 	 * category_id Required If the limit is for a category, the id of the
137 	 * category. Default is 0. <br>
138 	 * amount Required The amount this limit should be for (eg: 300) <br>
139 	 * duration Required The duration of this budget based on when it resets.
140 	 * (0=Weekly; 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually;
141 	 * 5=Annually) <br>
142 	 * reset_day Required Integer 1-31 for the day this limit should reset on.
143 	 * If this number is higher than the last day of the month, the limit will
144 	 * reset on the last day of the month. <br>
145 	 * start_date Required If the duration is not 2, this will be when the
146 	 * budget originally starts (formatted as yyyy-mm-dd). <br>
147 	 * rollover Required Whether or not this limit rolls over any unused money
148 	 * to the next month. 0=false, 1=true <br>
149 	 * transfer Required Whether or not this limit includes transfers in the
150 	 * amount spent. 0=false, 1=true <br>
151 	 * deposit Required Whether or not this limit uses deposits to reduce the
152 	 * amount spent. 0=false, 1=true
153 	 * <p>
154 	 * Returned Values: <br>
155 	 * Value Description <br>
156 	 * id / false Returns the id of the newly created limit on success or
157 	 * false/null on fail
158 	 */
159 	@Override
160 	public String insert(LimitDataType input) throws ClearcheckbookException {
161 		String insert = super.insert(input);
162 		_logger.debug(insert);
163 		return insert;
164 	}
165 
166 	/***
167 	 * Edit a specific limit for the current user. <br>
168 	 * Method: put <br>
169 	 * Call: limit
170 	 * <p>
171 	 * <br>
172 	 * Example: <br>
173 	 * https://username:password@www.clearcheckbook.com/api/limit/
174 	 * <p>
175 	 * Parameters: <br>
176 	 * Parameter Required Description <br>
177 	 * id Required The id of the limit being edited. <br>
178 	 * amount Required The amount this limit should be for (eg: 300) <br>
179 	 * duration Required The duration of this budget based on when it resets.
180 	 * (0=Weekly; 1=Bi-Weekly; 2=Monthly; 3=Quarterly; 4=Semi-Annually;
181 	 * 5=Annually) <br>
182 	 * reset_day Required Integer 1-31 for the day this limit should reset on.
183 	 * If this number is higher than the last day of the month, the limit will
184 	 * reset on the last day of the month. <br>
185 	 * start_date Required If the duration is not 2, this will be when the
186 	 * budget originally starts (formatted as yyyy-mm-dd). <br>
187 	 * rollover Required Whether or not this limit rolls over any unused money
188 	 * to the next month. 0=false, 1=true <br>
189 	 * transfer Required Whether or not this limit includes transfers in the
190 	 * amount spent. 0=false, 1=true <br>
191 	 * deposit Required Whether or not this limit uses deposits to reduce the
192 	 * amount spent. 0=false, 1=true
193 	 * <p>
194 	 * Returned Values: <br>
195 	 * Value Description <br>
196 	 * true / false Returns true on a successful edit or false/null on fail.
197 	 * ACTUALLY - it returns "null" on success and "" on fail
198 	 */
199 	@Override
200 	public boolean edit(LimitDataType dataType) throws ClearcheckbookException {
201 		String returnString;
202 		try {
203 			returnString = this.getConnection().putPage(getUrlSuffix(),
204 					dataType.getEditParameters());
205 			_logger.debug("returned: [" + returnString + "]");
206 			boolean ok = (returnString.equals("null"));
207 			_logger.info("edit : edited " + ok);
208 			return ok;
209 		} catch (IOException e) {
210 			throw new ClearcheckbookException("Failed to edit "
211 					+ getUrlSuffix(), e);
212 		}
213 	}
214 
215 	/***
216 	 * Delete a specific limit for the current user. <br>
217 	 * Method: delete <br>
218 	 * Call: limit
219 	 * <p>
220 	 * Example: <br>
221 	 * https://username:password@www.clearcheckbook.com/api/limit/
222 	 * <p>
223 	 * Parameters: <br>
224 	 * Parameter Required Description <br>
225 	 * id Required The id of the limit to delete
226 	 * <p>
227 	 * Returned Values: <br>
228 	 * Value Description <br>
229 	 * true / false Returns true on a successful delete or false/null on fail
230 	 */
231 	@Override
232 	public boolean delete(ParsedNameValuePair input)
233 			throws ClearcheckbookException {
234 		boolean delete = super.delete(input);
235 		_logger.debug(delete);
236 		return delete;
237 	}
238 
239 }