Skip to content

Commit c38c753

Browse files
committed
Add GetMessages
1 parent 380865c commit c38c753

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.cryptolens.methods;
2+
3+
import io.cryptolens.internal.BasicResult;
4+
import io.cryptolens.internal.HelperMethods;
5+
import io.cryptolens.models.*;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
/**
11+
* Methods related to the Message API (https://app.cryptolens.io/docs/api/v3/Message).
12+
* You can broadcast new messages by visiting https://app.cryptolens.io/Message.
13+
*/
14+
public class Message {
15+
16+
// create an overload without the error object
17+
18+
/**
19+
* This method will return a list of messages that were broadcasted.
20+
* You can create new messages here. Messages can be filtered based
21+
* on the time and the channel.
22+
* @param token The access token with 'GetMessages' permission.
23+
* @param model Method parameters.
24+
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
25+
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
26+
* <code>error</code> into this parameter.
27+
*/
28+
public GetMessagesResult GetMessages (String token, GetMessagesModel model) {
29+
return GetMessages(token, model, null);
30+
}
31+
32+
33+
/**
34+
* This method will return a list of messages that were broadcasted.
35+
* You can create new messages here. Messages can be filtered based
36+
* on the time and the channel.
37+
* @param token The access token with 'GetMessages' permission.
38+
* @param model Method parameters.
39+
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
40+
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
41+
* <code>error</code> into this parameter.
42+
*/
43+
public GetMessagesResult GetMessages (String token, GetMessagesModel model, APIError error) {
44+
45+
46+
Map<String,String> extraParams = new HashMap<>();
47+
extraParams.put("token", token);
48+
49+
GetMessagesResult result = HelperMethods.SendRequestToWebAPI("message/GetMessages", model, extraParams, GetMessagesResult.class, error);
50+
51+
if(result == null || result.result == 1) {
52+
if(result != null) {
53+
if (error != null) {
54+
error.message = result.message;
55+
error.errorType = ErrorType.WebAPIError;
56+
}
57+
} else {
58+
if (error != null) {
59+
error.errorType = ErrorType.WebAPIError;
60+
}
61+
}
62+
}
63+
64+
return result;
65+
}
66+
67+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.cryptolens.models;
2+
3+
public class GetMessagesModel extends RequestModel {
4+
5+
/**
6+
* Specifies the channel, whose messages you would like to retrieve.
7+
* If not set, messages from all channels will be returned.
8+
*/
9+
public String Channel;
10+
11+
/**
12+
* Allows you to retrieve only those messages that were created after
13+
* a certain Time (strictly greater than), eg. the last time you contacted
14+
* the server. The format is unix timestamp. If no time is specified, all
15+
* messages will be returned.
16+
*/
17+
public long Time;
18+
19+
20+
public GetMessagesModel () {}
21+
22+
public GetMessagesModel(String channel) {
23+
Channel = channel;
24+
}
25+
26+
public GetMessagesModel(String channel, long time) {
27+
Channel = channel;
28+
Time = time;
29+
}
30+
31+
public GetMessagesModel(long time) {
32+
Time = time;
33+
}
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.cryptolens.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import io.cryptolens.internal.BasicResult;
5+
6+
import java.util.List;
7+
8+
public class GetMessagesResult extends BasicResult {
9+
10+
@SerializedName(value = "messages", alternate = {"Messages"})
11+
public List<MessageObject> Messages;
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.cryptolens.models;
2+
3+
public class MessageObject {
4+
5+
public int Id;
6+
public String Content;
7+
public long Created;
8+
public String Channel;
9+
}

0 commit comments

Comments
 (0)