Refactory
[smsapi-java.git] / src / pl / smsapi / api / action / user / Add.java
blobc238f13573230fce93b5a8704c232a3392c0ad11
1 package pl.smsapi.api.action.user;
3 import org.json.JSONObject;
4 import pl.smsapi.api.action.BaseAction;
5 import pl.smsapi.api.response.UserResponse;
7 import java.net.URI;
8 import java.net.URISyntaxException;
10 public class Add extends BaseAction<UserResponse> {
12 @Override
13 public URI uri() throws URISyntaxException {
15 String query = "";
17 query += paramsLoginToQuery();
19 query += paramsOther();
21 return new URI(proxy.getProtocol(), null, proxy.getHost(), proxy.getPort(), proxy.getPath()+"user.do", query, null);
24 public Add setUsername(String username) {
25 params.put("add_user", username);
26 return this;
29 public Add setPassword(String password) {
30 params.put("pass", password);
31 return this;
34 public Add setPasswordApi(String password) {
35 params.put("pass_api", password);
36 return this;
39 public Add setLimit(int limit) {
40 params.put("limit", Integer.toString(limit));
41 return this;
44 public Add setLimit(double limit) {
45 params.put("limit", Double.toString(limit));
46 return this;
49 public Add setMonthLimit(int limit) {
50 params.put("month_limit", Integer.toString(limit));
51 return this;
54 public Add setMonthLimit(double limit) {
55 params.put("month_limit", Double.toString(limit));
56 return this;
59 public Add setSenders(boolean access) {
61 if (access == true)
62 params.put("senders", "1");
63 else
64 params.put("senders", "0");
66 return this;
69 public Add setPhonebook(boolean access) {
71 if (access == true)
72 params.put("phonebook", "1");
73 else
74 params.put("phonebook", "0");
76 return this;
79 public Add setActive(boolean val) {
81 if (val == true)
82 params.put("active", "1");
83 else
84 params.put("active", "0");
86 return this;
89 public Add setInfo(String info) {
90 params.put("info", info);
91 return this;
94 protected UserResponse createResponse(String data) {
95 JSONObject jsonObject = new JSONObject(data);
96 return
97 new UserResponse(
98 jsonObject.getString("username"),
99 jsonObject.optDouble("limit"),
100 jsonObject.optDouble("month_limit"),
101 jsonObject.optInt("senders"),
102 jsonObject.optInt("phonebook"),
103 jsonObject.optInt("active"),
104 jsonObject.optString("info")