Skip to content

Commit f2e9e55

Browse files
committed
Add Request for sending messages
1 parent 3c39e60 commit f2e9e55

3 files changed

Lines changed: 88 additions & 2 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.proxerme.library.connection.messenger.request;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.afollestad.bridge.Form;
6+
import com.afollestad.bridge.Response;
7+
import com.proxerme.library.connection.ProxerRequest;
8+
import com.proxerme.library.connection.messenger.result.SendMessageResult;
9+
import com.proxerme.library.info.ProxerTag;
10+
import com.proxerme.library.info.ProxerUrlHolder;
11+
12+
/**
13+
* TODO: Describe class
14+
*
15+
* @author Ruben Gees
16+
*/
17+
18+
public class SendMessageRequest extends ProxerRequest<SendMessageResult> {
19+
20+
private static final String SEND_MESSAGE_URL = "/api/v1/messenger/setmessage";
21+
22+
private static final String CONFERENCE_ID_FORM = "conference_id";
23+
private static final String TEXT_FORM = "text";
24+
25+
private String conferenceId;
26+
private String text;
27+
28+
public SendMessageRequest(@NonNull String conferenceId, @NonNull String text) {
29+
this.conferenceId = conferenceId;
30+
this.text = text;
31+
}
32+
33+
@Override
34+
protected int getTag() {
35+
return ProxerTag.MESSENGER_SEND_MESSAGE;
36+
}
37+
38+
@Override
39+
protected SendMessageResult parse(@NonNull Response response) throws Exception {
40+
return response.asClass(SendMessageResult.class);
41+
}
42+
43+
@NonNull
44+
@Override
45+
protected String getURL() {
46+
return ProxerUrlHolder.getHost() + SEND_MESSAGE_URL;
47+
}
48+
49+
@Override
50+
protected Form getBody() {
51+
return new Form().add(CONFERENCE_ID_FORM, conferenceId)
52+
.add(TEXT_FORM, text);
53+
}
54+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.proxerme.library.connection.messenger.result;
2+
3+
import android.support.annotation.Nullable;
4+
5+
import com.afollestad.bridge.annotations.Body;
6+
import com.proxerme.library.interfaces.ProxerResult;
7+
8+
/**
9+
* TODO: Describe class
10+
*
11+
* @author Ruben Gees
12+
*/
13+
14+
public class SendMessageResult implements ProxerResult<String> {
15+
16+
@Nullable
17+
@Body(name = "data")
18+
String item;
19+
20+
SendMessageResult() {
21+
}
22+
23+
public SendMessageResult(@Nullable String item) {
24+
this.item = item;
25+
}
26+
27+
@Override
28+
@Nullable
29+
public String getItem() {
30+
return item;
31+
}
32+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class ProxerTag {
2525
public static final int INFO_ENTRY_SYNONYM = 21;
2626
public static final int INFO_ENTRY_SEASON = 22;
2727

28-
2928
public static final int MESSENGER_CONFERENCES = 30;
3029
public static final int MESSENGER_MESSAGES = 31;
30+
public static final int MESSENGER_SEND_MESSAGE = 32;
3131

3232
public static final int CONFERENCES = 100;
3333
public static final int CHAT = 101;
@@ -39,7 +39,7 @@ public class ProxerTag {
3939
@IntDef({LOGIN, NEWS, LOGOUT, USERINFO, TOPTEN, CONFERENCES, CHAT, SEND_MESSAGE,
4040
USER_MEDIA_LIST, MEDIA_LIST, MEDIA_SEARCH,
4141
INFO_ENTRY_CORE, INFO_ENTRY_SYNONYM, INFO_ENTRY_SEASON,
42-
MESSENGER_CONFERENCES, MESSENGER_MESSAGES})
42+
MESSENGER_CONFERENCES, MESSENGER_MESSAGES, MESSENGER_SEND_MESSAGE})
4343
@Retention(RetentionPolicy.SOURCE)
4444
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
4545
public @interface ConnectionTag {

0 commit comments

Comments
 (0)