Skip to content

Commit e88c9dd

Browse files
committed
Implement SetFavour and SetUnfavour of the API.
1 parent a9b2abd commit e88c9dd

5 files changed

Lines changed: 269 additions & 1 deletion

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.proxerme.library.connection.messenger.entity;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
import android.support.annotation.NonNull;
6+
7+
/**
8+
* The respone class used by {@link com.proxerme.library.connection.messenger.request.SetFavourRequest}
9+
* and GetFavour
10+
*
11+
* @author Desnoo
12+
*/
13+
public class Favour implements Parcelable {
14+
15+
public static final Creator<Favour> CREATOR = new Creator<Favour>() {
16+
@Override
17+
public Favour createFromParcel(Parcel in) {
18+
return new Favour(in);
19+
}
20+
21+
@Override
22+
public Favour[] newArray(int size) {
23+
return new Favour[size];
24+
}
25+
};
26+
27+
String status;
28+
29+
/**
30+
* The Constructor.
31+
*
32+
* @param status The status of the response of the request.
33+
*/
34+
public Favour(@NonNull String status) {
35+
this.status = status;
36+
}
37+
38+
/**
39+
* The Constructor to parse the parcel.
40+
*
41+
* @param in The parcel to parse.
42+
*/
43+
protected Favour(Parcel in) {
44+
status = in.readString();
45+
}
46+
47+
48+
/**
49+
* Get the status of the {@link com.proxerme.library.connection.messenger.request.SetFavourRequest}.
50+
*
51+
* @return A string containing the status of the favor request.
52+
*/
53+
@NonNull
54+
public String getStatus() {
55+
return status;
56+
}
57+
58+
59+
@Override
60+
public int describeContents() {
61+
return 0;
62+
}
63+
64+
@Override
65+
public void writeToParcel(Parcel parcel, int i) {
66+
parcel.writeString(status);
67+
}
68+
69+
@Override
70+
public boolean equals(Object o) {
71+
if (this == o) return true;
72+
if (o == null || getClass() != o.getClass()) return false;
73+
74+
Favour favour = (Favour) o;
75+
76+
return status.equals(favour.status);
77+
78+
}
79+
80+
@Override
81+
public int hashCode() {
82+
return status.hashCode();
83+
}
84+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.proxerme.library.connection.messenger.request;
2+
3+
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
5+
6+
import com.afollestad.bridge.Form;
7+
import com.afollestad.bridge.Response;
8+
import com.proxerme.library.connection.ProxerRequest;
9+
import com.proxerme.library.connection.messenger.result.FavourResult;
10+
import com.proxerme.library.info.ProxerTag;
11+
import com.proxerme.library.info.ProxerUrlHolder;
12+
13+
/**
14+
* The class that represents the SetFavourRequest. Use this to favour an conference.
15+
*
16+
* @author Desnoo
17+
*/
18+
public class SetFavourRequest extends ProxerRequest<FavourResult> {
19+
20+
private static final String SET_FAVOUR_URL = "/api/v1/messenger/setfavour";
21+
private static final String CONFERENCE_ID = "conference_id";
22+
23+
private String conferenceId;
24+
25+
26+
/**
27+
* Package constructor.
28+
*/
29+
SetFavourRequest() {
30+
}
31+
32+
/**
33+
* The constructor.
34+
*
35+
* @param conferenceId The conference id of the conference to favour.
36+
*/
37+
public SetFavourRequest(@NonNull String conferenceId) {
38+
this.conferenceId = conferenceId;
39+
}
40+
41+
/**
42+
* Returns the id of the conference.
43+
*
44+
* @return The conference id.
45+
*/
46+
@NonNull
47+
public String getConferenceId() {
48+
return conferenceId;
49+
}
50+
51+
@Override
52+
protected int getTag() {
53+
return ProxerTag.MESSENGER_SET_UNFAVOUR;
54+
}
55+
56+
@Override
57+
protected FavourResult parse(@NonNull Response response) throws Exception {
58+
return response.asClass(FavourResult.class);
59+
}
60+
61+
@NonNull
62+
@Override
63+
protected String getURL() {
64+
return ProxerUrlHolder.getHost() + SET_FAVOUR_URL;
65+
}
66+
67+
@Nullable
68+
@Override
69+
protected Form getBody() {
70+
return new Form()
71+
.add(CONFERENCE_ID, conferenceId);
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.proxerme.library.connection.messenger.request;
2+
3+
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
5+
6+
import com.afollestad.bridge.Form;
7+
import com.afollestad.bridge.Response;
8+
import com.proxerme.library.connection.ProxerRequest;
9+
import com.proxerme.library.connection.messenger.result.FavourResult;
10+
import com.proxerme.library.info.ProxerTag;
11+
import com.proxerme.library.info.ProxerUrlHolder;
12+
13+
/**
14+
* The class that represents the SetUnfavourRequest. Use this to remove the favourite status of
15+
* an conference.
16+
*
17+
* @author Desnoo
18+
*/
19+
public class SetUnfavourRequest extends ProxerRequest<FavourResult> {
20+
21+
private static final String SET_UNFAVOUR_URL = "/api/v1/messenger/setunfavour";
22+
private static final String CONFERENCE_ID = "conference_id";
23+
24+
private String conferenceId;
25+
26+
/**
27+
* Package constructor.
28+
*/
29+
SetUnfavourRequest() {
30+
}
31+
32+
/**
33+
* The constructor.
34+
*
35+
* @param conferenceId The conference id of the conference to remove favourite status.
36+
*/
37+
public SetUnfavourRequest(@NonNull String conferenceId) {
38+
this.conferenceId = conferenceId;
39+
}
40+
41+
/**
42+
* Returns the id of the conference.
43+
*
44+
* @return The conference id.
45+
*/
46+
@NonNull
47+
public String getConferenceId() {
48+
return conferenceId;
49+
}
50+
51+
@Override
52+
protected int getTag() {
53+
return ProxerTag.MESSENGER_SET_UNFAVOUR;
54+
}
55+
56+
@Override
57+
protected FavourResult parse(@NonNull Response response) throws Exception {
58+
return response.asClass(FavourResult.class);
59+
}
60+
61+
@NonNull
62+
@Override
63+
protected String getURL() {
64+
return ProxerUrlHolder.getHost() + SET_UNFAVOUR_URL;
65+
}
66+
67+
@Nullable
68+
@Override
69+
protected Form getBody() {
70+
return new Form()
71+
.add(CONFERENCE_ID, conferenceId);
72+
}
73+
}
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 android.support.annotation.NonNull;
4+
5+
import com.afollestad.bridge.annotations.Body;
6+
import com.proxerme.library.connection.messenger.entity.Favour;
7+
import com.proxerme.library.interfaces.ProxerResult;
8+
9+
/**
10+
* The result of the {@link com.proxerme.library.connection.messenger.request.SetFavourRequest} or GetFavour...
11+
*
12+
* @author Desnoo
13+
*/
14+
public class FavourResult implements ProxerResult<Favour> {
15+
16+
@Body(name = "message")
17+
Favour favour;
18+
19+
FavourResult() {
20+
}
21+
22+
/**
23+
* The Constructor.
24+
*
25+
* @param favour The favour response message.
26+
*/
27+
public FavourResult(@NonNull Favour favour) {
28+
this.favour = favour;
29+
}
30+
31+
@NonNull
32+
@Override
33+
public Favour getItem() {
34+
return favour;
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
@@ -33,14 +33,16 @@ public class ProxerTag {
3333
public static final int MESSENGER_SEND_MESSAGE = 52;
3434
public static final int MESSENGER_CONFERENCE_CONSTANTS = 53;
3535
public static final int MESSENGER_CONFERENCE_INFO = 54;
36+
public static final int MESSENGER_SET_FAVOUR = 55;
37+
public static final int MESSENGER_SET_UNFAVOUR = 56;
3638

3739
/**
3840
* An annotation representing all the different tags.
3941
*/
4042
@IntDef({LOGIN, NEWS, LOGOUT, USER_INFO, USER_TOPTEN, USER_MEDIA_LIST, MEDIA_LIST, MEDIA_SEARCH,
4143
INFO_ENTRY_CORE, INFO_ENTRY_SYNONYM, INFO_ENTRY_SEASON, MESSENGER_CONFERENCES,
4244
MESSENGER_MESSAGES, MESSENGER_SEND_MESSAGE, MESSENGER_CONFERENCE_CONSTANTS,
43-
MESSENGER_CONFERENCE_INFO})
45+
MESSENGER_CONFERENCE_INFO, MESSENGER_SET_FAVOUR, MESSENGER_SET_UNFAVOUR})
4446
@Retention(RetentionPolicy.SOURCE)
4547
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
4648
public @interface ConnectionTag {

0 commit comments

Comments
 (0)