1 package com.leonarduk.clearcheckbook.calls;
2
3 import java.util.List;
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.AbstractDataType;
10 import com.leonarduk.clearcheckbook.dto.CategoryDataType;
11 import com.leonarduk.clearcheckbook.dto.ParsedNameValuePair;
12
13 public class CategoryCall extends AbstractCall<CategoryDataType> {
14
15 private static final Logger _logger = Logger.getLogger(CategoryCall.class);
16
17 public static final String TYPE = "category";
18
19 public CategoryCall(ClearCheckBookConnection connection) {
20 super(connection, CategoryDataType.class);
21 }
22
23 @Override
24 protected String getUrlSuffix() {
25 return TYPE;
26 }
27
28 @Override
29 protected String getPluralUrl() {
30 return "categories";
31 }
32
33 /***
34 *
35 Deletes a specific category for the current user <br>
36 * Method: delete <br>
37 * Call: category
38 * <p>
39 * Example: <br>
40 * https://username:password@www.clearcheckbook.com/api/category/
41 * <p>
42 * Parameters: Parameter Required Description <br>
43 * id Required The id of the category being deleted
44 * <p>
45 * Returned Values: <br>
46 * Value Description <br>
47 * true / false Returns true upon removal of the category or false/null on
48 * fail
49 *
50 * @Override {@link AbstractCall#delete(ParsedNameValuePair)}
51 * @return
52 * @throws ClearcheckbookException
53 */
54 public boolean delete(ParsedNameValuePair id)
55 throws ClearcheckbookException {
56 boolean delete = super.delete(id);
57 _logger.debug("edit: OK?" + delete + " " + id);
58 return delete;
59 }
60
61 /***
62 * Edit a specific category for the current user. <br>
63 * Method: put <br>
64 * Call: category
65 * <p>
66 * Example: <br>
67 * https://username:password@www.clearcheckbook.com/api/category/
68 * <p>
69 * Parameters: <br>
70 * Parameter Required Description <br>
71 * id Required The id of the category being edited <br>
72 * name Required The new name for the category <br>
73 * parent Required The new parent id for the category
74 * <p>
75 * Returned Values: <br>
76 * Value Description <br>
77 * true / false Returns true on a successful edit or false/null on fail.
78 *
79 * @Override {@link AbstractCall#edit(AbstractDataType)}
80 * @return
81 * @throws ClearcheckbookException
82 */
83 public boolean edit(CategoryDataType input) throws ClearcheckbookException {
84 boolean edit = super.edit(input);
85 _logger.debug("edit: OK?" + edit + " " + input);
86 return edit;
87 }
88
89 /***
90 * Gets all of the current users categories <br>
91 * Method: get <br>
92 * Call: categories
93 * <p>
94 * <br>
95 * Example: <br>
96 * https://username:password@www.clearcheckbook.com/api/categories/
97 * <p>
98 * <br>
99 * Parameters: <br>
100 * Parameter Required Description <br>
101 * None
102 * <p>
103 * Returned Values: <br>
104 * Value Description <br>
105 * id The id of the category <br>
106 * name The name of the category <br>
107 * parent The id of this category's parent. 0 if there is no parent.
108 *
109 * @Override {@link AbstractCall#getAll()}
110 * @return
111 */
112 public List<CategoryDataType> getAll() throws ClearcheckbookException {
113 List<CategoryDataType> all = super.getAll();
114 _logger.debug("getAll: " + all.size() + " returned");
115
116 return all;
117 }
118
119 /***
120 * Adds a category to the current users accout. <br>
121 * Method: post <br>
122 * Call: category
123 * <p>
124 * Example: <br>
125 * https://username:password@www.clearcheckbook.com/api/category/
126 * <p>
127 * Parameters: <br>
128 * Parameter Required Description <br>
129 * name Required The name of the new category <br>
130 * parent Optional The id of this category's parent.
131 * <p>
132 * <br>
133 * Returned Values: <br>
134 * Value Description <br>
135 * id / false The id of the newly created category or false/null on fail.
136 *
137 * @Override {@link AbstractCall#getAll()}
138 * @return
139 */
140 public String insert(CategoryDataType input) throws ClearcheckbookException {
141 String insert = super.insert(input);
142 _logger.debug("insert: id " + insert + " " + input);
143 return insert;
144 }
145
146 }