Skip to content

Commit 1406f2c

Browse files
committed
Merge branch 'v3' of github.com:/smsapi/smsapi-java-client into v3
2 parents d7dc814 + 9ffef3f commit 1406f2c

33 files changed

Lines changed: 897 additions & 174 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

66
## [3.0.0-RC3-SNAPSHOT]
7+
### Added
8+
- Subusers API
9+
710
### Changed
11+
- `pl.smsapi.api.UserFactory.actionAdd` marked as deprecated, use `pl.smsapi.api.action.subusers.SubusersFactory.actionAdd` instead
12+
- `pl.smsapi.api.UserFactory.actionEdit` marked as deprecated, use `pl.smsapi.api.action.subusers.SubusersFactory.actionEdit` instead
13+
- `pl.smsapi.api.UserFactory.actionList` marked as deprecated, use `pl.smsapi.api.action.subusers.SubusersFactory.actionList` instead
814
- `pl.smsapi.BasicAuthClient` marked as deprecated
915
- non-proxy action factories marked as deprecated
1016

src/main/java/pl/smsapi/api/UserFactory.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pl.smsapi.api;
22

33
import pl.smsapi.Client;
4+
import pl.smsapi.api.action.subusers.SubusersFactory;
45
import pl.smsapi.api.action.user.UserAdd;
56
import pl.smsapi.api.action.user.UserEdit;
67
import pl.smsapi.api.action.user.UserGetPoints;
@@ -21,20 +22,32 @@ public UserFactory(Client client, Proxy proxy) {
2122
super(client, proxy);
2223
}
2324

25+
/**
26+
* @deprecated use {@link SubusersFactory#actionList()} instead
27+
*/
28+
@Deprecated
2429
public UserList actionList() {
2530
UserList action = new UserList();
2631
action.client(client);
2732
action.proxy(proxy);
2833
return action;
2934
}
3035

36+
/**
37+
* @deprecated use {@link SubusersFactory#actionAdd(String, String)} ()} instead
38+
*/
39+
@Deprecated
3140
public UserAdd actionAdd() {
3241
UserAdd action = new UserAdd();
3342
action.client(client);
3443
action.proxy(proxy);
3544
return action;
3645
}
3746

47+
/**
48+
* @deprecated use {@link SubusersFactory#actionEdit(String)} ()} instead
49+
*/
50+
@Deprecated
3851
public UserEdit actionEdit(String username) {
3952
UserEdit action = new UserEdit();
4053
action.client(client);

src/main/java/pl/smsapi/api/action/AbstractAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.json.JSONObject;
55
import pl.smsapi.Client;
66
import pl.smsapi.api.authenticationStrategy.AuthenticationStrategy;
7+
import pl.smsapi.api.response.Response;
78
import pl.smsapi.exception.*;
89
import pl.smsapi.proxy.Proxy;
910

@@ -14,7 +15,7 @@
1415
import java.util.regex.Matcher;
1516
import java.util.regex.Pattern;
1617

17-
public abstract class AbstractAction<T> {
18+
public abstract class AbstractAction<T extends Response> {
1819

1920
public final static String RESPONSE_PACKAGE_NAME = "pl.smsapi.api.response";
2021

src/main/java/pl/smsapi/api/action/AbstractSendAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package pl.smsapi.api.action;
22

33
import pl.smsapi.StringUtils;
4+
import pl.smsapi.api.response.Response;
45

56
import java.util.Calendar;
67

7-
public abstract class AbstractSendAction<T, TResponse> extends AbstractAction<TResponse> {
8+
public abstract class AbstractSendAction<T, TResponse extends Response> extends AbstractAction<TResponse> {
89

910
/**
1011
* Set mobile phone number of the recipients.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import org.json.JSONObject;
4+
import pl.smsapi.api.response.Response;
5+
6+
public class Subuser implements Response {
7+
public final String id;
8+
public final String username;
9+
public final boolean active;
10+
public final String description;
11+
public final double pointsFromAccount;
12+
public final double pointsPerMonth;
13+
14+
private Subuser(String id, String username, boolean active, String description, double pointsFromAccount, double pointsPerMonth) {
15+
this.id = id;
16+
this.username = username;
17+
this.active = active;
18+
this.description = description;
19+
this.pointsFromAccount = pointsFromAccount;
20+
this.pointsPerMonth = pointsPerMonth;
21+
}
22+
23+
static class SubuserFromJsonFactory {
24+
public Subuser createFrom(JSONObject jsonObject) {
25+
return new Subuser(
26+
jsonObject.getString("id"),
27+
jsonObject.getString("username"),
28+
jsonObject.getBoolean("active"),
29+
jsonObject.optString("description"),
30+
jsonObject.getJSONObject("points").getDouble("from_account"),
31+
jsonObject.getJSONObject("points").getDouble("per_month")
32+
);
33+
}
34+
}
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import org.json.JSONObject;
4+
import pl.smsapi.api.action.AbstractAction;
5+
6+
public class SubuserAdd extends AbstractAction<Subuser> {
7+
public SubuserAdd(String username, String password) {
8+
params.put("credentials[username]", username);
9+
params.put("credentials[password]", password);
10+
}
11+
12+
@Override
13+
protected String endPoint() {
14+
return "subusers";
15+
}
16+
17+
@Override
18+
protected Subuser createResponse(String data) {
19+
return new Subuser.SubuserFromJsonFactory().createFrom(new JSONObject(data));
20+
}
21+
22+
public void withApiPassword(String apiPassword) {
23+
params.put("credentials[api_password]", apiPassword);
24+
}
25+
26+
public void asActive() {
27+
params.put("active", "1");
28+
}
29+
30+
public void asInactive() {
31+
params.put("active", "0");
32+
}
33+
34+
public void withDescription(String description) {
35+
params.put("description", description);
36+
}
37+
38+
public void withPointsFromAccount(double pointsFromAccount) {
39+
params.put("points[from_account]", String.valueOf(pointsFromAccount));
40+
}
41+
42+
public void withPointsPerMonth(double pointsPerMonth) {
43+
params.put("points[per_month]", String.valueOf(pointsPerMonth));
44+
}
45+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import pl.smsapi.api.action.AbstractAction;
4+
import pl.smsapi.api.response.Response;
5+
6+
public class SubuserDelete extends AbstractAction<Response> {
7+
private final String id;
8+
9+
public SubuserDelete(String id) {
10+
this.id = id;
11+
}
12+
13+
@Override
14+
protected String endPoint() {
15+
return "subusers/" + id;
16+
}
17+
18+
@Override
19+
protected String httpMethod() {
20+
return "DELETE";
21+
}
22+
23+
@Override
24+
protected Response createResponse(String data) {
25+
return null;
26+
}
27+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import org.json.JSONObject;
4+
import pl.smsapi.api.action.AbstractAction;
5+
6+
public class SubuserEdit extends AbstractAction<Subuser> {
7+
private final String id;
8+
9+
public SubuserEdit(String id) {
10+
this.id = id;
11+
}
12+
13+
@Override
14+
protected String endPoint() {
15+
return "subusers/" + id;
16+
}
17+
18+
@Override
19+
protected String httpMethod() {
20+
return "PUT";
21+
}
22+
23+
@Override
24+
protected Subuser createResponse(String data) {
25+
return new Subuser.SubuserFromJsonFactory().createFrom(new JSONObject(data));
26+
}
27+
28+
public void withPassword(String password) {
29+
params.put("credentials[password]", password);
30+
}
31+
32+
public void withApiPassword(String apiPassword) {
33+
params.put("credentials[api_password]", apiPassword);
34+
}
35+
36+
public void asActive() {
37+
params.put("active", "1");
38+
}
39+
40+
public void asInactive() {
41+
params.put("active", "0");
42+
}
43+
44+
public void withDescription(String description) {
45+
params.put("description", description);
46+
}
47+
48+
public void withPointsFromAccount(double pointsFromAccount) {
49+
params.put("points[from_account]", String.valueOf(pointsFromAccount));
50+
}
51+
52+
public void withPointsPerMonth(double pointsPerMonth) {
53+
params.put("points[per_month]", String.valueOf(pointsPerMonth));
54+
}
55+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import org.json.JSONObject;
4+
import pl.smsapi.api.action.AbstractAction;
5+
6+
public class SubuserGet extends AbstractAction<Subuser> {
7+
private final String id;
8+
9+
public SubuserGet(String id) {
10+
this.id = id;
11+
}
12+
13+
@Override
14+
protected String endPoint() {
15+
return "subusers/" + id;
16+
}
17+
18+
@Override
19+
protected String httpMethod() {
20+
return "GET";
21+
}
22+
23+
@Override
24+
protected Subuser createResponse(String data) {
25+
return new Subuser.SubuserFromJsonFactory().createFrom(new JSONObject(data));
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package pl.smsapi.api.action.subusers;
2+
3+
import org.json.JSONArray;
4+
import org.json.JSONObject;
5+
import pl.smsapi.api.response.ListResponse;
6+
7+
public class Subusers extends ListResponse<Subuser> {
8+
private Subusers(int count, JSONArray jsonArray) {
9+
super(count, jsonArray);
10+
}
11+
12+
@Override
13+
protected Subuser buildItem(JSONObject jsonObject) {
14+
return new Subuser.SubuserFromJsonFactory().createFrom(jsonObject);
15+
}
16+
17+
static class SubusersFromJsonFactory {
18+
public Subusers createFrom(JSONObject jsonObject) {
19+
return new Subusers(
20+
jsonObject.getInt("size"),
21+
jsonObject.getJSONArray("collection")
22+
);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)