Skip to content

Commit 57c517e

Browse files
committed
Added implementation of the Constants request for the messenger
1 parent 3284d80 commit 57c517e

4 files changed

Lines changed: 239 additions & 1 deletion

File tree

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package com.proxerme.library.connection.messenger.entity;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
import android.support.annotation.IntRange;
6+
7+
import com.afollestad.bridge.annotations.Body;
8+
9+
/**
10+
* Class that represents the constants of the messaging module. Such as max text length, request limits,
11+
* e.g. how many conferences at once could be requested.
12+
*
13+
* @author Desnoo
14+
*/
15+
public class Constants implements Parcelable {
16+
public static final Creator<Constants> CREATOR = new Creator<Constants>() {
17+
@Override
18+
public Constants createFromParcel(Parcel in) {
19+
return new Constants(in);
20+
}
21+
22+
@Override
23+
public Constants[] newArray(int size) {
24+
return new Constants[size];
25+
}
26+
};
27+
28+
@Body(name = "textCount")
29+
int textCount;
30+
@Body(name = "conferenceLimit")
31+
int conferenceLimit;
32+
@Body(name = "messagesLimit")
33+
int messagesLimit;
34+
@Body(name = "userLimit")
35+
int userLimit;
36+
@Body(name = "topicCount")
37+
int topicCount;
38+
39+
/**
40+
* Private constructor.
41+
*/
42+
Constants() {
43+
}
44+
45+
/**
46+
* The Constructor.
47+
*
48+
* @param textCount The max length of a message.
49+
* @param conferenceLimit The max number of conferences to request with one request.
50+
* @param messagesLimit The max number of messages of a conference to request with one request.
51+
* @param userLimit The max count of users of an conference.
52+
* @param topicCount The max length of a conference topic.
53+
*/
54+
public Constants(@IntRange(from = 0) int textCount, @IntRange(from = 0) int conferenceLimit,
55+
@IntRange(from = 0) int messagesLimit, @IntRange(from = 0) int userLimit,
56+
@IntRange(from = 0) int topicCount) {
57+
this.textCount = textCount;
58+
this.conferenceLimit = conferenceLimit;
59+
this.messagesLimit = messagesLimit;
60+
this.userLimit = userLimit;
61+
this.topicCount = topicCount;
62+
}
63+
64+
/**
65+
* The Constructor to parse from a parcel.
66+
*
67+
* @param in The parcel to parse.
68+
*/
69+
protected Constants(Parcel in) {
70+
textCount = in.readInt();
71+
conferenceLimit = in.readInt();
72+
messagesLimit = in.readInt();
73+
userLimit = in.readInt();
74+
topicCount = in.readInt();
75+
}
76+
77+
/**
78+
* Returns the max length of a message.
79+
*
80+
* @return The max length of a message.
81+
*/
82+
@IntRange(from = 0)
83+
public int getTextCount() {
84+
return textCount;
85+
}
86+
87+
/**
88+
* Returns the max number of conferences that can be requested by {@link com.proxerme.library.connection.messenger.request.ConferencesRequest}
89+
* with one request to the API.
90+
*
91+
* @return The max number of conferences to request with one request.
92+
*/
93+
@IntRange(from = 0)
94+
public int getConferenceLimit() {
95+
return conferenceLimit;
96+
}
97+
98+
/**
99+
* Returns the max number of messages of an conference that can be requested by {@link com.proxerme.library.connection.messenger.request.MessagesRequest}
100+
* one request to the API.
101+
*
102+
* @return The max number of messages that can be requested for an conference.
103+
*/
104+
@IntRange(from = 0)
105+
public int getMessagesLimit() {
106+
return messagesLimit;
107+
}
108+
109+
/**
110+
* Returns the max count of users that can be part of an conference.
111+
*
112+
* @return The max count of users of a conference.
113+
*/
114+
@IntRange(from = 0)
115+
public int getUserLimit() {
116+
return userLimit;
117+
}
118+
119+
/**
120+
* Returns the max length of the conference topic.
121+
*
122+
* @return The max length of the conference topic.
123+
*/
124+
@IntRange(from = 0)
125+
public int getTopicCount() {
126+
return topicCount;
127+
}
128+
129+
130+
@Override
131+
public int describeContents() {
132+
return 0;
133+
}
134+
135+
@Override
136+
public void writeToParcel(Parcel parcel, int i) {
137+
parcel.writeInt(textCount);
138+
parcel.writeInt(conferenceLimit);
139+
parcel.writeInt(messagesLimit);
140+
parcel.writeInt(userLimit);
141+
parcel.writeInt(topicCount);
142+
}
143+
144+
@SuppressWarnings("SimplifiableIfStatement")
145+
@Override
146+
public boolean equals(Object o) {
147+
if (this == o) return true;
148+
if (o == null || getClass() != o.getClass()) return false;
149+
Constants constants = (Constants) o;
150+
if (textCount != constants.textCount) return false;
151+
if (conferenceLimit != constants.conferenceLimit) return false;
152+
if (messagesLimit != constants.messagesLimit) return false;
153+
if (userLimit != constants.userLimit) return false;
154+
return topicCount == constants.topicCount;
155+
}
156+
157+
@Override
158+
public int hashCode() {
159+
int result = textCount;
160+
result = 31 * result + conferenceLimit;
161+
result = 31 * result + messagesLimit;
162+
result = 31 * result + userLimit;
163+
result = 31 * result + topicCount;
164+
return result;
165+
}
166+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.proxerme.library.connection.messenger.request;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.afollestad.bridge.Response;
6+
import com.proxerme.library.connection.ProxerRequest;
7+
import com.proxerme.library.connection.messenger.result.ConstantsResult;
8+
import com.proxerme.library.info.ProxerTag;
9+
import com.proxerme.library.info.ProxerUrlHolder;
10+
11+
/**
12+
* @author Desnoo
13+
*/
14+
public class ConstantsRequest extends ProxerRequest<ConstantsResult> {
15+
16+
private static final String CONFERENCE_CONSTANTS_URL = "/api/v1/messenger/constants";
17+
18+
19+
@Override
20+
protected int getTag() {
21+
return ProxerTag.MESSENGER_CONFERENCE_CONSTANTS;
22+
}
23+
24+
@Override
25+
protected ConstantsResult parse(@NonNull Response response) throws Exception {
26+
return response.asClass(ConstantsResult.class);
27+
}
28+
29+
@NonNull
30+
@Override
31+
protected String getURL() {
32+
return ProxerUrlHolder.getHost() + CONFERENCE_CONSTANTS_URL;
33+
}
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.proxerme.library.connection.messenger.result;
2+
3+
import com.afollestad.bridge.annotations.Body;
4+
import com.proxerme.library.connection.messenger.entity.Constants;
5+
import com.proxerme.library.interfaces.ProxerResult;
6+
7+
/**
8+
* The class that represents the result of the {@link com.proxerme.library.connection.messenger.request.ConstantsRequest}.
9+
*
10+
* @author Desnoo
11+
*/
12+
public class ConstantsResult implements ProxerResult<Constants> {
13+
14+
@Body(name = "data")
15+
Constants constants;
16+
17+
/**
18+
* Private Constructor.
19+
*/
20+
ConstantsResult() {
21+
}
22+
23+
/**
24+
* The constructor.
25+
*
26+
* @param constants The constants retrieved by the request.
27+
**/
28+
public ConstantsResult(Constants constants) {
29+
this.constants = constants;
30+
}
31+
32+
@Override
33+
public Constants getItem() {
34+
return this.constants;
35+
}
36+
}

library/src/main/java/com/proxerme/library/info/ProxerTag.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class ProxerTag {
2828

2929
public static final int MESSENGER_CONFERENCES = 30;
3030
public static final int MESSENGER_MESSAGES = 31;
31+
public static final int MESSENGER_CONFERENCE_CONSTANTS = 32;
32+
3133

3234
public static final int CONFERENCES = 100;
3335
public static final int CHAT = 101;
@@ -39,7 +41,7 @@ public class ProxerTag {
3941
@IntDef({LOGIN, NEWS, LOGOUT, USERINFO, TOPTEN, CONFERENCES, CHAT, SEND_MESSAGE,
4042
USER_MEDIA_LIST, MEDIA_LIST, MEDIA_SEARCH,
4143
INFO_ENTRY_CORE, INFO_ENTRY_SYNONYM, INFO_ENTRY_SEASON,
42-
MESSENGER_CONFERENCES, MESSENGER_MESSAGES})
44+
MESSENGER_CONFERENCES, MESSENGER_MESSAGES, MESSENGER_CONFERENCE_CONSTANTS})
4345
@Retention(RetentionPolicy.SOURCE)
4446
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
4547
public @interface ConnectionTag {

0 commit comments

Comments
 (0)